updateCustomer
Update customer data. Customer data is updated based on the current customer token.
Signature
declare function updateCustomer(
context: Context,
input: CustomerUpdateInput,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<FetchResult<UpdateCustomerV2Mutation>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
input | Required | CustomerUpdateInput | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- CustomerUpdateInput
- CustomQuery
- CustomHeaders
FetchResultUpdateCustomerV2Mutation
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// Updates customer first name
const result = await sdk.magento.updateCustomer({
firstname: 'New John'
});
// result contains updated customer data
console.log(result); // result.data.updateCustomerV2.customer.firstname === 'New John'Creating a custom GraphQL query
module.exports = {
integrations: {
magento: {
customQueries: {
'update-customer-custom-query': ({ variables, metadata }) => ({
variables,
query: `
mutation updateCustomer($input: CustomerUpdateInput!) {
updateCustomerV2(input: $input) {
customer {
${metadata.fields}
}
}
}
`
}),
},
}
}
};Using a custom GraphQL query to reduce the amount of data returned by the query
import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query
const customQuery = {
updateCustomer: 'update-customer-custom-query',
metadata: {
fields: 'firstname lastname'
}
};
const result = await sdk.magento.updateCustomer({
firstname: 'New John'
lastname: 'New Doe'
}, customQuery);
// result contains only the fields specified in the custom query
// result.data.updateCustomerV2.customer.firstname === 'New John'
// result.data.updateCustomerV2.customer.lastname === 'New Doe'
console.log(result); // result.data.updateCustomerV2.customer.firstname === 'New John'