Anchor to customerMergecustomer
customerMerge
mutation
Requires access scope.
Merges two customers.
Anchor to Arguments
Arguments
- Anchor to customerOneIdcustomer•
One Id ID!required The ID of the first customer that will be merged.
- Anchor to customerTwoIdcustomer•
Two Id ID!required The ID of the second customer that will be merged.
- Anchor to overrideFieldsoverride•
Fields The fields to override the default customer merge rules.
Was this section helpful?
Anchor to CustomerMergePayload returnsCustomerMergePayload returns
- •
The asynchronous job for merging the customers.
- Anchor to resultingCustomerIdresulting•
Customer Id The ID of the customer resulting from the merge.
- Anchor to userErrorsuser•
Errors [CustomerMerge non-nullUser Error!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Merge customers with override fields
- Merge two customers
- customerMerge reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CustomerMerge {
customerMerge(customerOneId: "gid://shopify/Customer/544365967", customerTwoId: "gid://shopify/Customer/624407574", overrideFields: {customerIdOfFirstNameToKeep: "gid://shopify/Customer/544365967", customerIdOfLastNameToKeep: "gid://shopify/Customer/624407574"}) {
resultingCustomerId
job {
id
done
}
userErrors {
code
field
message
}
}
}`,
{
variables: {
"customerOneId": "gid://shopify/Customer/544365967",
"customerTwoId": "gid://shopify/Customer/624407574",
"overrideFields": {
mutation CustomerMerge {
customerMerge(customerOneId: "gid://shopify/Customer/544365967", customerTwoId: "gid://shopify/Customer/624407574", overrideFields: {customerIdOfFirstNameToKeep: "gid://shopify/Customer/544365967", customerIdOfLastNameToKeep: "gid://shopify/Customer/624407574"}) {
resultingCustomerId
job {
id
done
}
userErrors {
code
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation CustomerMerge { customerMerge(customerOneId: \"gid://shopify/Customer/544365967\", customerTwoId: \"gid://shopify/Customer/624407574\", overrideFields: {customerIdOfFirstNameToKeep: \"gid://shopify/Customer/544365967\", customerIdOfLastNameToKeep: \"gid://shopify/Customer/624407574\"}) { resultingCustomerId job { id done } userErrors { code field message } } }",
"variables": {
"customerOneId": "gid://shopify/Customer/544365967",
"customerTwoId": "gid://shopify/Customer/624407574",
"overrideFields": {
"customerIdOfFirstNameToKeep": "gid://shopify/Customer/544365967",
"customerIdOfLastNameToKeep": "gid://shopify/Customer/544365967"
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation CustomerMerge {
customerMerge(customerOneId: "gid://shopify/Customer/544365967", customerTwoId: "gid://shopify/Customer/624407574", overrideFields: {customerIdOfFirstNameToKeep: "gid://shopify/Customer/544365967", customerIdOfLastNameToKeep: "gid://shopify/Customer/624407574"}) {
resultingCustomerId
job {
id
done
}
userErrors {
code
field
message
}
}
}`,
{
variables: {
"customerOneId": "gid://shopify/Customer/544365967",
"customerTwoId": "gid://shopify/Customer/624407574",
"overrideFields": {
"customerIdOfFirstNameToKeep": "gid://shopify/Customer/544365967",
"customerIdOfLastNameToKeep": "gid://shopify/Customer/544365967"
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation CustomerMerge {
customerMerge(customerOneId: "gid://shopify/Customer/544365967", customerTwoId: "gid://shopify/Customer/624407574", overrideFields: {customerIdOfFirstNameToKeep: "gid://shopify/Customer/544365967", customerIdOfLastNameToKeep: "gid://shopify/Customer/624407574"}) {
resultingCustomerId
job {
id
done
}
userErrors {
code
field
message
}
}
}`,
"variables": {
"customerOneId": "gid://shopify/Customer/544365967",
"customerTwoId": "gid://shopify/Customer/624407574",
"overrideFields": {
"customerIdOfFirstNameToKeep": "gid://shopify/Customer/544365967",
"customerIdOfLastNameToKeep": "gid://shopify/Customer/544365967"
}
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation CustomerMerge {
customerMerge(customerOneId: "gid://shopify/Customer/544365967", customerTwoId: "gid://shopify/Customer/624407574", overrideFields: {customerIdOfFirstNameToKeep: "gid://shopify/Customer/544365967", customerIdOfLastNameToKeep: "gid://shopify/Customer/624407574"}) {
resultingCustomerId
job {
id
done
}
userErrors {
code
field
message
}
}
}
QUERY
variables = {
"customerOneId": "gid://shopify/Customer/544365967",
"customerTwoId": "gid://shopify/Customer/624407574",
"overrideFields": {
"customerIdOfFirstNameToKeep": "gid://shopify/Customer/544365967",
"customerIdOfLastNameToKeep": "gid://shopify/Customer/544365967"
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"customerOneId": "gid://shopify/Customer/544365967",
"customerTwoId": "gid://shopify/Customer/624407574",
"overrideFields": {
"customerIdOfFirstNameToKeep": "gid://shopify/Customer/544365967",
"customerIdOfLastNameToKeep": "gid://shopify/Customer/544365967"
}
}
Response
JSON{
"customerMerge": {
"resultingCustomerId": "gid://shopify/Customer/624407574",
"job": {
"id": "gid://shopify/Job/ab22429a-ea18-4dad-ac2c-5823288b1e59",
"done": true
},
"userErrors": []
}
}