Return management just got easier! We’ve launched Customer Self-Serve Returns to all Shopify merchants. Click here to learn more!

Access denied for productUpdate field. Required access: `write_products` access scope.

Solved
IndikaDev
Shopify Partner
2 0 2

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

Screenshot 2023-01-25 143319.png

 

 

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!!!!

Accepted Solution (1)

Accepted Solutions
ShopifyDevSup
Shopify Staff
Shopify Staff
520 78 146

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

View solution in original post

Replies 2 (2)
ShopifyDevSup
Shopify Staff
Shopify Staff
520 78 146

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

IndikaDev
Shopify Partner
2 0 2

Thanks, it worked, don't know why graphiql was not working!!!