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."
}
]
}
}