Decoding Shopify Selling Plans: Unlocking Billing Type Details via the Admin API

Understanding Shopify Selling Plan Billing Types Through the Admin API

Hey everyone! I was just digging through a fascinating thread in the Shopify Community about accessing selling plan details, specifically the "billingType". It seems like a few folks were running into a bit of a wall trying to get this information using the Admin API. Let's break down what I learned and how you can get the data you need.

The original poster, invokertc, was trying to figure out how to retrieve the billing type (like "Pay As You Go", "Prepaid One-Time", or "Prepaid Auto-renew") for their selling plans. They noticed that this property, which is visible in the Shopify Admin UI when creating a selling plan, wasn't directly available as a separate field in the API response. Here's the image they shared:

Shopify Selling Plan billingType selection

It's a valid question, right? You see it in the UI, so you'd expect to pull it directly from the API. Turns out, it's a bit more nuanced than that.

The Key: billingPolicy and __typename

Ruchita_bhalala, a Shopify Community expert, chimed in with a really helpful explanation. The billingType isn't a standalone field in the Admin API. Instead, Shopify determines it based on the type of billingPolicy associated with the selling plan. You can reliably read this using __typename in the GraphQL Admin API.

Here's the breakdown:

  • SellingPlanRecurringBillingPolicyPay As You Go
  • SellingPlanFixedBillingPolicyPrepaid One-Time
  • SellingPlanPrepaidBillingPolicyPrepaid Auto-renew

So, to get the billing type, you need to query the sellingPlan and look at its billingPolicy's __typename. Ruchita even provided a handy GraphQL query to illustrate this:

{
 sellingPlan(id: "gid://shopify/SellingPlan/SELLING_PLAN_ID") {
 billingPolicy {
 __typename
 }
 }
}

Digging Deeper: interval and intervalCount

invokertc followed up, asking how to map the billing type when the billingPolicy looks like this:

{
  "__typename": "SellingPlanRecurringBillingPolicy",
  "anchors": [],
  "interval": "WEEK",
  "intervalCount": 1,
  "maxCycles": null,
  "minCycles": null
}

Ruchita clarified that the billingType in the Admin UI is essentially a label derived from the selling plan's billingPolicy.interval and intervalCount. You can use these properties to recreate the same logic programmatically in your app.

GraphQL is Your Friend

Ruchita further highlighted that the billingType property is accessible through the GraphQL Admin API, not the REST API. To get the interval and interval count, you'll need to query the SellingPlan object, ensuring your app has the read_selling_plans scope.

Here's a more comprehensive GraphQL example Ruchita provided:

{
 product(id: "gid://shopify/Product/PRODUCT_ID") {
 variants(first: 10) {
 edges {
 node {
 sellingPlanAllocations(first: 10) {
 edges {
 node {
 sellingPlan {
 id
 name
 billingPolicy {
 interval
 intervalCount
 }
 }
 }
 }
 }
 }
 }
 }
}

This query shows how to retrieve selling plan information, including the interval and intervalCount from the billingPolicy, which, as we discussed, are key to determining the billing type.

Putting It All Together

So, the key takeaway here is that you won't find a direct "billingType" field in the Shopify Admin API. Instead, you need to use the GraphQL Admin API and examine the billingPolicy. The __typename, interval, and intervalCount properties within the billingPolicy will give you the information you need to determine the billing type programmatically.

It might seem a bit roundabout at first, but once you understand the relationship between the billingPolicy and the billing type, it becomes much clearer. Big thanks to invokertc for asking the question and to ruchita_bhalala for providing such a detailed and helpful explanation! It's these kinds of community discussions that really help us all level up our Shopify development skills.

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools