Development discussions around Shopify APIs
Return management just got easier! We’ve launched Customer Self-Serve Returns to all Shopify merchants. Click here to learn more!
Hello I am trying to create a metafield on my products by following this article link .
I am running the following graphql queries on Admin API to create a metafield.
mutation ($input: ProductInput!) {
productUpdate(input: $input) {
product {
metafields(first: 100) {
edges {
node {
namespace
key
value
}
}
}
}
}
}
{
"input" : {
"id": "gid://shopify/Product/8068524540191",
"metafields": [
{
"namespace": "instructions",
"key": "wash",
"value": "cold wash",
"type": "single_line_text_field"
}
]
}
}
but getting the error
{
"data": {
"productUpdate": null
},
"errors": [
{
"message": "Access denied for productUpdate field. Required access: `write_products` access scope. Also: The user must have a permission to update products.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"productUpdate"
],
"extensions": {
"code": "ACCESS_DENIED",
"documentation": "https://shopify.dev/api/usage/access-scopes",
"requiredAccess": "`write_products` access scope. Also: The user must have a permission to update products."
}
}
],
"extensions": {
"cost": {
"requestedQueryCost": 112,
"actualQueryCost": 10,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 990,
"restoreRate": 50
}
}
}
}
I have provided the access scopes for admin API configuration
also when I am running this query
{
currentAppInstallation {
accessScopes {
handle
}
}
}
I am getting this response
{
"data": {
"currentAppInstallation": {
"accessScopes": [
{
"handle": "read_content"
},
{
"handle": "read_products"
},
{
"handle": "unauthenticated_read_product_listings"
},
{
"handle": "unauthenticated_read_product_tags"
},
{
"handle": "unauthenticated_write_checkouts"
},
{
"handle": "unauthenticated_write_customers"
},
{
"handle": "unauthenticated_read_customer_tags"
},
{
"handle": "unauthenticated_read_content"
},
{
"handle": "unauthenticated_read_checkouts"
},
{
"handle": "unauthenticated_read_customers"
}
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 2,
"actualQueryCost": 2,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 998,
"restoreRate": 50
}
}
}
}
Needed Help!!!!
Solved! Go to the solution
This is an accepted solution.
Hi @IndikaDev 👋
Would you please try the same mutation in the below curl request instead? I've seen this be an issue when apps incorrectly reference the Storefront API endpoint rather than the Admin API.
curl -L -X POST 'https://STORE-NAME.myshopify.com/admin/api/2023-01/graphql.json' \
-H 'X-Shopify-Access-Token: ADMIN-ACCESS-TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{"query":"mutation ($input: ProductInput!) { productUpdate(input: $input) { product { metafields(first: 10) { nodes { namespace key value } } } } }","variables":{"input":{"id":"gid://shopify/Product/6795723079798","metafields":[{"namespace":"instructions","key":"wash","value":"cold wash","type":"single_line_text_field"}]}}}'
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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
This is an accepted solution.
Hi @IndikaDev 👋
Would you please try the same mutation in the below curl request instead? I've seen this be an issue when apps incorrectly reference the Storefront API endpoint rather than the Admin API.
curl -L -X POST 'https://STORE-NAME.myshopify.com/admin/api/2023-01/graphql.json' \
-H 'X-Shopify-Access-Token: ADMIN-ACCESS-TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{"query":"mutation ($input: ProductInput!) { productUpdate(input: $input) { product { metafields(first: 10) { nodes { namespace key value } } } } }","variables":{"input":{"id":"gid://shopify/Product/6795723079798","metafields":[{"namespace":"instructions","key":"wash","value":"cold wash","type":"single_line_text_field"}]}}}'
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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
Thanks, it worked, don't know why graphiql was not working!!!
User | RANK |
---|---|
16 | |
7 | |
7 | |
6 | |
5 |
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022