Re: SubscriptionContracts Query Returns Empty

SubscriptionContracts Query Returns Empty

mt686
Shopify Partner
56 9 19

Hi!

The problem I'm having is no matter how I query subscription contracts on a store, nothing shows. I installed a custom subscription app on a store that has existing subscriptions, (by the app "Appstle"), and nothing shows when you query subscription contracts. You can see customers have subscriptions in the Shopify admin, but there's nothing there when you use the GQL api. I've tried accessing them in bulk, by id, and through the custom object. It's always a 200 ok response but with no subscription contracts. Here's examples of my querys:

Trying all subscriptions:

 

{
    subscriptionContracts(first:50){
        edges{
            node {
                id
            }
        }
    }
}

 

Returns:

 

    "data": {
        "subscriptionContracts": {
            "edges": []
        }
    },

 



Trying by customer:

 

{
    customers (first: 10, reverse: true){
        edges {
            node {
                id
                subscriptionContracts (first: 5){
                    edges {
                        node {
                            id
                        }
                    }
                }
            }
        }
    }
}

 

Returns:

 

    "data": {
        "customers": {
            "edges": [
                {
                    "node": {
                        "id": "gid://shopify/Customer/XXX",
                        "subscriptionContracts": {
                            "edges": []
                        }
                    }
                }
            ]
        }
    },

 



 Trying by id:

 

{
    subscriptionContract(id:"gid://shopify/SubscriptionContract/10916331831") {
        id
    }
}

 

 Returns:

 

    "data": {
        "subscriptionContract": null
    },

 

 

I can see through the Shopify admin there are subscription contracts that exist, through the Subscription API, but no matter how I try I cannot query them. Any help is appreciated!

Thank you

Replies 6 (6)

SBD_
Shopify Staff
1830 273 418

Hey @mt686 

 

I believe apps can only query for their own subscription contracts. More here:  https://shopify.dev/docs/apps/selling-strategies/subscriptions/contracts#requirements

Scott | Developer Advocate @ Shopify 

Brian_S
Shopify Partner
168 21 43

Thats correct - and I believe that's why they named the scope read and write own  subscription contracts (`read_own_subscription_contracts`, `write_own_subscription_contracts`)

 

The way to query for subs would be to use your subscription app's public API

 

Brian Singer
CTO & Cofounder of Subscription Service - Awtomic
MauriceWirtz
Tourist
5 0 3

 

Hello,

 

I'm currently using https://apps.shopify.com/shopify-subscriptions, which I believe is a first-party plugin. Initially, it returned an empty list of subscriptions. After adjusting the scopes due to an authorization error, it started working.

 

However, I'm still encountering the same issue with it returning an empty list, despite having active subscription contracts.

Is this also happening with the first-party plugin? What is the purpose of exposing subscriptionContract in the customer endpoint if it returns empty lists like this?

JohnHoltRipley
Shopify Partner
6 1 3

Hi

 

I've hit the same issue - because the First Party app has created the subscription, your app can't see them. If your app creates the subscriptions then you'd get them in that list.

I didn't want to have to re-create all of that functionality to manage subscriptions, so what I did was set up a few workflows in Flow, triggered on Subscription Created, Edited etc, and then use the 'Send HTTP request' action with something like

{
"customer": "{{subscriptionContract.customer.id}}"
}

in the body so that my app can find the relevant customer and update them - hope that might be helpful?

 

MauriceWirtz
Tourist
5 0 3

Thanks for the explanation, John. Just to clarify: there isn't a direct endpoint to retrieve the first-party subscriptions, correct?

JohnHoltRipley
Shopify Partner
6 1 3

Not that I'm aware of - looking at the documentation it seems to say that your app only sees subscriptions your app has created and can't see any others. The webhook workaround is the only way I've found of getting my code to be able to react to first party app subscriptions