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
}
}
}
}
}
}
}
}
}