# priceRuleCreate - admin-graphql - MUTATION
Version: 2024-07

## Description
Create a price rule using the input.

### Access Scopes
`write_price_rules` access scope.


## Arguments
* [priceRule](/docs/api/admin-graphql/2024-07/input-objects/PriceRuleInput): PriceRuleInput! - The input fields to create a price rule.
* [priceRuleDiscountCode](/docs/api/admin-graphql/2024-07/input-objects/PriceRuleDiscountCodeInput): PriceRuleDiscountCodeInput - The input fields to create a discount code for the price rule.


## Returns
* [priceRule](/docs/api/admin-graphql/2024-07/objects/PriceRule): PriceRule The newly created price rule.
* [priceRuleDiscountCode](/docs/api/admin-graphql/2024-07/objects/PriceRuleDiscountCode): PriceRuleDiscountCode The newly created discount code.
* [priceRuleUserErrors](/docs/api/admin-graphql/2024-07/objects/PriceRuleUserError): PriceRuleUserError! The list of errors that occurred from executing the mutation.
* [userErrors](/docs/api/admin-graphql/2024-07/objects/UserError): UserError! The list of errors that occurred from executing the mutation.


## Examples
### Create a price rule
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) { priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) { priceRule { id title validityPeriod { start } allocationMethod itemEntitlements { products(first: 3) { edges { node { id } } } targetAllLineItems } valueV2 { ... on MoneyV2 { amount currencyCode } } customerSelection { forAllCustomers } oncePerCustomer usageLimit target } priceRuleDiscountCode { id code } priceRuleUserErrors { code field message } } }\",\n \"variables\": {\n    \"priceRule\": {\n      \"title\": \"Boots Discount\",\n      \"allocationMethod\": \"ACROSS\",\n      \"customerSelection\": {\n        \"forAllCustomers\": true\n      },\n      \"itemEntitlements\": {\n        \"targetAllLineItems\": false,\n        \"productIds\": [\n          \"gid://shopify/Product/121709582\"\n        ]\n      },\n      \"target\": \"LINE_ITEM\",\n      \"validityPeriod\": {\n        \"start\": \"2016-08-29T12:00:00-04:00\"\n      },\n      \"value\": {\n        \"fixedAmountValue\": \"-10.0\"\n      }\n    }\n  }\n}'\n"
Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n  data: {\n    \"query\": `mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) {\n      priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) {\n        priceRule {\n          id\n          title\n          validityPeriod {\n            start\n          }\n          allocationMethod\n          itemEntitlements {\n            products(first: 3) {\n              edges {\n                node {\n                  id\n                }\n              }\n            }\n            targetAllLineItems\n          }\n          valueV2 {\n            ... on MoneyV2 {\n              amount\n              currencyCode\n            }\n          }\n          customerSelection {\n            forAllCustomers\n          }\n          oncePerCustomer\n          usageLimit\n          target\n        }\n        priceRuleDiscountCode {\n          id\n          code\n        }\n        priceRuleUserErrors {\n          code\n          field\n          message\n        }\n      }\n    }`,\n    \"variables\": {\n      \"priceRule\": {\n        \"title\": \"Boots Discount\",\n        \"allocationMethod\": \"ACROSS\",\n        \"customerSelection\": {\n          \"forAllCustomers\": true\n        },\n        \"itemEntitlements\": {\n          \"targetAllLineItems\": false,\n          \"productIds\": [\n            \"gid://shopify/Product/121709582\"\n          ]\n        },\n        \"target\": \"LINE_ITEM\",\n        \"validityPeriod\": {\n          \"start\": \"2016-08-29T12:00:00-04:00\"\n        },\n        \"value\": {\n          \"fixedAmountValue\": \"-10.0\"\n        }\n      }\n    },\n  },\n});\n"
Ruby example: "session = ShopifyAPI::Auth::Session.new(\n  shop: \"your-development-store.myshopify.com\",\n  access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n  session: session\n)\n\nquery = <<~QUERY\n  mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) {\n    priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) {\n      priceRule {\n        id\n        title\n        validityPeriod {\n          start\n        }\n        allocationMethod\n        itemEntitlements {\n          products(first: 3) {\n            edges {\n              node {\n                id\n              }\n            }\n          }\n          targetAllLineItems\n        }\n        valueV2 {\n          ... on MoneyV2 {\n            amount\n            currencyCode\n          }\n        }\n        customerSelection {\n          forAllCustomers\n        }\n        oncePerCustomer\n        usageLimit\n        target\n      }\n      priceRuleDiscountCode {\n        id\n        code\n      }\n      priceRuleUserErrors {\n        code\n        field\n        message\n      }\n    }\n  }\nQUERY\n\nvariables = {\n  \"priceRule\": {\n    \"title\": \"Boots Discount\",\n    \"allocationMethod\": \"ACROSS\",\n    \"customerSelection\": {\n      \"forAllCustomers\": true\n    },\n    \"itemEntitlements\": {\n      \"targetAllLineItems\": false,\n      \"productIds\": [\"gid://shopify/Product/121709582\"]\n    },\n    \"target\": \"LINE_ITEM\",\n    \"validityPeriod\": {\n      \"start\": \"2016-08-29T12:00:00-04:00\"\n    },\n    \"value\": {\n      \"fixedAmountValue\": \"-10.0\"\n    }\n  }\n}\n\nresponse = client.query(query: query, variables: variables)\n" 
Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n  `#graphql\n  mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) {\n    priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) {\n      priceRule {\n        id\n        title\n        validityPeriod {\n          start\n        }\n        allocationMethod\n        itemEntitlements {\n          products(first: 3) {\n            edges {\n              node {\n                id\n              }\n            }\n          }\n          targetAllLineItems\n        }\n        valueV2 {\n          ... on MoneyV2 {\n            amount\n            currencyCode\n          }\n        }\n        customerSelection {\n          forAllCustomers\n        }\n        oncePerCustomer\n        usageLimit\n        target\n      }\n      priceRuleDiscountCode {\n        id\n        code\n      }\n      priceRuleUserErrors {\n        code\n        field\n        message\n      }\n    }\n  }`,\n  {\n    variables: {\n      \"priceRule\": {\n        \"title\": \"Boots Discount\",\n        \"allocationMethod\": \"ACROSS\",\n        \"customerSelection\": {\n          \"forAllCustomers\": true\n        },\n        \"itemEntitlements\": {\n          \"targetAllLineItems\": false,\n          \"productIds\": [\n            \"gid://shopify/Product/121709582\"\n          ]\n        },\n        \"target\": \"LINE_ITEM\",\n        \"validityPeriod\": {\n          \"start\": \"2016-08-29T12:00:00-04:00\"\n        },\n        \"value\": {\n          \"fixedAmountValue\": \"-10.0\"\n        }\n      }\n    },\n  },\n);\n\nconst data = await response.json();\n"
Graphql query: "mutation priceRuleCreate($priceRule: PriceRuleInput!, $priceRuleDiscountCode: PriceRuleDiscountCodeInput) {\n  priceRuleCreate(priceRule: $priceRule, priceRuleDiscountCode: $priceRuleDiscountCode) {\n    priceRule {\n      id\n      title\n      validityPeriod {\n        start\n      }\n      allocationMethod\n      itemEntitlements {\n        products(first: 3) {\n          edges {\n            node {\n              id\n            }\n          }\n        }\n        targetAllLineItems\n      }\n      valueV2 {\n        ... on MoneyV2 {\n          amount\n          currencyCode\n        }\n      }\n      customerSelection {\n        forAllCustomers\n      }\n      oncePerCustomer\n      usageLimit\n      target\n    }\n    priceRuleDiscountCode {\n      id\n      code\n    }\n    priceRuleUserErrors {\n      code\n      field\n      message\n    }\n  }\n}"
#### Graphql Input
{
  "priceRule": {
    "title": "Boots Discount",
    "allocationMethod": "ACROSS",
    "customerSelection": {
      "forAllCustomers": true
    },
    "itemEntitlements": {
      "targetAllLineItems": false,
      "productIds": [
        "gid://shopify/Product/121709582"
      ]
    },
    "target": "LINE_ITEM",
    "validityPeriod": {
      "start": "2016-08-29T12:00:00-04:00"
    },
    "value": {
      "fixedAmountValue": "-10.0"
    }
  }
}
#### Graphql Response
{
  "data": {
    "priceRuleCreate": {
      "priceRule": {
        "id": "gid://shopify/PriceRule/1057371212",
        "title": "Boots Discount",
        "validityPeriod": {
          "start": "2016-08-29T16:00:00Z"
        },
        "allocationMethod": "ACROSS",
        "itemEntitlements": {
          "products": {
            "edges": [
              {
                "node": {
                  "id": "gid://shopify/Product/121709582"
                }
              }
            ]
          },
          "targetAllLineItems": false
        },
        "valueV2": {
          "amount": "-10.0",
          "currencyCode": "USD"
        },
        "customerSelection": {
          "forAllCustomers": true
        },
        "oncePerCustomer": false,
        "usageLimit": null,
        "target": "LINE_ITEM"
      },
      "priceRuleDiscountCode": null,
      "priceRuleUserErrors": []
    }
  }
}