A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
We are creating Customer and metafields using POST to insert customer and metafield. When we get response from Shopify admin REST Api, we only receiving Customer id but not metafield Ids. is there any way to get metafield Ids while performing the POST?
Now we have a scenario where we might need to update Customer information along with Metafields (we have roughly around 40 to 50 Metafields)
We can update Customer information using PUT but metafields does nt get updated. As per documentation provided by Shopify, we have to send Metafield Id. Though we can make a query call to get the metafield IDs but PUT method for metafields does not support mass update which means we have to perform PUT with each individual metafield which means 40 + API Calls. This is not a good practice from Salesforce side.
Any other approach shopify team can suggest or can I get Metafield id also along with Customer ID in POST request?
Any help would be appreciated.
Thank you,
With Regards,
Pallav Dave
When creating a customer with associated metafields, the Shopify API returns an ID for the newly created customer, but does not provide metafield IDs in the response in REST.
One possible solution is to use the GraphQL API to perform a bulk update of metafields for a customer. Specifically, you can use the `customerUpdate` mutation to update a customer and also include a `metafields` field to update all of the customer's metafields in a single request. Here's an example mutation for updating a customer's first name, last name, and metafields:
mutation {
customerUpdate(
input: {
id: "gid://shopify/Customer/6206619123734"
firstName: "John"
lastName: "Doe"
metafields: [
{
namespace: "my_namespace"
key: "my_key_1"
value: "my_value_1"
type: "single_line_text_field"
}
{
namespace: "my_namespace"
key: "my_key_2"
value: "my_value_2"
type: "single_line_text_field"
}
# Add additional metafields here as needed
]
}
) {
customer {
id
firstName
lastName
metafields(first: 10) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
Generally, any time that you use GraphQL you'll have an easier time of updating resources in bulk. It's especially easier to work with Metafields in GraphQL.
Shayne | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog