HTTP Request POST (body)

Post Reply
User avatar
magnussandstrom
Advanced member
Posts: 342
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

HTTP Request POST (body)

Post by magnussandstrom »

Hi, I am bulding a flow where I want to send a Pitstop Preflight report as a HTTP POST with the HTTP Request element. I have been asked by our dev-guy to supply the report (as json or XML) in the "body" of the POST.

In my Switch flow the preflight report (as XML) is 'triggering' the HTTP Request element, but I can't figure out how to include the preflight report as 'body' in the POST.

Or maybe I can use the 'Attatched file' but I don't understand how I could select the 'incoming' XML-file?

Any suggestions?

ps. As you might understand from my question, I am not very good at API:s (yet) ;)
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: HTTP Request POST (body)

Post by freddyp »

If it is the XML file that triggers the HTTP request, then it is:
Request type - POST
Attached file - [Job.Path]
Use MIME encoding - No
User avatar
magnussandstrom
Advanced member
Posts: 342
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: HTTP Request POST (body)

Post by magnussandstrom »

Thanks Freddy, that worked!
nfulton
Newbie
Posts: 10
Joined: Thu Jul 21, 2022 3:00 pm
Contact:

Re: HTTP Request POST (body)

Post by nfulton »

What if my "body" is not in a file but rather variables I am pulling from a dataset? An example of my body is below.

{
"JobNo": "[Metadata.Text:Dataset="job",Model="JSON",Path="/JobNo"]",
"CustomerRef1": "123",
"CustomerRef2": "1234",
"Ref4": "[Job.UserFullName]"
}
mkayyyy
Member
Posts: 73
Joined: Mon Nov 21, 2016 6:31 pm
Location: UK

Re: HTTP Request POST (body)

Post by mkayyyy »

nfulton wrote: Tue Nov 01, 2022 2:25 pm What if my "body" is not in a file but rather variables I am pulling from a dataset? An example of my body is below.

{
"JobNo": "[Metadata.Text:Dataset="job",Model="JSON",Path="/JobNo"]",
"CustomerRef1": "123",
"CustomerRef2": "1234",
"Ref4": "[Job.UserFullName]"
}
To do this we use the Create text file app to generate a JSON file and then use the flow element properties @freddyp provided above.

Although it would be nice if the HTTP request element had functionality to be able to send a dynamic POST body rather than having to generate a file.
nfulton
Newbie
Posts: 10
Joined: Thu Jul 21, 2022 3:00 pm
Contact:

Re: HTTP Request POST (body)

Post by nfulton »

I added the Create text file element, and have it generating a .json file.
Then within the HTTP request element I have the Attached file set to: [Job.Path]
When I run the flow, my MIS send back a 500 Internal Server Error and acts like it never received the body.

I have this HTTP request successfully working in Postman (where they do support a proper body). So I know the MIS API is working, it's just the problem of sending the body. For reference Tharstern is my MIS and the call is /job/update.
mkayyyy
Member
Posts: 73
Joined: Mon Nov 21, 2016 6:31 pm
Location: UK

Re: HTTP Request POST (body)

Post by mkayyyy »

nfulton wrote: Fri Dec 09, 2022 4:15 pm I added the Create text file element, and have it generating a .json file.
Then within the HTTP request element I have the Attached file set to: [Job.Path]
When I run the flow, my MIS send back a 500 Internal Server Error and acts like it never received the body.

I have this HTTP request successfully working in Postman (where they do support a proper body). So I know the MIS API is working, it's just the problem of sending the body. For reference Tharstern is my MIS and the call is /job/update.
I'm not familiar with the Tharstern API but the only other I think you'd need to set on the request is the headers, in particular a Content-Type header. Have you got that header set on the HTTP Request element?
Post Reply