azure-logic-apps - Azure 逻辑应用自定义连接器中的 URL 路径变量

标签 azure-logic-apps

我正在尝试构建一个可以更新 JIRA 问题的逻辑应用程序自定义连接器(预构建连接器中当前不可用的功能)。

这是来自 JIRA documentation for this request 的 cURL 示例

curl -D- -u fred:fred -X PUT --data {see below} -H "Content-Type: application/json" http://kelpie9:8081/rest/api/2/issue/QA-31

{
   "fields": {
       "assignee":{"name":"harry"}
   }
}

QA-31 值是我想要作为变量的唯一标识符。我使用 Postman 将其设置为环境变量并成功运行了请求。当我将 Postman 集合上传到我的自定义连接器时,“QA-31”值无法用作路径变量

然后我尝试直接编辑自定义连接器。在“导入示例”菜单中,我将 URL 中的“QA-31”替换为“{issueKey}”。这创建了一个路径变量,但它还在 url 前面加上了 '/en-us/widgets/manage' 前缀;我不想要的

Here is a picture of the problem

所以这里有几个问题:

  1. 为什么我在 Postman 中的路径变量没有在自定义连接器中被拾取,而来自该集合的其他请求工作正常
  2. 为什么在“从示例导入”菜单中添加路径变量时我的 URL 以“/en-us/widgets/manage”为前缀

谢谢!

最佳答案

在逻辑应用程序自定义连接器编辑器中,您可以通过将变量括在方括号内来定义路径变量(例如 https://api.library.com/[method }/)。这可以在创建/编辑自定义连接器的“定义”步骤中手动完成。但是,缺点是您必须使用“从示例导入”功能,这需要您手动重写特定请求。

为了回答您的问题,我们可以在 PostMan 中定义路径变量,然后运行 ​​V1 导出。

您可以在 Postman 请求中定义一个路径变量,方法是在变量名前加上一个“:”,就像这样,https://api.library.com/:method/ .这会将键(方法)和可选值添加到请求参数字段。 Postman variable path example

当您导出为 Postman V1 集合时,生成的 JSON 代码如下所示,

{
"id": "fc10d942-f460-4fbf-abb6-36943a112bf6",
"name": "Custom Method Demo",
"description": "",
"auth": null,
"events": null,
"variables": [],
"order": [
    "becb5ff8-6d31-48ee-be3d-8c70777d60aa"
],
"folders_order": [],
"folders": [],
"requests": [
    {
        "id": "becb5ff8-6d31-48ee-be3d-8c70777d60aa",
        "name": "Custom Request Method",
        "url": "https://api.library.com/:method",
        "description": "Use a path variable to define a custom method.",
        "data": null,
        "dataMode": "params",
        "headerData": [],
        "method": "GET",
        "pathVariableData": [
            {
                "key": "method",
                "value": ""
            }
        ],
        "queryParams": [],
        "auth": {
            "type": "noauth"
        },
        "events": [
            {
                "listen": "prerequest",
                "script": {
                    "id": "b7b91243-0c58-4dc6-b3ee-4fb4ffc604db",
                    "type": "text/javascript",
                    "exec": [
                        ""
                    ]
                }
            }
        ],
        "folder": null,
        "headers": "",
        "pathVariables": {
            "method": ""
        }
    }
]}

注意对应于我们的自定义路径变量的“pathVariables”字段。

现在我们可以将其导入到我们的逻辑应用程序中,路径变量将按照第一段中的描述进行正确解释。 Microsoft Azure Logic Apps Custom Connector with variable path

希望对您有所帮助。

关于azure-logic-apps - Azure 逻辑应用自定义连接器中的 URL 路径变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46929030/

相关文章:

azure - 使用逻辑应用提取电子邮件正文

azure - azure api-apps、logic-apps、web-apps 和 azure function 之间的区别

Azure 逻辑应用从 SFTP 服务器获取 csv 文件并插入到 Azure SQL 数据库表中

azure - 访问 token 已被错误的受众获取

azure - 获取逻辑应用工作流运行时执行的操作数

json - Azure 逻辑应用对 SQL 行的 HTTP 响应正文

azure - 可以用一些注释来标记逻辑应用程序运行吗?

azure - 执行直到Azure逻辑应用程序中的条件无法按预期工作

Azure 逻辑应用 SQL ODATA 按日期筛选

azure - 使用 Azure 逻辑应用 HTTP 连接器返回的 JSON