Getting a list of selling plans for my products via API

alain_tremblay
New Member
3 0 1

In my store I have a product entitled "Sensor Monitoring Kit" that has a product Id of 6825986654393 and one variant of Id 40446347542713.  I have one selling plan associated with this product which is selling plan Id 507642041 ("Delivery every 3 Days").

My question is, how can I get a list of all products in my store, the associated variants and selling plans via API?  I am not sure if I can use the REST APIs, or if I must write a GraphQL query.  If it is a GraphQL query, could I please get some assistance with the syntax?

Thank you!

Reply 1 (1)
pythonreactor
New Member
1 0 1

Hey @alain_tremblay , here is how I was able to work this out using Shopify's GraphQL backend:

 

 

 

{
  products(first: 5) {
    edges {
      node {
        ... on Product {
          sellingPlanGroups(first: 5) {
            edges {
              node {
                id
                sellingPlans(first: 5) {
                  edges {
                    node {
                      id
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

 

Do note that in order to query the `sellingPlan`, you must first connect through the `sellingPlanGroup` that it lives in. This information can be found by querying the products themselves.

 

If you want to search all of your products and their plans, you will have to use the above query (plus any other data points in there you need). I highly recommend messing with the Shopify GrahpiQL App so you can build some GraphQL queries.

 

Also read up on the query expense calculation: https://shopify.engineering/rate-limiting-graphql-apis-calculating-query-complexity

 

You will likely need to check against the `hasNextPage` and `cursor` if you have a lot of products or a lot of sellingPlan(s)(Group(s)) per Product.

 

Good luck!