Not able to get selling plan allocation for product variant

Hi there, I want to get which selling plan associate with the product variants using storefront graphql API, I have already gotten the selling plan groups for the product, but not able to get which plan is associated with product variants. also, I have tried the “sellingPlanAllocations” (Ref :- https://shopify.dev/api/storefront/2022-04/objects/SellingPlanAllocation) connection but it gives me an error “Field ‘sellingPlanAllocations’ doesn’t exist on type ‘ProductVariant’”.

Here is my storefront graphql code (i am not able to put whole code here so i add shorter version)

product(id: “gid://shopify/Product/‘.$prd_list.’”) {

variants(first: 10){

edges{

node{

id

sellingPlanAllocations{

edges{

node{

id

}

}

}

}

and the code gives me an error: message: “Field ‘sellingPlanAllocations’ doesn’t exist on type ‘ProductVariant’” please provide me a way to fix this. Thanks

Hey @Snehal64

What version of the storefront API are you using?

In the 2022-04 version you linked there is a **ProductVariant.**sellingPlanAllocations connection, but it requires an argument, and there’s no id field on the SellingPlanAllocation.

The sellingPlanAllocations also are not included on the admin API’s ProductVariant, which uses the SellingPlanGroups instead. Is it possible you have the wrong endpoint?

Hopefully that helps, but if you continue to see an unexpected result could you share the endpoint, your full query, and the X-Request-ID value from the response’s headers so I can take a closer look?

Cheers,

Hi JamesG,
Thanks for reply.
I am using 2022-04 API Version.
Can you please send me example of the “sellingPlanAllocations” query with product variant?
Thanks.

Hey @Snehal64

To find a selling plan id for the variant’s on a product I used this with the storefront API :

endpoint:

https://{{store}}.myshopify.com/api/2022-04/graphql.json

query:

query productSellingPlans($product: ID!) {
	product(id: $product) {
		variants(first: 3) {
			edges {
				node {
					id
					title
					sellingPlanAllocations(first: 1) {
						edges {
							node {
								sellingPlan{
									id
								}
							}
						}
					}
				}
			}
		}
	}
}

hope that helps