List products with their subscriptions (selling plans) using Admin or Storefront API

alex-ht-octane
Tourist
6 0 1

Hi!

I am trying to list products with their subscriptions (selling plan groups) using Admin GraphQL API, but I get nothing.

 

Details:

I have a development shop with Shopify payments in test mode. I installed ReCharge application to manage subscriptins. I created a product and set up subscription for it using ReCharge application. This, I suppose, should have created selling plans for the product.

I installed the Shopify GraphQL App to my store, and I gave it all possible permissions (checked them all at the app installation page).

Now I give the following query in the GraphQL app, using Admin API:

{
  sellingPlanGroups(first: 10) {
    edges {
      node {
        products(first: 10) {
          edges {
            node {
              id
              description
            }
          }
        }
      }
    }
  }
}

And I get nothing as a result:

{
  "data": {
    "sellingPlanGroups": {
      "edges": []
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 132,
      "actualQueryCost": 2,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 998,
        "restoreRate": 50
      }
    }
  }
}

Then I try getting them as a connection from product variants:

{
  products(first:5) {
    edges {
      node {
        id,
        description,
        title,
        options {
          id,
          name
        },
        variants(first:5) {
          edges {
            node {
              deliveryProfile {
                sellingPlanGroups(first:5) {
                  edges {
                    node {
                      id,
                      description
                    }
                  }
                }
              }
            }
          }
        }
      },
      cursor
    },
    
    pageInfo {
      hasNextPage,
      hasPreviousPage
    }
  }
}

Still nothing:

{
  "data": {
    "products": {
      "edges": [
        {
          "node": {
            "id": "gid://shopify/Product/6819008282788",
            "description": "Product 1 Description",
            "title": "Product 1",
            "options": [
              {
                "id": "gid://shopify/ProductOption/8749626982564",
                "name": "Size"
              },
              {
                "id": "gid://shopify/ProductOption/8749673054372",
                "name": "Color"
              }
            ],
            "variants": {
              "edges": [
                {
                  "node": {
                    "deliveryProfile": {
                      "sellingPlanGroups": {
                        "edges": []
                      }
                    }
                  }
                },
                {
                  "node": {
                    "deliveryProfile": {
                      "sellingPlanGroups": {
                        "edges": []
                      }
                    }
                  }
                },
                {
                  "node": {
                    "deliveryProfile": {
                      "sellingPlanGroups": {
                        "edges": []
                      }
                    }
                  }
                },
                {
                  "node": {
                    "deliveryProfile": {
                      "sellingPlanGroups": {
                        "edges": []
                      }
                    }
                  }
                },
                {
                  "node": {
                    "deliveryProfile": {
                      "sellingPlanGroups": {
                        "edges": []
                      }
                    }
                  }
                }
              ]
            }
          },
          "cursor": "eyJsYXN0X2lkIjo2ODE5MDA4MjgyNzg4LCJsYXN0X3ZhbHVlIjoiNjgxOTAwODI4Mjc4OCJ9"
        }
      ],
      "pageInfo": {
        "hasNextPage": false,
        "hasPreviousPage": false
      }
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 247,
      "actualQueryCost": 26,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 974,
        "restoreRate": 50
      }
    }
  }
}

 

I also tried Storefront API:

{
  products(first:5) {
    edges {
      node {
        id,
        description,
        title,
        options {
          id,
          name
        },
		sellingPlanGroups(first: 5) {
          edges {
            node {
              name
            }
          }
        }
      },
      cursor
    },
    
    pageInfo {
      hasNextPage,
      hasPreviousPage
    }
  }
}

But I get access denied error:

{
  "data": null,
  "errors": [
    {
      "message": "Access denied for sellingPlanGroups field.",
      "locations": [
        {
          "line": 12,
          "column": 3
        }
      ],
      "path": [
        "products",
        "edges",
        0,
        "node",
        "sellingPlanGroups"
      ],
      "extensions": {
        "code": "ACCESS_DENIED",
        "documentation": "https://shopify.dev/docs/admin-api/access-scopes"
      }
    }
  ]
}

 

What would be a correct way to go?

NickHeath
Tourist
10 1 3

I'm seeing the exact same issue with no data being returned, even though there are definitely selling plans available on the shop.

The minimum example I came up with is this request against the Admin API:

{
  sellingPlanGroups (first: 10) {
    edges {
      node {
        id
        name
      }
    }
  }
}

 

0 Likes
GrahamS
Shopify Staff
Shopify Staff
123 19 23

Hello @alex-ht-octane ,

I ran a quick test, and it would appear that selling plan groups are scoped to the app that created them, similar to webhooks. Selling plan groups that have been created and are managed by Recharge would only be available to query by the Recharge app. I expect that if you used your GraphiQL app to create a selling plan group, it would return via the calls you are currently making.

I didn't see this documented, so I'm going to do a bit of digging to see if this is an expected behaviour, and if so, I'll have the documentation updated to clarify this.

Best,

Graham

Graham S | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
NickHeath
Tourist
10 1 3

That scoping is really frustrating. It makes it impossible to create any app that provides utility or auxiliary admin support for subscriptions. Having the plans scoped to the creating app seems like a massive oversight.

Does this also mean that apps that provide backup services won't be able to access that data to backup selling plans? If so, this is a massive risk, and tanks the existing value we get from backup apps (I can't imagine the app providers would be very happy).

Finally, shouldn't the official Shopify Admin GraphQL app be able to override the scoping and return all the data? We use the GraphQL app for debugging and exploring the data. If it's "lying" to us, then it's worse than having no app at all.

0 Likes