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?
HTTP request parameters
Re: HTTP request parameters
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".
-
- Newbie
- Posts: 7
- Joined: Wed Apr 14, 2021 7:13 pm
Re: HTTP request parameters
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
Do you have double quotes around the variables?
Like this:
Note the single quotes inside the variable!
Like this:
Code: Select all
"Items": "[Metadata.Text:Path='/dn:OrderInfo/dn:OrderItems[1]/dn:PresseroOrderItem/dn:ItemId[1]',Dataset='Original',Model='XML']"
-
- Newbie
- Posts: 7
- Joined: Wed Apr 14, 2021 7:13 pm
Re: HTTP request parameters
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
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?
The other requests are fine: how do those work?
-
- Newbie
- Posts: 7
- Joined: Wed Apr 14, 2021 7:13 pm
Re: HTTP request parameters
It's working now! I attached the job as [Job.Path] and added Content-Type:application/json to the header. Thanks for everyones help.