G.Rose
G.Rose

Reputation: 714

Shopify PriceRule Create Mutation

I am trying to create a Price Rule to automatically apply a discount at checkout. I am getting the error:

{
  "errors": [
    {
      "message": "Parse error on \"1\" (INT) at [4, 24]",
      "locations": [
        {
          "line": 4,
          "column": 24
        }
      ]
    }
  ]
}

From mutation:

mutation priceRuleCreate($priceRule: PriceRuleInput!) {
  priceRuleCreate(priceRule: $priceRule) {
    priceRule {
      allocationLimit: 1,
      allocationMethod: "ACROSS",
         customerSelection: {
        customerIdsToAdd: ["gid://shopify/Customer/5476062265403"]
      },
      itemEntitlements: {
        collectionIds: ["gid://shopify/Collection/267286741051"]
      },
      itemPrerequisites: {
        collectionIds: ["gid://shopify/Collection/267286741051"]
      },
      prerequisiteShippingPriceRange: {
        greaterThanOrEqualTo: 0.00
      },
      prerequisiteSubtotalRange: {
        greaterThanOrEqualTo: 0.00
    },
    prerequisiteQuantityRange: {
        greaterThan: 1
    },
    shippingEntitlements: {
      countryCodes: ["US"],
      includeRestOfWorld: true
    },
    usageLimit: 3,
    title: "HB-131",
    target: "LINE_ITEM",
    value: {
      fixedAmountValue: 10.00
    },
    validityPeriod: {
        start: "2019-09-07T15:50:00Z"
      }
  }
    
  }
}

I'm unsure why I am getting this error since I am following the format from the documentation: https://shopify.dev/api/admin-graphql/2021-04/mutations/priceRuleCreate

For context I am using the GraphQL playground app that Shopify offers.

Upvotes: 0

Views: 587

Answers (1)

Joseph D.
Joseph D.

Reputation: 12174

Simply remove the values.

The mutation should just simply specify the fields that you need.

mutation priceRuleCreate($priceRule: PriceRuleInput!) {
  priceRuleCreate(priceRule: $priceRule) {
    priceRule {
      allocationLimit
    }
  }
}

Please refer to this document how to craft a GraphQL mutation request

Upvotes: 1

Related Questions