How to get renewed subscription orders from Order api

I am working with shopify rails i want to calculate the renewal rate of the subscription contracts but i am unable to find any source where i can know that the order is renewed and belong to specific subscription contract using Order Api can anyone help?

Hello mohsinmalik568,

Thank you for you question!

The SubscriptionContract GraphQL type might be able to help you.

Through the SubscriptionContract type you can access:

  • originOrder: The order from which this contract originated.
  • orders: A list of orders that are associated with the SubscriptionContract. An order is created each time a SubscriptionContract is successfully billed using the subscriptionBillingAttemptCreate mutation
  • billingAttempts: A list of billing attempts that are associated with the SubscriptionContract

You can find out more about the SubscriptionContract API page here: https://shopify.dev/docs/admin-api/graphql/reference/orders/subscriptioncontract

To add to this, you can also find the subscriptionContract via the orderID in GraphQL:

{
    order(id: "gid://shopify/Order/XXXX") {
        lineItems(first:10) {
            edges {
                node {
                    contract { id }
                }
            }
        }
    }
}