I'm working on my React task. I've tried create new product and send it with post method. I use fetch and axios both. In both cases I got error 422. Here is Swager : https://newdemostock.gopos.pl/doc/swagger-ui/index.html?configUrl=%2Fv3%2Fapi-docs%2Fswagger-config&urls.primaryName=internal%20ajax&fbclid=IwAR0GUn4T42DxkREmZ6TNLdK5UlQYFPqEQltpmfCQ6iUBVDTwwIRBhoARoA8
Login: zadanie@gopos.pl
password: testI've tried this endpoints : https://newdemostock.gopos.pl/ajax/219/products/create
Authorization: fd9ba9e1-0788-4e8f-ac46-a43df43e205e
OrganizationId : 219
Maybe I should have used another eindpoit? Does anyone know how I can solve this problem?const NewProduct = () => {
const product = {
name: "test",
item_name: "test",
};
const axiosConfig = {
headers: {
Authorization: `fd9ba9e1-0788-4e8f-ac46-a43df43e205e`,
"content-type": "application/json",
Accept: "application/json",
// mode: "cors",
// credentials: "same-origin",
},
};
const sendProduct = async () => {
axios
.post(
"https://newdemostock.gopos.pl/ajax/219/products/create",
product,
axiosConfig
)
.then((res) => {
console.log("RESPONSE RECEIVED: ", res);
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
});
// fetch("https://newdemostock.gopos.pl/ajax/219/products/create", {
// credentials: "same-origin",
// method: "post",
// mode: "cors",
// headers: new Headers({
// Authorization: "fd9ba9e1-0788-4e8f-ac46-a43df43e205e",
// "Content-Type": "application/json",
// Accept: "application/json",
// }),
// body: JSON.stringify(product),
// })
// .then((resp) => console.log(resp))
// .catch((err) => console.log(err));
};
return (
<div>
<button onClick={sendProduct}>Send</button>
</div>
);
};
422 error means the request is well formed but not processable. So it seems your requests are making it to the desired endpoint but the server is unable to process them there.
If you have access to the backend server I would recommend adding console.logs to the route you are trying to hit, hit it with postman or your local client and then check the server logs. If you don't have access to the server I would double check any documentation the server custodians have provided and maybe get in touch with them.