1

I am posting the details of user in api ,using the access token in header which i got in sign up but getting this error --> Unexpected end of JSON input. My code is

     postNameToApi() 
        {

        console.log("inside post api");
        fetch('https://MyPostApi', {
          method: 'POST',
          headers: {
                  'Accept': 'application/json',
                  'Content-Type': 'application/json',
                  'Authorization':'Bearer'+'Qwjubq41KAWw9uI2NMj4TPQ9t24PxC'
                },


          body: JSON.stringify({
          dob:'1992-04-18',
          gender: 'femanino',
          is_professional:true,
          is_referee:false

        })
           }).then((response) => response.json())
             .then((responseData) => {
                                console.log("inside responsejson");
                                console.log('response:',responseData);

                       //this.setState({response:responseData});
         }).done();
     }
2
  • Did you check whether the response is OK at all (or a 403)? Did you check whether the response body is JSON? What does the the network panel of your devtools say about the response? Commented Sep 20, 2016 at 11:31
  • yes I did. @Bergi Commented Sep 27, 2016 at 12:22

1 Answer 1

2

This is because your response is not in json format. Space is missing between Bearer and your token, i think this will solve your issue.

'Authorization':'Bearer '+'Qwjubq41KAWw9uI2NMj4TPQ9t24PxC'

Try your api call with postman first.

Sign up to request clarification or add additional context in comments.

1 Comment

Please explain why the missing space causes the response format to change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.