AcessScope and cost price for products

Bradlplaydon
Tourist
23 0 2

I have tried using this query in order to get access to products cost prices through GraphQL but I am having no luck I have found one other post regarding this and they mentioned that in order to access "inventoryItem" field there is a scope which needs to be granted to the private app in which can't be done through the manage private apps section is there any other way I can get cost price through 1 GraphQL call or will this require an elevated REST call to get this information?

{
  products(first: 1, sortKey: ID) {
    edges {
      cursor
      node {
        createdAt
        handle
        id
        images(first: 10) {
          edges {
            node {
              originalSrc
            }
          }
        }
        onlineStoreUrl
        productType
        publishedAt
        title
        totalInventory
        updatedAt
        vendor
        variants(first: 10) {
          edges {
            node {
              price
              availableForSale
              id
              title
              sku
              image {
                originalSrc
              }
              inventoryItem {
                unitCost {
                  amount
                }
              }
            }
            cursor
          }
          pageInfo {
            hasNextPage
          }
        }
      }
    }
    pageInfo {
      hasNextPage
    }
  }
}

 

Replies 7 (7)

_JCC_
Shopify Staff
200 27 55

Hey @Bradlplaydon ,

Happy to have a look at this for you. You would need at a minimum read access for the Inventory permission. Is the Inventory permission not listed under the Admin API Permissions for your private app?

Regards,

John

John C | Developer Support @ 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

Bradlplaydon
Tourist
23 0 2

Hey @_JCC_ yes Inventory permission is listed under the API permissions with "Read" access as we don't want to be writing to it. We have gotten around this by using REST and more than one call to pull cost price by calling the /rproducts endpoint and then inventory_items endpoint but would be much better if this could be achieved through 1 graphQL request

_JCC_
Shopify Staff
200 27 55

Hey @Bradlplaydon,

If you'd like I can investigate this a little further. If you could make the GraphQL request again and provide me with the x-request-id returned in the response headers I'll check the logs on our end.

Regards,

John

John C | Developer Support @ 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

Bradlplaydon
Tourist
23 0 2

Hey @_JCC_ here is a x-request-id from the query I just ran: dd9037f6d9a26fb9269a03b2089f1666 

Exact response:

{"data":null,"errors":[{"message":"Access denied for inventoryItem field. Required access: `read_inventory` access scope.","locations":[{"line":15,"column":15}],"path":["products","edges",0,"node","variants","edges",0,"node","inventoryItem"],"extensions":{"code":"ACCESS_DENIED","documentation":"https:\/\/shopify.dev\/docs\/admin-api\/access-scopes","requiredAccessScope":"read_inventory"}}],"extensions":{"cost":{"requestedQueryCost":902,"actualQueryCost":674,"throttleStatus":{"maximumAvailable":2000.0,"currentlyAvailable":1326,"restoreRate":100.0}}}}

Bradlplaydon
Tourist
23 0 2

Hey @_JCC_ did you manage to take a look at the request?

_JCC_
Shopify Staff
200 27 55

Hey @Bradlplaydon,

Sorry for my late reply. Yes I had a chance to take a look and it looks like this request is coming from the Shopify GraphiQL APP. I don't believe based on the logs that the GraphiQL app was installed with the necessary permissions to query the inventory cost. The GraphiQL App permissions can be updated using the Install URL

I hope this helps resolve the issue. 

Regards,

John

John C | Developer Support @ 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

Bradlplaydon
Tourist
23 0 2

Thanks @_JCC_  this is really helpful I have just plugged this into the graphql app:

 

{
  locations(first: 2) {
    edges {
      node {
        id
        address {
          country
        }
        inventoryLevels(first: 5) {
          edges {
            node {
              available
              item {
                sku
              }
            }
          }
        }
      }
    }
  }
  productVariants(first: 10) {
    edges {
      node {
        sku
      }
    }
  }
}

 

 on that store and it is providing the results I want however I am trying to figure out a way of fixing the overselling functionality for products so it goes of multi inventory location rather than combined location on the store with the x request id I gave you returned the correct response however we don't have multi inventory setup for it currently. I want to run tests on our dev store and I tried running the exact query and got this response:

 

  "message": "The server responded with invalid JSON, this is probably a server-side error",
  "response": "<!DOCTYPE html>\n<html>\n<head>\n  <title>The change you wanted was rejected (422)</title>\n  <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n  <style>\n  .rails-default-error-page {\n    background-color: #EFEFEF;\n    color: #2E2F30;\n    text-align: center;\n    font-family: arial, sans-serif;\n    margin: 0;\n  }\n\n  .rails-default-error-page div.dialog {\n    width: 95%;\n    max-width: 33em;\n    margin: 4em auto 0;\n  }\n\n  .rails-default-error-page div.dialog > div {\n    border: 1px solid #CCC;\n    border-right-color: #999;\n    border-left-color: #999;\n    border-bottom-color: #BBB;\n    border-top: #B00100 solid 4px;\n    border-top-left-radius: 9px;\n    border-top-right-radius: 9px;\n    background-color: white;\n    padding: 7px 12% 0;\n    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);\n  }\n\n  .rails-default-error-page h1 {\n    font-size: 100%;\n    color: #730E15;\n    line-height: 1.5em;\n  }\n\n  .rails-default-error-page div.dialog > p {\n    margin: 0 0 1em;\n    padding: 1em;\n    background-color: #F7F7F7;\n    border: 1px solid #CCC;\n    border-right-color: #999;\n    border-left-color: #999;\n    border-bottom-color: #999;\n    border-bottom-left-radius: 4px;\n    border-bottom-right-radius: 4px;\n    border-top-color: #DADADA;\n    color: #666;\n    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);\n  }\n  </style>\n</head>\n\n<body class=\"rails-default-error-page\">\n  <!-- This file lives in public/422.html -->\n  <div class=\"dialog\">\n    <div>\n      <h1>The change you wanted was rejected.</h1>\n      <p>Maybe you tried to change something you didn't have access to.</p>\n    </div>\n    <p>If you are the application owner check the logs for more information.</p>\n  </div>\n</body>\n</html>\n"
}