HTTP POST a body

Post Reply
Paulyy
Newbie
Posts: 9
Joined: Tue Aug 29, 2023 8:05 am

HTTP POST a body

Post by Paulyy »

Hi All,

Im a little stuck on how to use the HTTP Post a body request.
I have HTTP GET working to download files, do API Calls with parameters / headers etc.

I just cant get the the POST a Body working.
I've written the JSON data in the "Create a txt file" with input job.
i've tried to set it as the body content. etc.

and i get back an error "invalid token" which means it hasn't sent the json.

I have it working in POSTMAN so i know it's all correct and working.

**Example POST**

https://www.myurl.com.au/services/api.p ... plate+info

JSON:

Code: Select all

{
  "method": "setOrderStatus",
  "token": "QWASUjsh1221",
  "order_id": 16,
  "order_status": 2,
  "comment": "order status has been updated",
  "notify": 1,
  "courier_company_name": "test",
  "tracking_number": "1234",
  "product_info": "This is Standard Product",
  "template_info": "This is template info"
}

Any help is appreciated!
Thanks
Last edited by Paulyy on Tue Feb 13, 2024 2:19 pm, edited 1 time in total.
r.zegwaard
Member
Posts: 89
Joined: Fri Jul 08, 2011 10:31 am
Location: The Netherlands

Re: HTTP POST a body

Post by r.zegwaard »

I use the HTTP Post as follows:
  • Incoming job is the json-body to send
  • Property "Attached file" references this as in the screenshots
Image

Image
Paulyy
Newbie
Posts: 9
Joined: Tue Aug 29, 2023 8:05 am

Re: HTTP POST a body

Post by Paulyy »

Hmm i've tried this.
I just coped your whole http post aswell.
it just passes the json or txt file as an error. "Request finish tatus: not found"

What goes into the headers?
freddyp
Advanced member
Posts: 1000
Joined: Thu Feb 09, 2012 3:53 pm

Re: HTTP POST a body

Post by freddyp »

"POST a body" with "Body content - Input job" and "POST" with "Attached file - [Job.Path]" do the same thing.

It is common for web services that work with tokens to expect the token in one of the headers. There is a token in your JSON but that is perhaps not enough. Only the documentation can tell, or wait, Postman works, then you "just" have to look at how the Postman request is configured and translate that to "HTTP request". If you cannot make it work, export it from Postman and share it.
Paulyy
Newbie
Posts: 9
Joined: Tue Aug 29, 2023 8:05 am

Re: HTTP POST a body

Post by Paulyy »

this is my post request that works. (for security reasons ive changed the URL and token)

i exported this from Postman.

curl --location --request POST 'https://www.myurl.com.au/services/api.p ... A&notify=1' \
--header 'Cookie: T1BTU0VT=bi90rjf1j674v36bepk8tcd2s2'

I am still newish to all this, so please bear with me.
freddyp
Advanced member
Posts: 1000
Joined: Thu Feb 09, 2012 3:53 pm

Re: HTTP POST a body

Post by freddyp »

Ah, right. Cookies. Probably in combination with redirects. You can check that if you deactivate following redirects in Postman (in the Settings of the request). What I think you are going to see is not a 200 status code but a 3xx and in the response headers you will find that cookie.

If that is the case then v20 of "HTTP request" will solve that. It is still in beta but you can access it and install it.

Background explanation: when you browse to a certain url you often see that you end up on a different url. That is because the web server responds to the original url with a redirect to go to another url. This can happen several times before you end up on the correct page, but as a user you do not notice that (if you do not check the urls that is). "HTTP request" follows the redirects automatically, but if a web server included a cookie with the redirect, Pre-v20 "HTTP request" did not include it in the headers when following the redirect.
Paulyy
Newbie
Posts: 9
Joined: Tue Aug 29, 2023 8:05 am

Re: HTTP POST a body

Post by Paulyy »

Edit.

I've got it working, thanks for some friends running the same system.

I was to busy focusing on sending json when it should have been in the parameters.

method=setOrderStatus
token=1234567890
type=product
order_id=12453
order_product_id=34276
order_status=1
order_product_status=32
comment=test
notify=1
Post Reply