What's your biggest current challenge? Have your say in Community Polls along the right column.
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 subscriptionContracts field

Solved

Access denied for subscriptionContracts field

nelutihon
Tourist
3 0 1

Hello, 

 

I am trying to get the subscriptionContracts using the GraphQL and I am receiving the following response: 

"message": "Access denied for subscriptionContracts field.",

I see that in the response I am redirected to the Access Scopes page ( https://shopify.dev/api/usage/access-scopes ) page, but I can not find anything related to subscriptionContract, subscriptionContracts or even something related to subscriptions. 

I also checked  the ADMIN API PERMISSIONS section, but did not find a permission setting for subscriptions.

I want to mention that other requests, for ex. getting orders and order details, are working. 

 

My final goal is to get a list of all subscriptions using (REST or GRAPHQL). Is this possible at this moment ? Am I doing something wrong ?

 

 

My request is build like this:

 

Client:

 

    new Client([
            'base_uri' => 'https://' . $shopUrl . '/admin/api/2021-10/',
            'timeout' => 0,
            'allow_redirects' => false,
            'verify' => false,
            'headers' => [
                'Authorization' => 'Basic ' . base64_encode($apiKey . ':' . $pass),
                'Accept' => 'application/json',
                'Content-Type' => 'application/graphql'
            ]
        ]);

 

 

Body:

 

{
  subscriptionContracts(first: 10) {
    edges {
      node {
        id
        createdAt
        orders (first: 10) {
          edges {
            node {
              id
            }
          }
        }
      }
    }
  }
}

 

 

The response I receive: 

 

 

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

 

 

Accepted Solution (1)
MeganMcVey
Shopify Staff (Retired)
15 4 2

This is an accepted solution.

I am looking in the Apps -> Manage private apps -> {APP Name} -> Admin API section.

Ah... I didn't realize it was a private app.

 

From the https://shopify.dev/apps/subscriptions/contracts page:

The requirements for building an app that uses subscriptions depends on the type of app that you're building. Private apps can't access Subscription APIs. Public and custom apps need to request access to the appropriate protected scopes through the Partner Dashboard.

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 6 (6)

MeganMcVey
Shopify Staff (Retired)
15 4 2

Hello Nelutihon,

Thank you for posting your question.

It looks like you need the read_own_subscription_contracts access scope.
Ref: 
https://shopify.dev/api/admin-graphql/2021-07/objects/SubscriptionContract


Does this solve your problem?

To learn more visit the Shopify Help Center or the Community Blog.

MeganMcVey
Shopify Staff (Retired)
15 4 2

The documentation here may help: https://shopify.dev/apps/subscriptions

 

Especially the sections:

You can request Shopify-Approval Scopes through the Partners Dashboard.

To learn more visit the Shopify Help Center or the Community Blog.

nelutihon
Tourist
3 0 1

@MeganMcVey thank you for the quick reply.

 

I know about the resources that you gave, I've read them, but I can not find the specific setting that can enable or disable `read_own_subscription_contracts` access scope. 

I am looking in the Apps -> Manage private apps -> {APP Name} -> Admin API section.

 

Can you please point me to the place where I can enable/disable the required access scopes for subscriptions ?

 

I am attaching the full list of access scopes. 

 

Thank you.

 

nelutihon_0-1639386908381.png

 

MeganMcVey
Shopify Staff (Retired)
15 4 2

This is an accepted solution.

I am looking in the Apps -> Manage private apps -> {APP Name} -> Admin API section.

Ah... I didn't realize it was a private app.

 

From the https://shopify.dev/apps/subscriptions/contracts page:

The requirements for building an app that uses subscriptions depends on the type of app that you're building. Private apps can't access Subscription APIs. Public and custom apps need to request access to the appropriate protected scopes through the Partner Dashboard.

To learn more visit the Shopify Help Center or the Community Blog.

nelutihon
Tourist
3 0 1

@MeganMcVey I understand.

Thank you for your help.

Illia_Kuzma
Shopify Partner
36 2 14

Hey,

I get this error when I use  Shopify GraphiQL App