loading...

Unable to POST array of objects in axios

gurupal profile image Gurupal Singh Updated on ・1 min read

why this post method is showing data: {key: "data"} ? Anyone ?

handleUpload() {
    const companyuid = this.props.match.params.id;
    var raw = 
                {
                    "data":[
                                {
                                    "type": "CRN",
                                    "value": this.state.cr_number,
                                    "files": [this.state.UUID_CRN]
                                },
                                {
                                    "type": "VRN",
                                    "value": this.state.vat,
                                    "files": [this.state.UUID_VAT]
                                },
                                {
                                    "type": "CON",
                                    "value": this.state.vat,
                                    "files": [this.state.UUID_VAT]
                                }
                            ]
                };

    let AUTH_TOKEN = window.localStorage.getItem("ACCESSTOKEN");

    fetch(
      "http://xxxx/documents",
      {
        method: "POST",
        headers: {
          Accept: "application/json",
          "Content-Type": "application/json",
          Authorization: Bearer ${AUTH_TOKEN}
        },
        body: JSON.stringify(raw)
      }
    )
      .then(response => response.json())
      .then(responseJson => {
        console.log(responseJson);
      })
      .catch(error => console.log("error", error));
  }

Posted on by:

Discussion

markdown guide
 

Is this error showing when you are parsing it back to JSON?

 

It's resolved .. Thanks for the reply though :)