Unable to write Draft Orders to Shopify store

Hi there,

I hope someone can give me any clues.

I have an external Ruby on Rails application, and within my application I’ve set up an integration with a Shopify store.

Through the building process, I’ve been using my Shopify Dev store to test everything. It all works well. I’m able to create Draft Orders with the Admin API, and then initiate a Shopify Checkout for users to pay, after which the order is created. When testing this in Insomnia, I send the query, get a 201 Success, and it returns the successfully created draft order.

But now, it is time to test it all out in the actual Production Shopify store. In this store, I have all the required permissions, the exact same as in my Dev store. I am able to successfully fetch any data, like products and orders. But, I seem unable to write anything. When I try to create a draft order, instead of a 201 with the returned Draft Order, it produces a 200, and lists a heap of irrelevant old draft orders. When I try to create an Order with CreateOrder, I get a 404 Not Found.

I have spoken to Support about this, and they reset the cache of the store, though that hasn’t helped. I’m currently waiting for a reply from the Shopify Developer team, but in the meantime, thought I’d see if anyone can shed some light?

The Production store is an older store (I think 8-10 years old), and they have thousands of Orders and Draft Orders in their database. Below is the Draft Order query that works in my Dev store, but not in the Production store.

Thanks in advance to anyone who can contribute!

Hey @Daniel_Kelly :waving_hand: - would you be able to share an X-Request-ID from the API response headers we send out with each API response? I can’t say for sure given the information here what is causing the 404/201 responses you’re seeing when the mutations are run through your app, but if you’re able to share that request ID, I can take a direct look in the logs on our end and investigate further for you.

You should be able to grab those request ID headers using NET::HTTP, if you aren’t already (or through your app’s HTTP client/integration): Class: Net::HTTP (Ruby 2.7.0)

Hope to hear from you soon - happy to look into this for sure.

Hey @Alan_G! Thanks for helping with this. I’ll give you some X-Request-ID’s from a few query attempts. I’m doing these straight from Insomnia.

1.
URL (POST): admin/api/2023-01/graphql.json
Graph QL query:

query {
  draftOrders(first: 10) {
    edges {
      node {
        id
      }
    }
  }
}

Response: 404 Not Found
X-Request-ID: 11017284-d39e-4a0b-aef8-a4bbad275856-1747535355

2.
URL (POST): admin/api/2024-07/graphql.json
Graph QL mutation:

mutation {
  draftOrderCalculate(
    input: {
      purchasingEntity: {
        purchasingCompany: {
          companyId: "gid://shopify/Company/1"
          companyLocationId: "gid://shopify/CompanyLocation/1"
          companyContactId: "gid://shopify/CompanyContact/1"
        }
      }
      billingAddress: {
        address1: "123 Main St"
        city: "Sample City"
        provinceCode: "CA"
        zip: "90210"
      }
      lineItems: [
        {
          originalUnitPrice: "100.00"
          quantity: 2
          variantId: "gid://shopify/ProductVariant/123"
        }
      ]
    }
  ) {
    calculatedDraftOrder {
      totalPrice
    }
    userErrors {
      field
      message
    }
  }
}

Response: 404 Not Found
X-Request-ID: 08b2c034-2048-4bf2-a2d0-045c184de8ff-1747535635

3.
URL: admin/api/2024-07/graphql.json
Graph QL mutation:

mutation CreateDraftOrder {
  draftOrderCreate(input: {
    lineItems: [
      {
        title: "Test Only",
        price: "10.00",
        quantity: 1
      }
    ],
    note: "API Test Only - Please Delete"
  }) {
    draftOrder {
      id
      totalPrice
      lineItems {
        edges {
          node {
            title
            quantity
          }
        }
      }
      note
    }
    userErrors {
      field
      message
    }
  }
}

Response: 404 Not Found
X-Request-ID: 651a969c-d1cf-4581-841f-7b6506fbede6-1747536396

4.
REST API POST Request
URL: admin/api/2024-07/draft_orders.json
Request Body:

{
    "draft_order": {
      "line_items": [
        {
          "title": "Test Only",
          "price": "10.00",
          "quantity": 1
        }
      ],
      "note": "API Test Only - Please Delete"
    }
  }

Response: 200 OK
So with this one, when doing the exact same in my dev store, I get a 201 Created and it returns the new draft order. But in this Production store, it gives a 200 OK, and returns other old draft orders, rather than creating and returning a new one.
X-Request-ID: ade3154f-4ac1-4643-91b1-a4284ea8cbbe-1747091808

So overall, I’m currently able to use the REST API to fetch orders and products etc. But, trying to use the REST API to Write seems to return the 200 instead of 201 Created. It seems that none of my GraphQL attempts work, both mutations and queries.

The Storefront API seems to be working fine for me though. Users are able to login and get access tokens etc.

Thanks for the logs @Daniel_Kelly - really appreciate you send those over! I did some digging on my end and in our logs the four request IDs below were tied to GET requests rather than POST requests:

08b2c034-2048-4bf2-a2d0-045c184de8ff-1747535635
11017284-d39e-4a0b-aef8-a4bbad275856-1747535355
651a969c-d1cf-4581-841f-7b6506fbede6-1747536396
ade3154f-4ac1-4643-91b1-a4284ea8cbbe-1747091808

This is likely why we were returning 404/4xx errors (and the 200 response for the REST GET call) - for our GraphQL API, even if the request is just a query for data, it should be sent as a POST request. I think formatting the requests as a POST should solve the issue for these (I would check your API client to make sure the requests are set as POST requests), but if you do see any more issues with these just let me know and I can take a look!

Hope this helps a little bit.

Hi @Alan_G, well perhaps we’re getting closer to the issue. You see, I am indeed sending all of these as POST Requests. Yet, sounds like Shopify is getting them as GET Requests. Please see my Loom video below (3 mins) which shows my testing in Insomnia.

I know that the Production store has 37 apps installed in their Shopify store, could there be something intercepting my POST requests?

Below are the x-request-ids of the examples I showed in the video:

REST API POST Request to Create Draft Order (Production Store):
6c590cac-758e-47ee-a6b2-362b72293717-1747782366

REST API POST Request to Create Draft Order (Dev Store):
0e6f9773-7809-4da6-8473-702dec02b96c-1747782411

GraphQL POST Request mutation (Production Store):
4a0bcad2-fc05-4b90-abf6-2c58be7b5d24-1747782466

Hey @Daniel_Kelly - thanks for sharing that video, I really appreciate it! I noticed you’re using the branded URL for the shop: http://empiricalhealthshop.com.au/, for API calls, we do require the myshopify.com URL for shops to be used. Could you try using the myshopify.com URL for the shop and letting me know if that resolves the issue?

If not, just ping me here and we can keep digging for sure.

1 Like

@Alan_G Boom! That was the fix. Thanks!

1 Like

No worries @Daniel_Kelly - glad that worked! :raising_hands: