HTTP request parameters

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

HTTP request parameters

Post by Scott_PC79 » Mon May 17, 2021 11:11 pm

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: 691
Joined: Thu Feb 09, 2012 3:53 pm

Re: HTTP request parameters

Post by freddyp » Tue May 18, 2021 11:22 am

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: 6
Joined: Wed Apr 14, 2021 7:13 pm

Re: HTTP request parameters

Post by Scott_PC79 » Tue May 18, 2021 11:07 pm

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: 477
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: HTTP request parameters

Post by jan_suhr » Tue May 18, 2021 11:18 pm

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: 6
Joined: Wed Apr 14, 2021 7:13 pm

Re: HTTP request parameters

Post by Scott_PC79 » Thu May 20, 2021 11:05 pm

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: 691
Joined: Thu Feb 09, 2012 3:53 pm

Re: HTTP request parameters

Post by freddyp » Fri May 21, 2021 8:04 am

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: 6
Joined: Wed Apr 14, 2021 7:13 pm

Re: HTTP request parameters

Post by Scott_PC79 » Fri May 21, 2021 8:56 pm

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