orderCreate ignores a unique id metafield value already held by another order

When two orders are created with the same id-type custom metafield value, orderCreate silently creates the second order without the metafield value and returns no userErrors. This also applies to orders that have been deleted.

This is frustrating when trying to ensure duplicate orders are not imported when importing from another system.

productCreate works correctly - it returns an error to say it is already assigned.

Example GraphQL Admin API mutations are below. See the “Response 2 from orderCreate” section - rather than returning an error, it just creates the order, but without the metafield value

Order Create Example

Create Order Custom ID Metafield Definition

mutation CreateOrderTestIdDefinition {

  metafieldDefinitionCreate(

    definition: {

      name: "Test ID"

      namespace: "custom"

      key: "test-id"

      ownerType: ORDER

      type: "id"

    }

  ) {

    createdDefinition {

      id

      namespace

      key

      type { name }

      capabilities {

        uniqueValues { enabled }

      }

    }

    userErrors {

      field

      message

      code

    }

  }

}

Create Order with Custom ID Metafield


  mutation reproOrderCreate {

    orderCreate(

      order: {

        lineItems: [

          {

            title: "Test product"

            quantity: 1

            priceSet: { shopMoney: { amount: "10.00", currencyCode: GBP } }

          }

        ]

        metafields: [

          { namespace: "custom", key: "test-id", type: "id", value: "123" }

        ]

      }

    ) {

      order {

        id

        name

        metafield(namespace: "custom", key: "test-id") { value }

      }

      userErrors { field message }

    }

  }

Response 1 from orderCreate


  "orderCreate": {

    "order": {

      "id": "gid://shopify/Order/6718010360023",

      "name": "#1041",

      "metafield": {

        "value": "123"

      }

    },

    "userErrors": []

  }

}

Response 2 from orderCreate (silently imports without error)


  "orderCreate": {

    "order": {

      "id": "gid://shopify/Order/6718010392791",

      "name": "#1042",

      "metafield": null

    },

    "userErrors": []

  }

}

Product Create Example

Create Product Custom ID Metafield Definition

mutation reproDefinitionCreate {

    metafieldDefinitionCreate(definition: {

      name: "Test ID"

      namespace: "custom"

      key: "test-id"

      ownerType: PRODUCT

      type: "id"

    }) {

      createdDefinition { id }

      userErrors { field message code }

    }

  }

Create Product with Custom ID Metafield

  mutation reproProductCreate {

    productCreate(

      product: {

        title: "Test product"

        metafields: [

          { namespace: "custom", key: "test-id", type: "id", value: "123" }

        ]

      }

    ) {

      product {

        id

        title

        metafield(namespace: "custom", key: "test-id") { value }

      }

      userErrors { field message }

    }

  }

Response 1 from productCreate

{

  "productCreate": {

    "product": {

      "id": "gid://shopify/Product/9304904466647",

      "title": "Test product",

      "metafield": {

        "value": "123"

      }

    },

    "userErrors": []

  }

}

Response 2 from productCreate (fails with error)

{

  "productCreate": {

    "product": null,

    "userErrors": [

      {

        "field": ["metafields", "0", "value"],

        "message": "Value is already assigned to another metafield. Choose a different value to ensure it remains unique."

      }

    ]

  }

}

Hey @Stephen_Upchurch - thanks for the detailed repro here.

Just confirming my read on this: the duplicate id metafield value being rejected is expected, since id metafields enforce unique values. The part that doesn’t look right to me though is orderCreate still creating the second order, silently dropping the metafield, and returning no userErrors.

I’d like to flag this on our end. Could you share the x-request-id from the response headers for one of the orderCreate calls where the order was created but the metafield came back as null? If you also have one for the deleted-order case, that would be useful too.

For now, the safest workaround would be to check orderByIdentifier before import and verify the metafield after creation, but I definitely get that this isn’t ideal for duplicate prevention during imports. Hope to hear from you soon.

Hi @alan_g, thanks for getting back to me. Info requested below.

Request ID for an order where the metafield came back as null: f03e55e8-cd31-4c6c-9f00-10799361e717-1782407284’

Request ID for an order where the metafield came back as null where the previous order had which matching metafield value been deleted: fb891829-dd6a-4644-b029-ce90399c1bd8-1782407457

The problem with orderByIdentifier is if the order has been deleted it doesn’t find anything (as you would expect), but the order is created with a null metafield value.

Hey @Stephen_Upchurch - thanks for sending those over. I was able to trace both requests, and they line up with what you’re seeing. Basically, it looks like orderCreate does complete successfully, but the duplicate custom ID metafield isn’t set and no userErrors are returned.

The uniqueness check itself is expected for id metafields, but the silent behaviour here doesn’t look right. I’m going to flag this on our end as orderCreate should be surfacing a proper error instead of creating the order without the metafield.

One extra detail that would help: when you mention the previous order had been deleted, how was that order deleted? Was it removed through the Shopify admin, via an API call, or some other cleanup flow?

I’m just asking because orderByIdentifier not returning a deleted order makes sense, but the unique ID value still being unavailable to a new orderCreate call is the part I want to pin down. If the original order hadn’t been deleted, I’d expect orderByIdentifier to return it, so the deleted-order flow seems like the important distinction here.

Hi @Alan_G Thanks - the order was deleted in the Shopify Admin (by Clicking More Actions - Delete Order on the view order page).

Hey @Stephen_Upchurch - no worries, thanks for confirming!

I think there might be two pieces here: the deleted-order case looks related to order deletion retaining the unique metafield constraint after the order is soft-deleted, and the orderCreate response itself should be surfacing a proper userErrors entry instead of creating the order with the metafield omitted.

I’m flagging this internally and I’ll keep this thread updated when I have more to share.