1
votes

I am working on a project that talks with an API, my script is in nodeJS (it's a big project so I will give you a very simplified version)

Essentially when I do a PUT request to the API, with the postman, it works fine, When I do it with my Code: GET works great (so I know the URL is correct), but PUT doesn't work with my script, I get no errors on my console, and the API simple sends back the OK status, so I have no clues where it went wrong

Here is a very basic version of my script (that doesn't work either)

(I know the URL is correct)

PUT parameters:

{ method: 'PUT',
  baseUrl: 'https://fusionrv.XXXX.XX/fusion/apiservice',
  url:
   'XXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXX',
  qs:
   { auth:
      'AUTH_KEY',
     value: 1 },
  headers: { 'content-type': 'application/json' } }

simple code (without the imports):

request(putParams, (err, res) => {
    if (err) console.log(err);
    data = JSON.parse(res.body)
    console.log(data)
});

In Postman, I have the same baseURL and url, as well as the same params "auth" and "value", the body is set to "none", and headers are Content-type: application/json.

The response (both in Postman and NodeJS):

{
    "Status": "Success"
}

So does anyone know why it works with postman but not with the request module? I appreciate all of you!

2
What you using to make the request? - codejockie
How are you doing the PUT request? What tool or framework are you using? Have you tried to change the qs to body? - vmf91
Sorry, I am using the request module in Node.js, and postman obviously, and it's a query string that is sent to the API, it's an empty body. - Andrew Jouffray
Might be this link useful - Rasa Mohamed

2 Answers

0
votes

Turns out the issue was with the API, I needed to do a POST request and use a different URL to access it, it's a very strange API.

0
votes

Add user-agent as part of the header

'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'