--- title: metafieldsSet - Customer API description: |- Sets metafield values. Metafield values will be set regardless if they were previously created or not. Allows a maximum of 25 metafields to be set at a time. This operation is atomic, meaning no changes are persisted if an error is encountered. As of `2024-07`, this operation supports compare-and-set functionality to better handle concurrent requests. If `compareDigest` is set for any metafield, the mutation will only set that metafield if the persisted metafield value matches the digest used on `compareDigest`. If the metafield doesn't exist yet, but you want to guarantee that the operation will run in a safe manner, set `compareDigest` to `null`. The `compareDigest` value can be acquired by querying the metafield object and selecting `compareDigest` as a field. If the `compareDigest` value does not match the digest for the persisted value, the mutation will return an error. You can opt out of write guarantees by not sending `compareDigest` in the request. api_version: 2025-10 api_name: customer type: mutation api_type: graphql source_url: html: https://shopify.dev/docs/api/customer/latest/mutations/metafieldsset md: https://shopify.dev/docs/api/customer/latest/mutations/metafieldsset.md --- # metafields​Set mutation Sets metafield values. Metafield values will be set regardless if they were previously created or not. Allows a maximum of 25 metafields to be set at a time. This operation is atomic, meaning no changes are persisted if an error is encountered. As of `2024-07`, this operation supports compare-and-set functionality to better handle concurrent requests. If `compareDigest` is set for any metafield, the mutation will only set that metafield if the persisted metafield value matches the digest used on `compareDigest`. If the metafield doesn't exist yet, but you want to guarantee that the operation will run in a safe manner, set `compareDigest` to `null`. The `compareDigest` value can be acquired by querying the metafield object and selecting `compareDigest` as a field. If the `compareDigest` value does not match the digest for the persisted value, the mutation will return an error. You can opt out of write guarantees by not sending `compareDigest` in the request. ## Arguments * metafields [\[Metafields​Set​Input!\]!](https://shopify.dev/docs/api/customer/latest/input-objects/MetafieldsSetInput) required The list of metafield values to set. Maximum of 25. *** ## Metafields​Set​Payload returns * metafields [\[Metafield!\]](https://shopify.dev/docs/api/customer/latest/objects/Metafield) The list of metafields that were set. * user​Errors [\[Metafields​Set​User​Error!\]!](https://shopify.dev/docs/api/customer/latest/objects/MetafieldsSetUserError) non-null The list of errors that occurred from executing the mutation. *** ## Examples * ### Create and update metafields #### Description Create and update operations are combined in the \`metafieldSet\` mutation. The following example shows you how to create one new metafield, \`key: "title"\`, and update an existing metafield, \`key: "nickname"\` in one mutation. #### Query ```graphql mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) { metafieldsSet(metafields: $metafields) { metafields { key namespace value createdAt updatedAt } userErrors { field message code } } } ``` #### Variables ```json { "metafields": [ { "key": "nickname", "namespace": "my_fields", "ownerId": "gid://shopify/Customer/624407574", "type": "single_line_text_field", "value": "Big Tuna" }, { "key": "title", "namespace": "my_fields", "ownerId": "gid://shopify/Customer/624407574", "type": "single_line_text_field", "value": "Dr." } ] } ``` #### cURL ```bash curl -X POST \ https://shopify.com//account/customer/api/2025-10/graphql/api/2025-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'Authorization: {access_token}' \ -d '{ "query": "mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) { metafieldsSet(metafields: $metafields) { metafields { key namespace value createdAt updatedAt } userErrors { field message code } } }", "variables": { "metafields": [ { "key": "nickname", "namespace": "my_fields", "ownerId": "gid://shopify/Customer/624407574", "type": "single_line_text_field", "value": "Big Tuna" }, { "key": "title", "namespace": "my_fields", "ownerId": "gid://shopify/Customer/624407574", "type": "single_line_text_field", "value": "Dr." } ] } }' ``` #### Response ```json { "metafieldsSet": { "metafields": [ { "key": "nickname", "namespace": "my_fields", "value": "Big Tuna", "createdAt": "2024-11-13T20:03:35Z", "updatedAt": "2024-11-13T20:03:38Z" }, { "key": "title", "namespace": "my_fields", "value": "Dr.", "createdAt": "2024-11-13T20:03:38Z", "updatedAt": "2024-11-13T20:03:38Z" } ], "userErrors": [] } } ``` * ### Creating and updating metafields using compare-and-swap (CAS) #### Description Create and update operations are combined in the \`metafieldSet\` mutation. The following example shows you how to create one new metafield, \`key: "title"\`, and update an existing metafield, \`key: "nickname"\` in one mutation in a safer way with compare-and-swap (CAS) through the \`compareDigest\` field. #### Query ```graphql mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) { metafieldsSet(metafields: $metafields) { metafields { key namespace value createdAt updatedAt } userErrors { field message code } } } ``` #### Variables ```json { "metafields": [ { "key": "nickname", "namespace": "my_fields", "ownerId": "gid://shopify/Customer/624407574", "type": "single_line_text_field", "value": "Big Tuna", "compareDigest": "8ac49f51d020905227c0bc6d040a035396ec518dbda59d6bb53df3f718fb9f35" }, { "key": "title", "namespace": "my_fields", "ownerId": "gid://shopify/Customer/624407574", "type": "single_line_text_field", "value": "Dr.", "compareDigest": null } ] } ``` #### cURL ```bash curl -X POST \ https://shopify.com//account/customer/api/2025-10/graphql/api/2025-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'Authorization: {access_token}' \ -d '{ "query": "mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) { metafieldsSet(metafields: $metafields) { metafields { key namespace value createdAt updatedAt } userErrors { field message code } } }", "variables": { "metafields": [ { "key": "nickname", "namespace": "my_fields", "ownerId": "gid://shopify/Customer/624407574", "type": "single_line_text_field", "value": "Big Tuna", "compareDigest": "8ac49f51d020905227c0bc6d040a035396ec518dbda59d6bb53df3f718fb9f35" }, { "key": "title", "namespace": "my_fields", "ownerId": "gid://shopify/Customer/624407574", "type": "single_line_text_field", "value": "Dr.", "compareDigest": null } ] } }' ``` #### Response ```json { "metafieldsSet": { "metafields": [ { "key": "nickname", "namespace": "my_fields", "value": "Big Tuna", "createdAt": "2024-11-13T20:03:38Z", "updatedAt": "2024-11-13T20:03:39Z" }, { "key": "title", "namespace": "my_fields", "value": "Dr.", "createdAt": "2024-11-13T20:03:39Z", "updatedAt": "2024-11-13T20:03:39Z" } ], "userErrors": [] } } ``` * ### metafieldsSet reference [Open in GraphiQL](http://localhost:3457/graphiql?query=mutation%20MetafieldsSet\(%24metafields%3A%20%5BMetafieldsSetInput!%5D!\)%20%7B%0A%20%20metafieldsSet\(metafields%3A%20%24metafields\)%20%7B%0A%20%20%20%20metafields%20%7B%0A%20%20%20%20%20%20key%0A%20%20%20%20%20%20namespace%0A%20%20%20%20%20%20value%0A%20%20%20%20%20%20createdAt%0A%20%20%20%20%20%20updatedAt%0A%20%20%20%20%7D%0A%20%20%20%20userErrors%20%7B%0A%20%20%20%20%20%20field%0A%20%20%20%20%20%20message%0A%20%20%20%20%20%20code%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D\&variables=%7B%0A%20%20%22metafields%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22key%22%3A%20%22nickname%22%2C%0A%20%20%20%20%20%20%22namespace%22%3A%20%22my_fields%22%2C%0A%20%20%20%20%20%20%22ownerId%22%3A%20%22gid%3A%2F%2Fshopify%2FCustomer%2F624407574%22%2C%0A%20%20%20%20%20%20%22type%22%3A%20%22single_line_text_field%22%2C%0A%20%20%20%20%20%20%22value%22%3A%20%22Big%20Tuna%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22key%22%3A%20%22title%22%2C%0A%20%20%20%20%20%20%22namespace%22%3A%20%22my_fields%22%2C%0A%20%20%20%20%20%20%22ownerId%22%3A%20%22gid%3A%2F%2Fshopify%2FCustomer%2F624407574%22%2C%0A%20%20%20%20%20%20%22type%22%3A%20%22single_line_text_field%22%2C%0A%20%20%20%20%20%20%22value%22%3A%20%22Dr.%22%0A%20%20%20%20%7D%0A%20%20%5D%0A%7D) ```graphql mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) { metafieldsSet(metafields: $metafields) { metafields { key namespace value createdAt updatedAt } userErrors { field message code } } } ``` ## Input variables JSON ```json { "metafields": [ { "key": "nickname", "namespace": "my_fields", "ownerId": "gid://shopify/Customer/624407574", "type": "single_line_text_field", "value": "Big Tuna" }, { "key": "title", "namespace": "my_fields", "ownerId": "gid://shopify/Customer/624407574", "type": "single_line_text_field", "value": "Dr." } ] } ``` ## Response JSON ```json { "metafieldsSet": { "metafields": [ { "key": "nickname", "namespace": "my_fields", "value": "Big Tuna", "createdAt": "2024-11-13T20:03:35Z", "updatedAt": "2024-11-13T20:03:38Z" }, { "key": "title", "namespace": "my_fields", "value": "Dr.", "createdAt": "2024-11-13T20:03:38Z", "updatedAt": "2024-11-13T20:03:38Z" } ], "userErrors": [] } } ```