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

Post Reply
cwswitch
Member
Posts: 99
Joined: Fri Feb 24, 2017 12:25 am

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

Post 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
cwswitch
Member
Posts: 99
Joined: Fri Feb 24, 2017 12:25 am

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

Post 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
User avatar
JimmyHartington
Advanced member
Posts: 384
Joined: Tue Mar 22, 2011 7:38 am

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

Post 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.
cwswitch
Member
Posts: 99
Joined: Fri Feb 24, 2017 12:25 am

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

Post by cwswitch »

Thanks Jimmy. That's a good idea for simplification.
Post Reply