DEV Community

Gurupal Singh
Gurupal Singh

Posted on • Edited on

Unable to POST array of objects in axios

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));
  }
Enter fullscreen mode Exit fullscreen mode

Top comments (5)

Collapse
 
adityamitra profile image
Aditya Mitra

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

Collapse
 
gurupal profile image
Gurupal Singh

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

Collapse
 
parasbuda profile image
Parasbuda

how you solved it im also stucked on this

Collapse
 
difafebri profile image
difa febri

hello, sir, can you tell me how you solved it? i got stuck in this similar situation. Any kind of response from you would be much appreciated. Thank you!

Collapse
 
rawalprashant profile image
Prashant Raval

Kindly post the solution so it can help others, like me too :)