How to get app subscription status from Shopify API

Viewed 766

Is there a way to determine the subcsription status of an app via the Shopify node client or in the GraphQL API?

Given a user has signed up to our public app, when they log in. then I should be able to check if their Shopify subscription to our app is still active.

I can see via the GraphQL API I can query

currentAppInstallation {
   activeSubscriptions {
     id
     name
     test
   }
}

This seems to return an empty array, implying my test store I doesn't have any active subscriptions. This may be due to my app and shop being in test mode though.

Does anybody know if this is the case or is there another way to get the subscription status? Also, it would be good to do via the Shopify client if that is possible?

1 Answers

This is how I did if I have the APP subscription ID, I got the GraphQL query from Shopify's Billing API documentation:

query {
  node(id: "gid://shopify/AppSubscription/4019585080") {
    ...on AppSubscription {
      billingInterval
      createdAt
      currentPeriodEnd
      id
      name
      status
      test
      lineItems {
        plan {
          pricingDetails {
            ...on AppRecurringPricing {
              interval
              price {
                amount
                currencyCode
              }

            }
            ...on AppUsagePricing {
              terms
              cappedAmount {
                amount
                currencyCode

              }
              balanceUsed {
                amount
                currencyCode
              }
            }
          }
        }
      }
    }
  }
}

Notice that status is defined at root, so you'll get it inside the node.

Related