Page 1 of 1

HTTP request parameters

Posted: Mon May 17, 2021 11:11 pm
by Scott_PC79
I'm trying to send a request to an API and it keeps sending back a BadRequest error. I'm using switch variables in the parameters for the values. Here is the example request from the web server
{
"OrderId": "39052da0-70d5-4c84-9504-73f36ce25369",
"SiteShippingMethodName": "UPS Ground",
"ShipmentInfo": {
"Address": {
"FirstName": "Name",
"LastName": "Example",
"Address1": "No name street",
"City": "No Name",
"StateProvince": "No Name",
"Postal": "123456",
"Country": "US"
},
"ShipDate": "2015-12-06",
"Tracking": "JPOOAI881817376WBY",
"Items": [
{
"OrderItemId": "08e8b07d-2e91-41e4-8e2b-ec844a176b19"
}
]
}
}

and this is my parameter request

OrderId=[Metadata.Text:Path="/dn:OrderInfo/dn:OrderID[1]",Dataset="Original",Model="XML"]
SiteShippingMethodName=[Metadata.Text:Path="/dn:OrderInfo/dn:OrderItems[1]/dn:PresseroOrderItem/dn:ShipMethod[1]",Dataset="Original",Model="XML"]
Business=[Metadata.Text:Path="/textfile/line[10]",Dataset="Email",Model="XML"]
Address1=[Metadata.Text:Path="/dn:OrderInfo/dn:OrderShipTo[1]/dn:Address1[1]",Dataset="Original",Model="XML"]
City=[Metadata.Text:Path="/dn:OrderInfo/dn:OrderShipTo[1]/dn:City[1]",Dataset="Original",Model="XML"]
StateProvince=[Metadata.Text:Path="/dn:OrderInfo/dn:OrderShipTo[1]/dn:StateProvince[1]",Dataset="Original",Model="XML"]
Postal=[Metadata.Text:Path="/dn:OrderInfo/dn:OrderShipTo[1]/dn:Postal[1]",Dataset="Original",Model="XML"]
Country=[Metadata.Text:Path="/dn:OrderInfo/dn:OrderShipTo[1]/dn:Country[1]",Dataset="Original",Model="XML"]
ShipDate=[Switch.Date:TimeZone="UTC"]
Tracking=[Metadata.Text:Path="/textfile/name-value-pair/value",Dataset="Email",Model="XML"]
Items=[Metadata.Text:Path="/dn:OrderInfo/dn:OrderItems[1]/dn:PresseroOrderItem/dn:ItemId[1]",Dataset="Original",Model="XML"]

Anyone have any suggestions as to how to fix?

Re: HTTP request parameters

Posted: Tue May 18, 2021 11:22 am
by freddyp
Based on the example request the API does not expect parameters, but a body with a JSON in it. There is an app "Make JSON" that can create a file with the JSON content using Switch variables and then you post that using "HTTP request".

Re: HTTP request parameters

Posted: Tue May 18, 2021 11:07 pm
by Scott_PC79
I added make JSON to the flow and set the variables but the problem now seems to be the [ after items. I keep getting a 'spaces are not allowed in a variable definition in JSON code'. I tried omitting them and changed them to { but I keep getting a BadRequest error. Now what?

Re: HTTP request parameters

Posted: Tue May 18, 2021 11:18 pm
by jan_suhr
Do you have double quotes around the variables?

Like this:

Code: Select all

"Items": "[Metadata.Text:Path='/dn:OrderInfo/dn:OrderItems[1]/dn:PresseroOrderItem/dn:ItemId[1]',Dataset='Original',Model='XML']"
Note the single quotes inside the variable!

Re: HTTP request parameters

Posted: Thu May 20, 2021 11:05 pm
by Scott_PC79
double quotes didn't work either. The webserver API support is telling me that the payload is correct but there must be something wrong in the actual request I'm sending. I'm not sure what it could be because I'm able to send other request just fine.

Re: HTTP request parameters

Posted: Fri May 21, 2021 8:04 am
by freddyp
Are you using POST (you probably should)? Are you using MIME encoding (you probably should not)? I assume the JSON file you make with "Make JSON" is the input job: did you define "Attached file" as [Job.Path]? Is the web service expecting certain headers?

The other requests are fine: how do those work?

Re: HTTP request parameters

Posted: Fri May 21, 2021 8:56 pm
by Scott_PC79
It's working now! I attached the job as [Job.Path] and added Content-Type:application/json to the header. Thanks for everyones help.