Unable to create SellingPlanGroup using GraphQl

I am using below mutation to create a Selling Plan Group:

mutation {
                    sellingPlanGroupCreate(input: 
                      {
                        name: "Test Discount Selling Plan", 
                        options: ["Test Discount"], 
                        position: 1, 
                        sellingPlansToCreate: [
                          {
                            name: "Test Discount",
                            options: "Discount 1",
                            position: 1, 
                            billingPolicy: {
                              fixed: {
                                checkoutCharge: {
                                  type: PERCENTAGE,
                                  value: {
                                    percentage: 0.0
                                  },
                                },
                              },
                            },
                            pricingPolicies: [
                              {
                                fixed: 
                                {
                                  adjustmentType: PERCENTAGE,
                                  adjustmentValue:
                                  {
                                    percentage: 15.0
                                  }
                                }
                              }
                            ]
                          }
                        ]
                      },
                      resources: {productIds: [], productVariantIds: []}
                      ) {
                      sellingPlanGroup {
                        id
                      }
                      userErrors {
                        field
                        message
                      }
                    }
                  }

I receive below response from server:

errors: [{message: "InputObject 'SellingPlanBillingPolicyInput' doesn't accept argument 'fixed'",…}]
0: {message: "InputObject 'SellingPlanBillingPolicyInput' doesn't accept argument 'fixed'",…}
extensions: {code: "argumentNotAccepted", name: "SellingPlanBillingPolicyInput", typeName: "InputObject",…}
locations: [{line: 13, column: 31}]
message: "InputObject 'SellingPlanBillingPolicyInput' doesn't accept argument 'fixed'"
path: ["mutation", "sellingPlanGroupCreate", "input", "sellingPlansToCreate", 0, "billingPolicy", "fixed"]

It says message: “InputObject ‘SellingPlanBillingPolicyInput’ doesn’t accept argument ‘fixed’”

However, if we look into the related documentation https://shopify.dev/api/admin-graphql/2022-07/input-objects/SellingPlanBillingPolicyInput

The property fixed is clearly mentioned there

I have tried to write the query in many different ways as suggested in the documentation but finally, I am stuck here.

Quick and prompt help will be highly appreciated. Coz I am in the middle of a project and I have to deliver this ASAP.

Hi there @Waqas87 !

May I ask what API Version you are using? The functionality you are trying to use was adding as Version 2022-07. I was able to reproduce your issue when using an older version of the API than this one.

Hope that helps!

-Josh

Hello @JoshArnold

Your response is appreciated.

When I reported this error, in my server config file I was using January 22 version of API. Then I updated the version to July22.

Then error changed. “category not included in list”. I modified the mutation accordingly.

mutation createSellingPlan{
                    sellingPlanGroupCreate(input: {name: "Test Discount Selling
                    Plan",merchantCode: "subscribe-and-save",category: "SUBSCRIPTION", 
                    options: ["Test Discount"], position: 1, sellingPlansToCreate: 
                    [{name: "Test Discount", options: "Discount 1", position: 1, 
                    billingPolicy: {recurring: { interval: WEEK, intervalCount: 1 } }, 
                    deliveryPolicy: {recurring: { interval: WEEK, intervalCount: 1 } }, 
                    pricingPolicies: [{fixed: {adjustmentType: PERCENTAGE, 
                    adjustmentValue: {percentage: 15.0}}}]}]}, resources: {productIds: 
                    [], productVariantIds: []}) {
                      sellingPlanGroup {
                        id
                      }
                      userErrors {
                        field
                        message
                      }
                    }
                  }

Now I am facing below error:

Hi again, @Waqas87 !

I think you have placed the category at the wrong level now in your current query. It should be inside of the sellingPlansToCreate array/objects.

Hello @JoshArnold ,

I have modified the mutation as you advised:

mutation { sellingPlanGroupCreate( input: { name: "Test Discount Selling Plan" merchantCode: "subscribe-and-save" options: ["Test Discount"] position: 1 sellingPlansToCreate: [ { name: "Test Discount" category: "SUBSCRIPTION" options: "Discount 1" position: 1 billingPolicy: { recurring: { interval: WEEK, intervalCount: 1 } } deliveryPolicy: { recurring: { interval: WEEK, intervalCount: 1 } } pricingPolicies: [ { fixed: { adjustmentType: PERCENTAGE adjustmentValue: { percentage: 15.0 } } } ] } ] } resources: { productIds: [], productVariantIds: [] } ) { sellingPlanGroup { id } userErrors { field message } } }

But now the error has changed to:

It is saying about SellingPlanCategory. I think this field is nullable. The Category that we are talking about here was at the right place i.e within the input object but outside the SellingPlansToCreate object. As you can also see this in the documentation:

https://shopify.dev/apps/subscriptions/selling-plans

Now let me quickly brief you on what I am actually trying to achieve.

Requirement: I need to give a discount on cart line item.

Solution: Attach selling plan (with pricing policy fixed and adjustment type %) to cart line item.

I don’t want to create a discount on the product in the cart instead, I want to apply the discount for a customer on the current cart session only.

Hi again @Waqas87 !

I think you may be misreading the documentation. The category field is definitely part of the sellingPlansToCreate object and not above it:
https://shopify.dev/api/admin-graphql/2022-07/input-objects/SellingPlanGroupInput#field-sellingplangroupinput-sellingplanstocreate

The other error you got regarding the category being an invalid field is once again due to the API version you are using. Use version 2022-07 or newer and it will all work fine. This worked for me:

mutation { sellingPlanGroupCreate(
  input: {
    name: "Test Discount Selling Plan"
    merchantCode: "subscribe-and-save"
    options: ["Test Discount"]
    position: 1
    sellingPlansToCreate: [
      {
        name: "Test Discount" 
        category: SUBSCRIPTION
        options: "Discount 1" 
        position: 1 
        billingPolicy: { 
          recurring: { 
            interval: WEEK, intervalCount: 1 
          } 
        } 
        deliveryPolicy: { 
          recurring: { 
            interval: WEEK, intervalCount: 1 
          } 
        } 
        pricingPolicies: [ 
          { 
            fixed: { 
              adjustmentType: PERCENTAGE 
              adjustmentValue: { 
                percentage: 15.0 
              } 
            } 
          } 
        ] 
      } 
    ] 
  } 
  resources: { 
    productIds: [], productVariantIds: [] 
  } 
) { sellingPlanGroup { id } userErrors { field message } } }

Hi @JoshArnold

It worked for me. I just copy pasted the query version that you provided and it worked. The difference is just of the category fields that I was misinterpreting. I am really thankful to you for your prompt and continuous assistance.

Thanks (once again)

1 Like