Manage subscriptions for a customer through the Storefront API

raRaRa
New Member
3 0 0

Hi everyone. I'm using Shopify as a headless ecommerce for a NextJS website that I'm developing It has been a great experience using the Storefront API to manage the cart, fetch products, etc.

I'm now working on the account page and I want to fetch all orders for a customer, which seems to be really easy, but it looks like the Storefront API doesn't support getting active subscriptions for a customer, or seeing if an order is associated with a subscription/selling plan. Additionally I want the customer to be able to cancel a subscription.

 

I can see that the Admin API can list subscriptionContracts for a Customer, but is there a reason why the Storefront API can't? I also can't find anything on the roadmap other than that the Subscriptions API is supported in the Storefront API, but in reality it's only partly supported (unless this is by design).

 

As a plan B I'm thinking about creating my own API to manage subscriptions through the Admin API, is there a way to cancel a subscription through the Admin API?

 

Thanks!

Replies 2 (2)
JasonYang
Shopify Staff
Shopify Staff
9 1 4

Hello, 

 

At the moment, there is no way list subscriptionContracts in StoreFrontApi. Though it is possible in Admin Api as you mentioned: https://shopify.dev/api/admin-graphql/2022-01/objects/Customer#queries

 

To cancel a subscription contract, there is no direct endpoint for that at the moment. I think you would need to modify the contracts directly to stop building orders: https://shopify.dev/api/admin-graphql/2022-01/objects/SubscriptionContract#top by fetching the active contracts. 

raRaRa
New Member
3 0 0

Hi @JasonYang, thank you for the quick response to this matter.

 

Yeah I will just utilize the Admin API for this use case, although it would be nice to see this possible in the Storefront in the near future.

 

Regarding the second question about cancelling a subscription, do you mean that I could modify the subscription contract to stop the billing?

 

Thanks!