Selling Plan ID in a headless store?

Topic summary

A developer is building a headless commerce setup using Next.js, Sanity CMS, and Shopify with webhook-based product synchronization.

Core Challenge:

  • Need to retrieve and store Selling Plan IDs for subscription products in Sanity
  • Goal is to identify which product variants are part of subscription plans before adding them to cart

Technical Context:

  • Products sync from Shopify to Sanity via webhooks
  • Want to populate a “Selling Plan ID” field in Sanity during product updates
  • Included a GraphQL query snippet (displayed in reverse text) that queries product variants and selling plan allocations

Seeking:

  • Insights from others who have successfully implemented similar selling plan ID retrieval
  • Suggestions on how to handle this workflow efficiently

The discussion remains open with no responses yet.

Summarized with AI on November 5. AI used: claude-sonnet-4-5-20250929.

Hi everyone!

I’m working on a Next.js + Sanity + Shopify setup where Shopify products are synchronized into the CMS using webhooks. I have a specific use case: I want to retrieve the selling plan ID for products with subscriptions and store it in Sanity.

The main goal is to populate a “Selling Plan ID” field in Sanity whenever a product is updated via Shopify’s webhook. This would allow me to check if a variant is part of a subscription before it’s added to the cart.

Has anyone managed to successfully fetch and store Selling Plan IDs like this? I’d love some insights or suggestions on how to handle it efficiently.

This is my current query setup:

{
      product(id: "gid://shopify/Product/${productId}") {
        id
        variants(first: 10) {
          edges {
            node {
              id
              title
              sellingPlanAllocations(first: 5) {
                edges {
                  node {
                    sellingPlan {
                      id
                      name
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
1 Like