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.