edvu
edvu

Reputation: 31

URL path variables in Azure Logic App Custom Connectors

I'm trying to build a Logic Apps Custom Connector that can update a JIRA issue (a feature not currently available in the prebuilt connector).

Here is a cURL example from the JIRA documentation for this request

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"}
   }
}

The QA-31 value is the unique identifier that I want to make a variable. Using Postman I set that as an Environment variable and successfully ran the request. When I uploaded the Postman collection to my custom connector 'QA-31' value wasn't available as a path variable

Then I tried editing the custom connector directly. In the Import Sample menu I replaced 'QA-31' in the URL with '{issueKey}'. This created a path variable but it also prefixed the url with '/en-us/widgets/manage'; which I don't want

Here is a picture of the problem

So there are a couple questions here:

  1. Why is my path variable in Postman not being picked up in the custom connector while other requests from that collection were working fine
  2. Why is my URL being prefixed with '/en-us/widgets/manage' when add a path variable in the 'Import from Sample' menu

Thanks!

Upvotes: 3

Views: 3314

Answers (1)

gunnerman
gunnerman

Reputation: 193

Inside the Logic Apps Custom Connector Editor you may define path variables by enclosing the variable inside brackets (e.g. https://api.library.com/[method}/). This can be done manually during the "Definition" step of creating/editing your custom connector. However, the drawback is that you must use the "Import from sample" feature which requires you to manually rewrite the particular request.

To answer your question we can define the path variables in PostMan and then run the V1 export.

You can define a path variable in a Postman request by prepending a ':' to the variable name like so, https://api.library.com/:method/. This will add the key (method) and the optional value to the request parameters field. Postman variable path example

When you export as a Postman V1 collection the resulting JSON code looks like,

{
"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": ""
        }
    }
]}

Notice the "pathVariables" field which corresponds to our custom path variable.

Now we can import this into our Logic App and the path variable is properly interpreted as described in the first paragraph. Microsoft Azure Logic Apps Custom Connector with variable path

Hope that helps.

Upvotes: 4

Related Questions