Page 1 of 1

HTTP request v20+ not expanding switch variables (maybe?)

Posted: Sat Nov 23, 2024 3:19 am
by cwswitch
Hi,

we are able to complete a request with POST a body, custom, set to Hard Coded values of

Code: Select all

{
    "ExternalConsignment": {
        "ConsignmentNo": "34CAW2079918",
        "ConsignmentTrackingCode": "34CAW2079918",
        "ConsignmentTrackingURL": "https://auspost.com.au/mypost/track/#/search",
        "ExternalConsignmentDeliveries": [
            {
                "DeliveryKey": "584659",
                "DeliveryTrackingCode": "34CAW2079918",
                "DeliveryTrackingURL": "https://auspost.com.au/mypost/track/#/search"
            }
        ]
    }
}
but it fails with "Request finish status: Unsupported Media Type; status code: 415; status description: 415; last error: Request failed with status code 415" when we use variables

Code: Select all

{
    "ExternalConsignment": {
        "ConsignmentNo": "[Job.PrivateData:Key="Consignment"]",
        "ConsignmentTrackingCode": "[Job.PrivateData:Key="Consignment"]",
        "ConsignmentTrackingURL": "[Job.PrivateData:Key="URL"]",
        "ExternalConsignmentDeliveries": [
            {
                "DeliveryKey": "[Job.PrivateData:Key="FDKey"]",
                "DeliveryTrackingCode": "[Job.PrivateData:Key="Consignment"]",
                "DeliveryTrackingURL": "[Job.PrivateData:Key="URL"]"
            }
        ]
    }
}
To make the hardcoded version, I highlighted each variable, eg [Job.PrivateData:Key="Consignment"] copied the value that Switch was returning, then pasted it in place of the variable. In theory then Switch can see the value, and the value works.

Other settings are

URL: the URL we need to use and this is the same whether we test with hardcoded or switch variables so should not be a factor
Request Type: POST a body
Body content: Custom
Custom body: as shown in the code snips above
Authentication scheme: None
Parameters:
Headers:
Response: Attach as dataset
Dataset name: HTTPResponse
Dataset model: Automatic
Response headers: Discard
Retry after failed connection: No
Ignore server certificate errors: No

Re: HTTP request v20+ not expanding switch variables (maybe?)

Posted: Sat Nov 23, 2024 9:11 am
by cwswitch
I'm still curious what I was doing wrong, but I have solved it by some workarounds.

Workaround
  • Get all the data as before
  • Inject a half made json that has placeholder values
  • Use the String Replace app to swap the placeholders for the variables
  • Pass the file through the HTTP Request as Post a Body: Input Job

Re: HTTP request v20+ not expanding switch variables (maybe?)

Posted: Sat Nov 23, 2024 11:29 am
by JimmyHartington
Maybe you could simplify your flow by using the app "Create text file" https://www.enfocus.com/en/appstore/pro ... -text-file

With this you should be able to create the JSON directly with your variables.

Re: HTTP request v20+ not expanding switch variables (maybe?)

Posted: Sat Nov 23, 2024 7:39 pm
by cwswitch
Thanks Jimmy. That's a good idea for simplification.

Re: HTTP request v20+ not expanding switch variables (maybe?)

Posted: Wed Oct 01, 2025 4:43 pm
by schmitzdp
Hi,

I have the same problem. Why is it not possible to insert variables into “Post a body”? :?

I was thinking of injecting a JSON dataset with variables, but I can't find an application that could execute it.

My goal is to keep the original file, add this dataset, and retrieve the HTTP response for the rest of my flow.

Do you have any ideas?

Thanks

Re: HTTP request v20+ not expanding switch variables (maybe?)

Posted: Mon Oct 06, 2025 2:07 pm
by magnussandstrom
Isn't the problem that hard brackets [ ] is used for both Switch variables and the array in the JSON?

I use this clunky work-a-round:

Using Create text file to create a JSON but for the array brackets I instead use the place-holder-text startarray and stoparray.

After Create text file I use String replace to replace startarray and stoparray to [ and ].

I can now use HTTP Request POST a body, Body content = Input job.


Example:
{
"company": "[Job.PrivateData:Key="myCompany"]",
"name": "[Job.PrivateData:Key="myName"]",
"orderLines": startarray
{
"lineItem": "[Metadata.Text:Dataset="Xml",Model="XML",Path="/order/document/item"]",
"lineDescription": "[Metadata.Text:Dataset="Xml",Model="XML",Path="/order/document/description"]",
"lineQty": [Metadata.Text:Dataset="Xml",Model="XML",Path="/order/document/qty"]
}
stoparray
}

Re: HTTP request v20+ not expanding switch variables (maybe?)

Posted: Mon Oct 06, 2025 3:57 pm
by magnussandstrom
It would be a neat feature in the HTTP Request app to be able to substitute array brackets with other characters.

Re: HTTP request v20+ not expanding switch variables (maybe?)

Posted: Wed Oct 08, 2025 8:27 am
by magnussandstrom
Freddy shared a helpful workaround to resolve this issue.

Solution:
Insert double square brackets ([[) for the array’s opening bracket (but not at the last bracket). This prevents conflicts with Switch meta-data brackets while still producing valid JSON for the endpoint.

Example:

Code: Select all

{
  "company": "[Job.PrivateData:Key=\"myCompany\"]",
  "name": "[Job.PrivateData:Key=\"myName\"]",
  "orderLines": [[
    {
      "lineItem": "[Metadata.Text:Dataset="Xml",Model="XML",Path="/order/document/item"]",
      "lineDescription": "[Metadata.Text:Dataset="Xml",Model="XML",Path="/order/document/description"]",
      "lineQty": [Metadata.Text:Dataset="Xml",Model="XML",Path="/order/document/qty"]
    }
  ]
}