HTTP request parameters

Post Reply
Scott_PC79
Newbie
Posts: 7
Joined: Wed Apr 14, 2021 7:13 pm

HTTP request parameters

Post 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?
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: HTTP request parameters

Post 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".
Scott_PC79
Newbie
Posts: 7
Joined: Wed Apr 14, 2021 7:13 pm

Re: HTTP request parameters

Post 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?
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: HTTP request parameters

Post 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!
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
Scott_PC79
Newbie
Posts: 7
Joined: Wed Apr 14, 2021 7:13 pm

Re: HTTP request parameters

Post 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.
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: HTTP request parameters

Post 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?
Scott_PC79
Newbie
Posts: 7
Joined: Wed Apr 14, 2021 7:13 pm

Re: HTTP request parameters

Post 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.
Post Reply