Subscription API access denied error

Solved

Subscription API access denied error

RaiselCast
Shopify Partner
4 1 0

Hello

 

I'm developing an APP for my company's shopify store to manage product subscriptions, and need to show the list of ACTIVE SubscriptionContracts.

 

* I already have access to the Subscriptions API in the Partners dashboard and I'm using the following scopes:

 "customer_write_own_subscription_contracts,read_customer_payment_methods,read_orders,write_customers,write_own_subscription_contracts,write_products"

 

* My app is currently in development, so I haven't selected a Distribution method yet.

* When I run my app and go to the given http://localhost:3457/graphiql enviroment, I can retrieve the SubscriptionContracts using the following query with the 2024-10 API version:

 

query GetSubscriptionContracts{
  subscriptionContracts(first: 20, reverse:true, query: "status:ACTIVE"){
    edges {
      node {
        id
        status
        customer {
          id
          email
        }
        nextBillingDate
        createdAt
        updatedAt
        billingPolicy{
          interval
          intervalCount
          minCycles
          maxCycles
        }
        status
        lines(first:5) {
          nodes{
            id
            productId
            variantId
          }
        }
      }
    }
  }
}

But, when try to execute the request inside my app I'm getting the following error:

 

 

"Access denied for subscriptionContract field. Required access: the `read_own_subscription_contracts` or `write_own_subscription_contracts` scope."

This is the code I'm using to fetch the subscription contracts:

const response = await fetch("https://storename.myshopify.com/admin/api/2024-10/graphql.json", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-Shopify-Access-Token": SHOPIFY_ACCESS_TOKEN,
      },
      body: JSON.stringify({
        query: `
              query GetSubscriptionContracts{
  subscriptionContracts(first: 20, reverse:true, query: "status:ACTIVE"){
    edges {
      node {
        id
        status
        customer {
          id
          email
        }
        nextBillingDate
        createdAt
        updatedAt
        billingPolicy{
          interval
          intervalCount
          minCycles
          maxCycles
        }
        status
        lines(first:5) {
          nodes{
            id
            productId
            variantId
          }
        }
      }
    }
  }
}
            `,
      }),
    });

Why the query works on http://localhost:3457/graphiql and NOT on my side?

 

I'll appreciate any help on this issue. I have read related posts and Shopify documentation but didn't a solution.

 

Thanks in advance!

 

Accepted Solution (1)
RaiselCast
Shopify Partner
4 1 0

This is an accepted solution.

Hello Deepjpatel.

Thanks for your response.

 

I had installed a private app in the store with the same name as my Custom APP, and I was also using the API-Key of the private app.

To fix this, I uninstalled the private app and made sure I used the correct token.

Thanks for your support.

 

View solution in original post

Replies 2 (2)

Deepjpatel
Shopify Partner
13 0 0

Hii Deep here,

I think error is scope means

Required access: the `read_own_subscription_contracts` or `write_own_subscription_contracts` scope."

This error indicates inside toml file add `read_own_subscription_contracts` & `write_own_subscription_contracts`. this two scopes and run command `shopify app deploy` so this scopes deployed on your app after you verify again that query

RaiselCast
Shopify Partner
4 1 0

This is an accepted solution.

Hello Deepjpatel.

Thanks for your response.

 

I had installed a private app in the store with the same name as my Custom APP, and I was also using the API-Key of the private app.

To fix this, I uninstalled the private app and made sure I used the correct token.

Thanks for your support.