0

this is the API call

export const socialPostUpdateBio = (publicKey,sig,about)=>{  

  let data=
  "pub="+ publicKey+
  "&sig="+ sig.sig+
  "&about="+about

  console.log('====',data)

  fetch('https://endpoint/postUpdateBio', {
method: 'POST',
headers: new Headers({
  "Content-Type": "application/x-www-form-urlencoded", // <-- Specifying the Content-Type
  Accept: "application/json"
}),
body:data
}).then((response) => response.json())
.then((responseJson) => {
  console.log("New post updateBio",responseJson);
  return responseJson.movies;
})
.catch((error) => {
console.error(error);
});
}

this is data about:Its coming as a string not as a object

{name:"Guruprakash Gupta",dob:"14/08/1997",location:"Bangalore",bio:"Gratitude",sex:"Male",profile_pic:"QmdDjpQ3G6vg7zkU2BBPMQJYsnnRtTEDEtL9xBXjvPh4i4-image-jpg"}

before api call we have a one more function where we are signing the data with private key,so signing of data is correct here so i haven't inculded that function.

this is what response im getting

Response {type: "default", status: 524, ok: false, statusText: undefined, headers: Headers, …}type: "default"status: 524ok: falsestatusText: undefinedheaders: Headers {map: {…}}url: "https://murmurjapi.wandx.co/accounts/postUpdateBio"_bodyInit: Blobdata: (...)size: (...)type: (...)_data: {size: 4831, offset: 0, blobId: "d07d8515-51de-48c1-950d-7d9a77c8c640"}size: 4831offset: 0blobId: "d07d8515-51de-48c1-950d-7d9a77c8c640"__proto__: Object__proto__: Objectdata: (...)size: (...)type: (...)constructor: ƒ Blob()slice: ƒ slice(start, end)close: ƒ close()get data: ƒ ()set data: ƒ (data)get size: ƒ ()get type: ƒ ()__proto__: Object_bodyBlob: Blob {_data: {…}}__proto__: ObjectbodyUsed: false_initBody: ƒ (body)blob: ƒ ()arrayBuffer: ƒ ()text: ƒ ()formData: ƒ ()json: ƒ ()clone: ƒ ()constructor: ƒ Response(bodyInit, options)__proto__: Object
Sivakumar A
  • 601
  • 1
  • 6
  • 16
guruprakash gupta
  • 877
  • 4
  • 9
  • 15
  • your question is not clear, what problem are you facing? – Sivakumar A Jan 20 '20 at 07:11
  • when im calling the api, its throwing an error Unexpected token < in JSON at position 0,in API im sending only 3 data public_key,sign, and about, so all my data is correct then why im getting this error ? – guruprakash gupta Jan 20 '20 at 07:15
  • just put console.log(response) in the first then(), and please edit the question with the response. I think response itself not coming as json. we want to verify that – Sivakumar A Jan 20 '20 at 07:21
  • i have update it as u asked it ,please check it – guruprakash gupta Jan 20 '20 at 07:39
  • please undo the changes and add the responseJson in the question? please show that also – Sivakumar A Jan 20 '20 at 08:13
  • 1
    Does this answer your question? ["SyntaxError: Unexpected token < in JSON at position 0"](https://stackoverflow.com/questions/37280274/syntaxerror-unexpected-token-in-json-at-position-0) – SDushan Jan 20 '20 at 08:24

1 Answers1

0

You're receiving HTML (or XML) back from the server, but response.json() telling XML or HTML to parse as JSON. Parser cannot parse XML or HTML, so it's showing this error. Check the "Network" tab in Chrome dev tools or postman client to see contents of the server's response.

Sivakumar A
  • 601
  • 1
  • 6
  • 16