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?
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.
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:
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