Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

App subscription renewal

App subscription renewal

Sellboost
Shopify Partner
2 0 0

I'm developing an app that uses recurring subscriptions to offer services to merchants.

 

Currently, I can create subscriptions and commit them without any problem through the GraphQl Api.

 

When I create the subscription, I receive a GID value and when the merchant confirms the subscription, I obtain the charge_id value.

 

You can check that the numerical value of the GID is equal to that of the charge_id.

 

Therefore:

  • Is the GID the unique identifier for the active subscription, or does it serve as the global identifier for the charge?
  • Upon subscription renewal, will a new GID be generated? If that's the case, what happens with the aforementioned GID?
  • If a new GID isn't generated, does a new charge_id get created instead? If so, could you explain how I can retrieve the new charge_id through the GraphQl API?
Replies 2 (2)

Liam
Community Manager
3108 344 895

Hi Sellboost,

 

The GID (Global ID) in Shopify's GraphQL API is a base64 encoded string that represents a global identifier for a resource. It's designed to be unique across the entire Shopify ecosystem, not just within a single shop.

 

When you create a subscription, the GID you receive is for that specific charge. When a subscription renews, a new charge is created, and this new charge will have its own unique GID. The previous GID associated with the previous charge remains unchanged and still points to that specific charge. Each charge, whether it's the initial one or a renewal, will have its own unique GID.

 

To retrieve the new charge_id (or the GID for the new charge) through the GraphQL API, you'd typically query the subscription and its associated charges. Depending on the exact structure of Shopify's GraphQL schema, the query might look something like this:

 

{
  subscription(id: "gid://shopify/Subscription/YOUR_SUBSCRIPTION_ID") {
    charges(first: 10, orderBy: { field: CREATED_AT, direction: DESC }) {
      edges {
        node {
          id
          // ... any other fields you want
        }
      }
    }
  }
}


This query fetches the charges associated with a specific subscription, ordered by their creation date in descending order. The most recent charge (i.e. the latest renewal) would be the first one in the returned list.

 

Hope this helps! 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Sellboost
Shopify Partner
2 0 0

Hi Liam, Thank you very much for your response.

 

I understand that when it comes to the subscription renewal, Shopify won't notify me through a webhook. Therefore, I assume I should inquire about the new GID.

Is this information correct?

 

Could I inquire about the new GID using a query like the following:


query appSubscription {
     currentAppInstallation {
        allSubscriptions(first: 1, reverse: true) {
            nodes {
              name,
               id,
              status,
              createdAt,
              currentPeriodEnd,
              test
           }
       }
     }
 }

I understand that I will need to verify that the GID of this latest subscription is active, different from the previous GID, and, most importantly, that the `currentPeriodEnd`

has not passed.

Are these statements accurate?