customerUpdateMe
Update customer firstName, lastName, email or dateOfBirth.
It updates specified properties of a customer profile in commercetools by sending a request to its GraphQL API.
By default, it uses the customerUpdateMeDefaultQuery GraphQL query.
The method allows you to update customer properties such as firstName, lastName, email or dateOfBirth more easily. However, if you need to update other customer properties (e.g. addresses), choose the updateCustomer method instead.
Signature
declare function customerUpdateMe(
context: CommercetoolsIntegrationContext,
currentUser: CustomerUpdateCurrentUser,
updatedUserData: UpdatedUserData,
customQuery?: CustomQuery
): Promise<CustomerUpdateMeResponse>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | CommercetoolsIntegrationContext | |
currentUser | Required | CustomerUpdateCurrentUser | |
updatedUserData | Required | UpdatedUserData | |
customQuery | Optional | CustomQuery |
Returns
Returns a representation of the CustomerUpdateMeResponse.
Referenced Types
- CommercetoolsIntegrationContext
- CustomerUpdateCurrentUser
- UpdatedUserData
- CustomQuery
- CustomerUpdateMeResponse
Examples
Updating customer's email.
const { user } = await sdk.commerce.customerUpdateMe({
version: 123,
}, {
email: 'test@gmail.com'
});Updating customer's firstName.
const { user } = await sdk.commerce.customerUpdateMe({
version: 123,
}, {
firstName: 'John'
});Updating customer's lastName.
const { user } = await sdk.commerce.customerUpdateMe({
version: 123,
}, {
lastName: 'Doe'
});Updating customer's dateOfBirth.
const { user } = await sdk.commerce.customerUpdateMe({
version: 123,
}, {
dateOfBirth: '1997-01-01'
});Updating multiple customer properties at once.
const { user } = await sdk.commerce.customerUpdateMe({
version: 123,
}, {
firstName: 'John',
lastName: 'Doe',
dateOfBirth: '1997-01-01'
});Creating a custom GraphQL query for the method in middleware.config.ts. We can use it to specify response fields as well as overwrite certain query variables.
export const integrations = {
ct: {
// ...
customQueries: {
'customer-update-me-custom-query': ({ variables, metadata }) => ({
variables: Object.assign(variables, metadata?.variables),
query: `
mutation customerUpdateMe($version: Long!, $actions: [MyCustomerUpdateAction!]!, $storeKey: KeyReferenceInput) {
user: updateMyCustomer(version: $version, actions: $actions, storeKey: $storeKey) {
${metadata?.fields}
}
}
`
})
}
}
}
};Updating customer's first name and selecting response fields using the custom GraphQL query from the previous example.
const { cart } = await sdk.commerce.customerUpdateMe({
version: 123,
}, {
firstName: 'John'
}, {
updateMyCustomer: 'customer-update-me-custom-query',
metadata: {
fields: 'id, version, firstName'
}
})