Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
I have tried to install multiple subscription-based apps on our store and after placing subscription orders I can't seem to figure out a way on the Orders API if a line item is subscription-based or not.
Could someone please advise on how to identify if an order has a Subscription Product Line Item?
Hi @mog
A subscription created order will show
"source_name": "subscription_contract"
but there is no line_item property to indicate subscription status. Hope this helps!
To learn more visit the Shopify Help Center or the Community Blog.
Thanks, but I don't see this on the initial order. Only the subsequent orders that are placed by the subscription app contain the "source_name" set to "subscription_contract".
I have the exact same question. I'd like to know a way to identify if an order is the initial order of a subscription using the Order API.
I'm wondering about the same thing as well, just had a customer of one of our apps ask about it.
I don't see any field at the line item level in the Order API data that would indicate whether a line item was purchased as a subscription or not.
This is an old post but I will post a solution for any unfortunate soul who happens upon this issue.
The order create webhook payload does not have any information relating to the selling plans purchased, nor does the storefront api. What you need to do is get the admin gql order id and query the order line items server-side, those objects do have the corresponding selling plan.
Using the existence of those properties as a flag you can determine if the product was purchased as a subscription or one-time.
Can you provide more detail on which properties you used to determine the selling plan?
Actually, I think I got it:
query = '''
{
order(id: "gid://shopify/Order/''' + order_id + '''") {
lineItems(first: 10) {
edges {
node {
title
sellingPlan {
name
}
}
}
}
}
}
'''
It's also mentioned on this page: https://help.shopify.com/en/manual/checkout-settings/script-editor/scripts-subscriptions
When merchants sell subscription products, those product are assigned a selling plan (by the subscription app). When you write scripts, you can use the lineitem object .selling_plan_id to identify when a product is being bought as a subscription.
Line items for subscriptions have a selling plan ID, whereas line items for one-time purchases don't have a selling plan ID.
It's very late now, but just want to give another work around since we have ui extension now so what i did is, in cart extension am checking if any lineItem is having "sellingPlan" (i am using recharge for subscription, so for any other app there might be a different attribute in lineItem, not sure), based on this this attribute am updating a cart attribute so that when order creation webhook run's i get that attribute with it. This way we don't have to call any other api call.