Solved

Unable to create SellingPlanGroup using GraphQl

Waqas87
Tourist
7 1 3

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

Screenshot 2022-07-24 at 2.26.18 AM.png

 

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.

Accepted Solution (1)
JoshArnold
Shopify Staff
29 7 5

This is an accepted solution.

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-sellingplang...

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

 

Josh (aka Master Chief) | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 6 (6)

JoshArnold
Shopify Staff
29 7 5

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

Josh (aka Master Chief) | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Waqas87
Tourist
7 1 3

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.

 

Screenshot 2022-07-27 at 9.17.48 PM.png

 

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:

 

Screenshot 2022-07-27 at 8.58.58 PM.png

 

JoshArnold
Shopify Staff
29 7 5

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.

Josh (aka Master Chief) | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Waqas87
Tourist
7 1 3

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:

 

Screenshot 2022-07-30 at 9.35.38 AM.png

 

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:

 

Screenshot 2022-07-30 at 9.40.01 AM.png

 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.

JoshArnold
Shopify Staff
29 7 5

This is an accepted solution.

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-sellingplang...

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

 

Josh (aka Master Chief) | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Waqas87
Tourist
7 1 3

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)