0

I am working on REST API.

From my end, everything seems to be fine. I've tried multiple libraries (AXIOS, request, fetch) in order to make a PUT call. However, I keep on getting 429 or 400 as a response code.

Below is the implemented code

const fetch = require('node-fetch');

const date= new Date();
const bodyData = `{"fields":
    { 
        "priority":{"name":"Blocker"}, 
        "date":"${date}"
    }
}`;

 await fetch('url', {
   method: 'PUT',
   headers: {
                'Authorization': `Basic ${Buffer.from('username:password').toString('base64')}`,
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
   body: bodyData
})
  .then((response) => { console.log(response.data) }) //print the result
  .catch((err) => {return res.json({'msg': "Something went wrong"})});

Observation:-

  1. The 429 error should not appear if the structure of the fetch call is incorrect.

I am not sure If am missing something, could you guys help me please?

RAJENDRA H
  • 83
  • 10
  • 429 is too many requests ... not sure what you think it is ... are you saying if you bombard an API with incorrect "structure" it should always give 400? Perhaps the check for too many requests is done before the "structure" is even checked (that's how I'd do it, why waste CPU cycles validating the request body if someone is bombarding my API) – Jaromanda X Jul 28 '22 at 07:01
  • I'd just `const bodyData=JSON.stringify({fields:{priority:{name:"Blocker"},date}});` then you don't have to worry about all those `"` to create valid JSON as JSON.stringify handles it all for you – Jaromanda X Jul 28 '22 at 07:04
  • as for the 400 status ... only knowing what the server expects can answer that – Jaromanda X Jul 28 '22 at 07:08
  • HI @JaromandaX, I can understand API has Rate limiting feature, however, at least few times it should work in a while. – RAJENDRA H Jul 28 '22 at 07:10
  • sure ... but I guess that's when you get the 400 status because your request is bad – Jaromanda X Jul 28 '22 at 07:58

0 Answers0