Manage customer accounts with the Customer Account API
You can update customer accounts using the Customer Account API.
This guide covers how to update a customer, and accomplish common tasks like creating, updating and deleting an address on a customer.
Anchor to RequirementsRequirements
- You've completed the Getting started with the Customer Account API guide.
Anchor to Step 1: Update a customerStep 1: Update a customer
Customers are automatically created if needed when you call the API.
You update a customer using the customerUpdate
mutation. You can use this mutation to update the profile of a customer on your storefront.
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
mutation customerUpdate($input:CustomerUpdateInput!) {
customerUpdate(input:$input) {
customer {
id
firstName
lastName
}
userErrors {
field
message
code
}
}
}
Variables
{
"input": {
"firstName": "John",
"lastName": "Doe"
}
}
JSON response
{
"data": {
"customerUpdate": {
"customer": {
"id": "gid://shopify/Customer/1",
"firstName": "John",
"lastName": "Doe"
},
"userErrors": []
}
},
"extensions": {
"cost": {
"requestedQueryCost": 10,
"actualQueryCost": 10
}
}
}
Anchor to Step 2: Create an addressStep 2: Create an address
The following example shows how to use the customerAddressCreate
mutation to create a new address for a customer:
POST <https
GraphQL mutation
mutation addressCreate($addressInput:CustomerAddressInput!, $defaultAddress:Boolean) {
customerAddressCreate(address:$addressInput, defaultAddress:$defaultAddress) {
customerAddress {
id
address1
city
territoryCode
zoneCode
phoneNumber
zip
}
userErrors {
field
message
code
}
}
}
Variables
{
"addressInput": {
"lastName": "Doe",
"firstName": "John",
"address1": "123 Test Street",
"zoneCode": "QC",
"territoryCode": "CA",
"zip": "H3K0X2",
"city": "Montreal"
},
"defaultAddress": false
}
JSON response
{
"data": {
"customerAddressCreate": {
"customerAddress": {
"id": "gid://shopify/CustomerAddress/1",
"address1": "123 Test Street",
"city": "Montreal",
"territoryCode": "CA",
"zoneCode": "QC",
"phoneNumber": null,
"zip": "H3K0X2"
},
"userErrors": []
}
},
"extensions": {
"cost": {
"requestedQueryCost": 10,
"actualQueryCost": 10
}
}
}
Anchor to Step 3: Update an addressStep 3: Update an address
The following example shows how to use the customerAddressUpdate
mutation to update an existing address for a customer:
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
mutation addressUpdate($addressInput:CustomerAddressInput!, $addressId:ID!, $defaultAddress:Boolean) {
customerAddressUpdate(addressId:$addressId, address:$addressInput, defaultAddress:$defaultAddress) {
customerAddress {
id
address1
city
territoryCode
zoneCode
phoneNumber
zip
}
userErrors {
field
message
code
}
}
}
Variables
{
"addressId": "gid://shopify/CustomerAddress/1",
"addressInput": {
"address1": "456 Test Street",
"zip": "H3K8X2"
},
"defaultAddress": true
}
JSON response
{
"data": {
"customerAddressUpdate": {
"customerAddress": {
"id": "gid://shopify/CustomerAddress/1",
"address1": "456 Test Street",
"city": "Montreal",
"territoryCode": "CA",
"zoneCode": "QC",
"phoneNumber": null,
"zip": "H3K8X2"
},
"userErrors": []
}
},
"extensions": {
"cost": {
"requestedQueryCost": 10,
"actualQueryCost": 10
}
}
}
Anchor to Step 4: Delete an addressStep 4: Delete an address
The following example shows how to use the customerAddressDelete
mutation to create a new address for a customer:
POST <https
GraphQL mutation
mutation addressDelete($addressId:ID!) {
customerAddressDelete(addressId:$addressId) {
deletedAddressId
userErrors {
field
message
code
}
}
}
Variables
{
"addressId": "gid://shopify/CustomerAddress/2"
}
JSON response
{
"data": {
"customerAddressDelete": {
"deletedAddressId": "gid://shopify/CustomerAddress/2",
"userErrors": []
}
},
"extensions": {
"cost": {
"requestedQueryCost": 10,
"actualQueryCost": 10
}
}
}
Anchor to Next stepsNext steps
- Learn more about the Customer Account API.
Was this page helpful?