Axios POST fails with 422, but Node Native works, Postman works, CURL works, requests works

Alaxandros
Tourist
4 0 2

EDIT-> Nevermind this. I fixed it.

 

I'm ready to break down in tears. Below you can see my Axios request/response, but before you pick it apart, know it also fails when I generate similar code directly from a working postman POST. This means that I set up my options in Postman, I click "Send," I get back a valid response, then I generate the code, paste it in a node file, and it fails similar to the below error. Also keep in mind that this POST works in every other language/library I've tried, it seems very specific to Axios. Also, I don't need to JSON.stringify the data, Axios does that for me.

 

Relevant response header: 'x-request-id': '7c77db7d-964b-45df-8e93-ea59411ae6e9'

 

 

const axios = require('axios');

const data = {"customer":
{"email":null,
"first_name":null,
"last_name":null}
};


var post_config = {
method: 'POST',
url: 'STORE/admin/api/2021-01/customers.json',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': 'TOKEN HERE',
},
data: data
};

axios(post_config)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});

 

 

0 Likes