Hey there, I’m a newbie with Shopify API (and APIs in general) so please be gentle. I have a development store where I’m testing a my first private app that will create a draft order for a customer who has products in their cart.
But I’m not even that far yet, I’m just trying to submit a new draft order successfully with manually-entered JSON data that I copy/pasted from the reference docs, and the result I’m getting is a 200 OK response status, instead of the 201 Created response that Shopify API Docs gives in its example. https://shopify.dev/docs/admin-api/rest/reference/orders/draftorder#create-2020-10
In addition to the 200 OK response status, my result object is undefined.
I’m using a basic JS call with fetch(url,json)
to POST to the /admin/api/2020-10/draft_orders.json
endpoint.
My console code is below. Can anyone spot what I’m doing wrong?
var obj = {
return {
"draft_order": {
"line_items": [
{
"id": 6121005744299,
"title": "Fancy Pants",
"price": "9.99",
"quantity": 2
}
],
"customer": {
"id": 4508630712491
},
"use_customer_default_address": true
}
};
}
var url = '/admin/api/2020-10/draft_orders.json'
var fetchBody = () => {
return {
'method': 'POST',
'headers': {
'X-Shopify-Storefront-Access-Token': '4c83ecf984755b699086217a8dc40e76',
'Content-Type': 'application/json'
},
'body': JSON.stringify(obj)
};
}
console.log(url,obj,JSON.stringify(obj))
fetch(url,fetchBody())
.then(response => {
console.log(response)
})
.then(result => {
console.log('result',result)
})