Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Price rule not working with graphql for Free Shipping

Price rule not working with graphql for Free Shipping

waleed_i
Shopify Partner
1 0 0

I have been creating the price rule with GraphQL API. It is working fine for LINE_ITEM but not for SHIPPING_LINE type. I am passing the data as:

 input_data = {
          :priceRule=>{
                  :title=>"OU-19", 
                  :validityPeriod=>{
                         :start=>"2023-01-26T19:35:06.146+05:00"
                   }, 
                  :target=>"SHIPPING_LINE", 
                  :allocationMethod=>"ACROSS", 
                  :customerSelection=>{
                          :forAllCustomers=>true
                  }, 
                 :combinesWith=>{
                          :orderDiscounts=>true
                 }, 
                 :itemEntitlements=>{
                         :targetAllLineItems=>true
                 }, 
                :prerequisiteSubtotalRange=>{
                        :greaterThanOrEqualTo=>19.0
                }, 
                :value=>{
                        :percentageValue=>-100.0
                }
        }
}

And the query through which the data is being passed is through shopify_api gem. It is as below:

query = ShopifyAPI::GraphQL.client.parse <<-'GRAPHQL'                                                                                                                                                 
      mutation($priceRule: PriceRuleInput!) {
         priceRuleCreate(priceRule: $priceRule) {
           priceRule {
             id
             title
             allocationMethod
             value
             customerSelection
             startsAt
             endsAt
           }       
           userErrors {
             field
             message
           }priceRuleUserErrors {
          code
          field
          message
        }        
         }
       }
     GRAPHQL
  result = ShopifyAPI::GraphQL.client.query(query, variables: input_data)

But in the response, I am getting the following error:

#<GraphQL::Client::Response:0x00007f7c8f7b5058
 @data=#< priceRuleCreate=...>,
 @errors=#<GraphQL::Client::Errors @messages={} @details={}>,
 @extensions={"cost"=>{"requestedQueryCost"=>12, "actualQueryCost"=>10, "throttleStatus"=>{"maximumAvailable"=>1000.0, "currentlyAvailable"=>990, "restoreRate"=>50.0}}},
 @original_hash=
  {"data"=>
    {"priceRuleCreate"=>
      {"priceRule"=>nil,
       "userErrors"=>
        [{"field"=>["priceRule", "allocationMethod"], "message"=>"Allocation method is invalid"},
         {"field"=>["priceRule", "itemEntitlements", "targetAllLineItems"], "message"=>"Target selection can't be blank"}],
       "priceRuleUserErrors"=>
        [{"code"=>"INVALID", "field"=>["priceRule", "allocationMethod"], "message"=>"Allocation method is invalid"},
         {"code"=>"BLANK", "field"=>["priceRule", "itemEntitlements", "targetAllLineItems"], "message"=>"Target selection can't be blank"}]}},
   "extensions"=>{"cost"=>{"requestedQueryCost"=>12, "actualQueryCost"=>10, "throttleStatus"=>{"maximumAvailable"=>1000.0, "currentlyAvailable"=>990, "restoreRate"=>50.0}}}}>

It is giving me the error that "Target Selection Can't be blank" even though I am passing the field "targetAllLineItems" as true. The issue does not occur with LINE_ITEM. Moreover, for the allocation method error, when I pass "EACH", it does not give any error but cause error with "ACROSS".
Can anyone help me resolving this error as I am really stuck with this free shipping error?
I am using API version 2022-10

Replies 0 (0)