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.