customerUpdateMe
Method updating customer's firstName, lastName, email or dateOfBirth.
This method sends a POST request to the customerUpdateMe endpoint of the Vue Storefront API Middleware. In turn, it updates specified properties of a customer profile in commercetools by sending a request to its GraphQL API. The default GraphQL query used by this method can be found here.
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
export declare function customerUpdateMe<Res extends PartialCustomerUpdateMeResponse = CustomerUpdateMeResponse>(
params: CustomerUpdateMeParams,
options?: MethodOptions<CustomQuery<"customerUpdateMe">>
): Promise<Res>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
params | Required | CustomerUpdateMeParams | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
options | Optional | MethodOptions<CustomQuery<"customerUpdateMe">> | Options that can be passed to additionally configure the request or customize the logic in a plugin. |
Returns
Returns a representation of the CustomerUpdateMeResponse.
Referenced Types
- PartialCustomerUpdateMeResponse
- CustomerUpdateMeResponse
- CustomerUpdateMeParams
- MethodOptions
- CustomQuery
Examples
Updating customer's email.
import { sdk } from '~/sdk.config.ts';
const { user } = await sdk.commerce.customerUpdateMe({
version: 123,
email: 'test@gmail.com'
});Updating customer's firstName.
import { sdk } from '~/sdk.config.ts';
const { user } = await sdk.commerce.customerUpdateMe({
version: 123,
firstName: 'John'
});Updating customer's lastName.
import { sdk } from '~/sdk.config.ts';
const { user } = await sdk.commerce.customerUpdateMe({
version: 123,
lastName: 'Doe'
});Updating customer's dateOfBirth.
import { sdk } from '~/sdk.config.ts';
const { user } = await sdk.commerce.customerUpdateMe({
version: 123,
dateOfBirth: '1997-01-01'
});Updating multiple customer properties at once.
import { sdk } from '~/sdk.config.ts';
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.js. We can use it to specify response fields as well as overwrite certain query variables.
module.exports = {
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. Notice how we are using the type parameter to overwrite the default response interface.
import { sdk } from '~/sdk.config.ts';
type CustomCustomerUpdateMeResponse = {
user: {
id: string;
version: string;
firstName: string;
}
}
const { cart } = await sdk.commerce.customerUpdateMe<CustomCustomerUpdateMeResponse>({
version: 123,
firstName: 'John'
}, {
customQuery: {
updateMyCustomer: 'customer-update-me-custom-query',
metadata: {
fields: 'id, version, firstName'
}
}
})