Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: "Access Denied For AutomaticDiscountNodes Field." Even Though I Have write_discounts s

"Access Denied For AutomaticDiscountNodes Field." Even Though I Have write_discounts scope

LouiseEH
Shopify Partner
40 3 8

Hi,

 

I have an app with the scope write_discounts.
I try the following query:

{
  automaticDiscountNodes (first: 3) {
    edges {
      node {
        id       
      }
    }
  }
}

And I get:

{
    "data": null,
    "errors": [
        {
            "message": "Access denied for automaticDiscountNodes field.",
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "automaticDiscountNodes"
            ],
            "extensions": {
                "code": "ACCESS_DENIED",
                "documentation": "https://shopify.dev/api/usage/access-scopes"
            }
        }
    ],
    "extensions": {
        "cost": {
            "requestedQueryCost": 5,
            "actualQueryCost": 2,
            "throttleStatus": {
                "maximumAvailable": 1000.0,
                "currentlyAvailable": 998,
                "restoreRate": 50.0
            }
        }
    }
}

I use API version 2023-10.

 

Basically I want to access the current values of the metafields that was set with 

discountAutomaticAppCreate so I can show the current value of the fields in the UI the merchant can use to configure the automatic discount. One way to access the information is via automatic discount nodes. querying all metafields is in the unstable API version, querying private metafields does not work (created the metafields with th $app: prefix in the namespace).

 

Kind regards,

-Louise

Replies 2 (2)

LouiseEH
Shopify Partner
40 3 8

Using the query on "metafields" with the unstable API version does not work either - no metafields are returned when querying for owner with the id of the automatic discount node:

query{
    metafields(owner: "gid://shopify/DiscountAutomaticNode/1400168874288", first:10){
        edges{
            node{
                key
                value
            }
        }
    }
}

{
    "data": {
        "metafields": {
            "edges": []
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 12,
            "actualQueryCost": 2,
            "throttleStatus": {
                "maximumAvailable": 1000.0,
                "currentlyAvailable": 998,
                "restoreRate": 50.0
            }
        }
    }
}
LouiseEH
Shopify Partner
40 3 8

Ok finally got it - apparently I can use this query:

query{
    discountNodes(first:10){
        edges{
            node{
                id
                discount{
                    __typename
          ... on DiscountAutomaticApp {
            status
            title
            
          }
                }
                metafields(first:10){
                    edges{
                        node{
                            id
                            key
                            namespace
                            value
                        }
                    }
                }
            }
        }
    }
}