Santam
Santam

Reputation: 301

Fetch Post Request with Parameters is returning 400 status code?

I have a Post Request using fetch in react native, but I get a status code 400 for this, what is wrong with the code?

function sendRequest2() {
    fetch(`https://sandbox-api.dexcom.com/v2/oauth2/token`, {
      method: "POST",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      body: JSON.stringify({
        code: "value1",
        client_id: "value2",
        client_secret: "value3",
        redirect_uri: "http://www.google.com",
        grant_type: "authorization_code",
      }),
    })
      .then((response) => {
        response.json();
      })
      .then((data) => {
        console.log(data);
      })
      .catch((err) => console.log("The error is: " + err));
  }

Upvotes: 2

Views: 890

Answers (2)

TARJU
TARJU

Reputation: 1994

You can try by removing JSON.stringify

That would solve the issue

Moreover you have shared a lot of open information regarding your server openly.

You must either hide it or add some dummy values. Sharing such a secure data openly is not recommended in open community.

Upvotes: 0

Romylussone
Romylussone

Reputation: 815

Check your content-type, replace it by :

headers: {
    "Content-Type": "application/json",
  },

helpfull link : application/x-www-form-urlencoded or multipart/form-data?

Upvotes: 0

Related Questions