A place to discuss charging merchants for your apps and services using the billing API.
I am developing a Shopify app and I need to fetch some information on whether the user's subscription is active. If it is they will be allowed to use the app and if it isn't they will be redirected to a page prompting them to re-subscribe.
I am looking at the current stable GraphQL API (2024-01) and there are no queries under the billing section that would provide me this information.
There are various objects listed, including `AppSubscription` (https://shopify.dev/docs/api/admin-graphql/2024-01/objects/AppSubscription) that contains the information I need, but there doesn't seem to be any queries that return this object. There are only mutations, and I surely shouldn't need to mutate the billing records just to retrieve some information about them.
Does anyone know how I can fetch this info/object?
Solved! Go to the solution
This is an accepted solution.
I also spend a lot of time trying to figure this out, as they lack documentation to guide developers with this task. I discovered this with lots of trial and error using the GraphQL tool they offer. This is the snippet that I use to pull out IDs of the active subscriptions that are linked to your app.
export async function CheckForSubscriptions(admin: AdminApiContext) {
const gqlRes = await admin.graphql(
`#graphql
{
currentAppInstallation {
activeSubscriptions {
id
lineItems {
id
plan {
pricingDetails {
... on AppUsagePricing {
__typename
}
}
}
}
status
currentPeriodEnd
name
}
}
}
`
)
const res = await gqlRes.json() as SubscriptionCheck;
console.log('subscription check', res.data.currentAppInstallation.activeSubscriptions)
return res
}
I hope it helps.
This is an accepted solution.
I also spend a lot of time trying to figure this out, as they lack documentation to guide developers with this task. I discovered this with lots of trial and error using the GraphQL tool they offer. This is the snippet that I use to pull out IDs of the active subscriptions that are linked to your app.
export async function CheckForSubscriptions(admin: AdminApiContext) {
const gqlRes = await admin.graphql(
`#graphql
{
currentAppInstallation {
activeSubscriptions {
id
lineItems {
id
plan {
pricingDetails {
... on AppUsagePricing {
__typename
}
}
}
}
status
currentPeriodEnd
name
}
}
}
`
)
const res = await gqlRes.json() as SubscriptionCheck;
console.log('subscription check', res.data.currentAppInstallation.activeSubscriptions)
return res
}
I hope it helps.