A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
As the title says, I want to update customer metafield using admin rest api.
The response is coming back with 200, but the metafields were not included in the response object either.
Also, I cannot get the metafiled coming to the following endpoint.
https://{{ shop name }}/admin/api/2023-01/metafields.json
I tried to update the following endpoint, but was unable to do so.
Is there some configuration that needs to be done?
Thank you in advance.
endpoint | https://{{ shop name }}/admin/api/2023-01/customers/{{ customer.id }}.json |
Webhook version | 2023-01 |
Admin API access scope | write_customers、 read_customers |
const requestHeaders = { 'X-Shopify-Access-Token': accessToken, 'Content-Type': 'application/json', }; const Payload = { customer: { first_name, last_name, metafields: [ { key: metafieldKey_01, value: newValue, value_type: 'single_line_text_field', namespace: metafieldNamespace_01, }, { key: metafieldKey_02, value: newValue, value_type: 'single_line_text_field', namespace: metafieldNamespace_02, }, ], }, }; const updateCustomer = (payload) => { fetch(ApiUrl, { method: 'PUT', headers: requestHeaders, body: JSON.stringify(payload), }) .then((response) => response.json()) .then((data) => console.log(data)) .catch((error) => console.error(error, payload)); };
If you are updating the metafields you need to include the metafield id in your metafields object.
metafields: [
{
id:[metafield id],
key: metafieldKey_01,
value: newValue,
value_type: 'single_line_text_field',
namespace: metafieldNamespace_01,
},
{
id:[metafieldid],
key: metafieldKey_02,
value: newValue,
value_type: 'single_line_text_field',
namespace: metafieldNamespace_02,
},
]
Cheers,
Gary