Manage subscriptions for a customer through the Storefront API

Manage subscriptions for a customer through the Storefront API

raRaRa
Visitor
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 4 (4)

JasonYang
Shopify Staff (Retired)
12 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. 

To learn more visit the Shopify Help Center or the Community Blog.

raRaRa
Visitor
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!

ConstantineDev
Shopify Partner
9 0 2

Admin API has access only for own subscribes. 

Through Admin API you cant to fetch all subscription of user only subscription that created through this app.
That's why scope named like: read_own_subscription_contracts

 

You can use Customer Account API to get all customer subscription and other information. just change you auth function to OAuth and use exchange token for requests - https://shopify.dev/docs/api/customer#retrieving-nonce 

malthemilthers
Excursionist
17 1 9

Hi RaRaRa - I'm looking to do this exact same thing. Did you find a solution? How did you manage to do it? Did you use the admin api? Did you manage to figure out a way to cancel subscriptions? Or perhaps even a skip next order feature?

 

Thanks