Subscription API: deliveryPolicy/billingPolicy always returns empty object {} in GraphQL

groovymedia
New Member
2 0 3

We're implementing an app with subscription APIs. After I added SellingPlanPlanGroup like this page, I successfully added SellingPlanGroup and SellingPlan. However, GraphQL query to  SellingPlanGroup returned empty object {} as billingPolicy and deliveryPolicy like following

 

 

 

[{"node":{"id":"gid:\/\/shopify\/SellingPlan\/13172836","name":"Delivered every week","description":null,"billingPolicy":{},"deliveryPolicy":{},"createdAt":"2021-01-18T04:04:14Z","position":1,"pricingPolicies":[{}],"options":["1 Week(s)"]}} ... ]

 

 

 

 BillingPolicy/deliveryPolicy is always like {} and pricingPolicies is always like [{}].

How can I get billingPolicy/deliveryPolicy/pricingPolicies of existing Plan? Seems like only way to get SellingPlan is SellingPlanGroup.sellingPlans which returns like this.

abekeishi
Excursionist
20 10 21

Same issue here.

idea?

0 Likes
Webdibs
Tourist
4 0 0

Same problem here

0 Likes
groovymedia
New Member
2 0 3

Hi everyone including  and Webdibs! I've solved this problem by myself after I wrote them.

The reason why graphQL returns nothing is because there're a lot of possible type of billingPolicy and deliveryPolicy. Shopify create them expandable. BillingPolicy might be SellingPlanRecurringBillingPolicy or another (Although currently it's an only choice). You just need to call like below.

 

         billingPolicy {
            ... on SellingPlanRecurringBillingPolicy {
                createdAt
                maxCycles
                minCycles
                interval
                intervalCount
                anchors {
                    ... on SellingPlanAnchor {
                        day
                        month
                        type
                    }
                }
            }
        }
        deliveryPolicy {
            ... on SellingPlanRecurringDeliveryPolicy {
                createdAt
                interval
                intervalCount
                cutoff
                preAnchorBehavior
                anchors {
                    ... on SellingPlanAnchor {
                        day
                        month
                        type
                    }
                }
            }
        }

 

 

Unfortunately this kind of way to call isn't mentioned well, however there're a lot of GraphQL query which need this way.

Same discussion here(webdibs here too  https://community.shopify.com/c/Shopify-APIs-SDKs/Performing-a-gql-selection-on-a-union/td-p/986381

Hope this helps.