I am getting this error while creating orders programmatically.
My code:
router.post(“/createOrders”, verifyRequest(), async (ctx, res) => {
const { shop, accessToken } = ctx.session;
const url = https://${shop}/admin/api/2021-07/orders.json;
// const session = await Shopify.Utils.loadCurrentSession(ctx.req, ctx.res);
ctx.body = ctx.request.body;
// console.log(ctx.request.body[0].line_items);
const shopifyHeader = (Token) => ({
“Content-Type”: “application/json”,
“X-Shopify-Access-Token”: Token,
});
const data = {
order: {
email: “adam123445@example.com”,
fulfillment_status: “fulfilled”,
fulfillments: [{ location_id: 487523303 }],
line_items: [{ variant_id: 447656429, quantity: 1 }],
},
};
const myorder = await axios
.post(url, data, {
headers: shopifyHeader(accessToken),
})
.then((res) => console.log(res));
console.log("result: ", res);
});
Error: Request failed with status code 422
at createError (D:\ShopifyApps\SkuShopify\node_modules\axios\lib\core\createError.js:16:15)
at settle (D:\ShopifyApps\SkuShopify\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (D:\ShopifyApps\SkuShopify\node_modules\axios\lib\adapters\http.js:269:11)
at IncomingMessage.emit (events.js:412:35)
at endReadableNT (internal/streams/readable.js:1317:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21)