You can create custom IDs when you need a reliable unique identifier to match resources across multiple shops and/or systems (e.g. ERPs, CRMs, PIMs). This guide shows you how to create and manage custom IDs using Metafields in the GraphQL Admin API.
Any developer who uses external systems (e.g., PIM, ERP) and wants to create a mapping of identifiers to manage data migration and synchronization with Shopify.
PRODUCT
requires the same access as mutating a product.ID metafield types are automatically configured to have unique values.
Look up by custom ID is not available for all resource types. It is currently supported for:
Create or update by custom ID is not available for all reference types. It is currently supported for:
productSet
)customerSet
)Look up by custom ID is only available using the GraphQL Admin API.
You can create an ID metafield definition using the GraphQL Admin API's createMetafieldDefinition
mutation
The following example creates a pinned id
metafield definition for the product owner type:
Add a metafield to the corresponding resource type using the id type with the namespace and key for your definition. For example, add a metafield to a new product if you created a product metafield definition.
Add a metafield to the corresponding resource type using the id
type with the namespace and key from your definition. In the following example, add a metafield to an existing product if you've created a product metafield definition.
After you've added the Custom ID metafield to a resource, you can look up that resource by its custom ID. Here are some examples of available GraphQL Admin API queries:
If you've created a product metafield definition, then use the productByIdentifier
query.
If you've created a customer metafield definition, then use the customerByIdentifier
query.
If you've created an order metafield definition, then use the orderByIdentifier
query.
Similar ByIdentifier
queries are available for other supported resource types like collections and product variants.
The following example looks up a product by the Custom ID:
You can also update or create some resources by referencing their Custom ID. This is available for products via the productSet
mutation, and customers via customerSet
. When the identifier
argument for these mutations includes a custom ID, they will first look up a matching record. If one exists, the mutation will update it. Otherwise, the mutation will attempt to create a new record with the provided inputs.
The following example looks up a product using the Custom ID format from Step 4 and updates its title:
The following example demonstrates how productSet
creates a new product when the Custom ID doesn't match existing products:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4