Creating new draft order with Shopify DraftOrder API returns 200 OK instead of 201 Created

Solved
Fowlertown_Web_
Shopify Partner
18 1 3

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 as an 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 help me turn this 200 into a 201?

 

 

 

 

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)
})

 

 

 

 

 

0 Likes
Fowlertown_Web_
Shopify Partner
18 1 3

This is an accepted solution.

This is now a duplicate post, since it was rejected at first I posted a new message.

https://community.shopify.com/c/Shopify-APIs-SDKs/REST-Admin-API-returns-200-OK-for-New-Draft-Order/...

0 Likes