# discountAutomaticBxgyCreate - admin-graphql - MUTATION
Version: 2025-01

## Description
Creates a
[buy X get Y discount (BXGY)](https://help.shopify.com/manual/discounts/discount-types/buy-x-get-y)
that's automatically applied on a cart and at checkout.

> Note:
> To create code discounts, use the
[`discountCodeBxgyCreate`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountCodeBxgyCreate)
mutation.

### Access Scopes
Apps must have `write_discounts` access scope.


## Arguments
* [automaticBxgyDiscount](/docs/api/admin-graphql/2025-01/input-objects/DiscountAutomaticBxgyInput): DiscountAutomaticBxgyInput! - The input data used to create the automatic BXGY discount.


## Returns
* [automaticDiscountNode](/docs/api/admin-graphql/2025-01/objects/DiscountAutomaticNode): DiscountAutomaticNode The automatic discount that was created.
* [userErrors](/docs/api/admin-graphql/2025-01/objects/DiscountUserError): DiscountUserError! The list of errors that occurred from executing the mutation.


## Examples
### Create an automatic buy X get Y (BXGY) discount for different products
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) { discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBxgy { title startsAt endsAt } } } userErrors { field message } } }\",\n \"variables\": {\n    \"automaticBxgyDiscount\": {\n      \"title\": \"Buy first product, get second product free\",\n      \"startsAt\": \"2025-01-01T00:00:00Z\",\n      \"endsAt\": \"2025-12-31T23:59:59Z\",\n      \"customerBuys\": {\n        \"items\": {\n          \"products\": {\n            \"productsToAdd\": [\n              \"gid://shopify/Product/108828309\"\n            ]\n          }\n        },\n        \"value\": {\n          \"quantity\": \"1\"\n        }\n      },\n      \"customerGets\": {\n        \"items\": {\n          \"products\": {\n            \"productsToAdd\": [\n              \"gid://shopify/Product/20995642\"\n            ]\n          }\n        },\n        \"value\": {\n          \"discountOnQuantity\": {\n            \"quantity\": \"1\",\n            \"effect\": {\n              \"percentage\": 1.0\n            }\n          }\n        }\n      },\n      \"usesPerOrderLimit\": \"1\"\n    }\n  }\n}'\n"
Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n  data: {\n    \"query\": `mutation CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n      discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {\n        automaticDiscountNode {\n          id\n          automaticDiscount {\n            ... on DiscountAutomaticBxgy {\n              title\n              startsAt\n              endsAt\n            }\n          }\n        }\n        userErrors {\n          field\n          message\n        }\n      }\n    }`,\n    \"variables\": {\n      \"automaticBxgyDiscount\": {\n        \"title\": \"Buy first product, get second product free\",\n        \"startsAt\": \"2025-01-01T00:00:00Z\",\n        \"endsAt\": \"2025-12-31T23:59:59Z\",\n        \"customerBuys\": {\n          \"items\": {\n            \"products\": {\n              \"productsToAdd\": [\n                \"gid://shopify/Product/108828309\"\n              ]\n            }\n          },\n          \"value\": {\n            \"quantity\": \"1\"\n          }\n        },\n        \"customerGets\": {\n          \"items\": {\n            \"products\": {\n              \"productsToAdd\": [\n                \"gid://shopify/Product/20995642\"\n              ]\n            }\n          },\n          \"value\": {\n            \"discountOnQuantity\": {\n              \"quantity\": \"1\",\n              \"effect\": {\n                \"percentage\": 1.0\n              }\n            }\n          }\n        },\n        \"usesPerOrderLimit\": \"1\"\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 CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n    discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {\n      automaticDiscountNode {\n        id\n        automaticDiscount {\n          ... on DiscountAutomaticBxgy {\n            title\n            startsAt\n            endsAt\n          }\n        }\n      }\n      userErrors {\n        field\n        message\n      }\n    }\n  }\nQUERY\n\nvariables = {\n  \"automaticBxgyDiscount\": {\n    \"title\": \"Buy first product, get second product free\",\n    \"startsAt\": \"2025-01-01T00:00:00Z\",\n    \"endsAt\": \"2025-12-31T23:59:59Z\",\n    \"customerBuys\": {\n      \"items\": {\n        \"products\": {\n          \"productsToAdd\": [\"gid://shopify/Product/108828309\"]\n        }\n      },\n      \"value\": {\n        \"quantity\": \"1\"\n      }\n    },\n    \"customerGets\": {\n      \"items\": {\n        \"products\": {\n          \"productsToAdd\": [\"gid://shopify/Product/20995642\"]\n        }\n      },\n      \"value\": {\n        \"discountOnQuantity\": {\n          \"quantity\": \"1\",\n          \"effect\": {\n            \"percentage\": 1.0\n          }\n        }\n      }\n    },\n    \"usesPerOrderLimit\": \"1\"\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 CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n    discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {\n      automaticDiscountNode {\n        id\n        automaticDiscount {\n          ... on DiscountAutomaticBxgy {\n            title\n            startsAt\n            endsAt\n          }\n        }\n      }\n      userErrors {\n        field\n        message\n      }\n    }\n  }`,\n  {\n    variables: {\n      \"automaticBxgyDiscount\": {\n        \"title\": \"Buy first product, get second product free\",\n        \"startsAt\": \"2025-01-01T00:00:00Z\",\n        \"endsAt\": \"2025-12-31T23:59:59Z\",\n        \"customerBuys\": {\n          \"items\": {\n            \"products\": {\n              \"productsToAdd\": [\n                \"gid://shopify/Product/108828309\"\n              ]\n            }\n          },\n          \"value\": {\n            \"quantity\": \"1\"\n          }\n        },\n        \"customerGets\": {\n          \"items\": {\n            \"products\": {\n              \"productsToAdd\": [\n                \"gid://shopify/Product/20995642\"\n              ]\n            }\n          },\n          \"value\": {\n            \"discountOnQuantity\": {\n              \"quantity\": \"1\",\n              \"effect\": {\n                \"percentage\": 1.0\n              }\n            }\n          }\n        },\n        \"usesPerOrderLimit\": \"1\"\n      }\n    },\n  },\n);\n\nconst data = await response.json();\n"
Graphql query: "mutation CreateBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n  discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {\n    automaticDiscountNode {\n      id\n      automaticDiscount {\n        ... on DiscountAutomaticBxgy {\n          title\n          startsAt\n          endsAt\n        }\n      }\n    }\n    userErrors {\n      field\n      message\n    }\n  }\n}"
#### Graphql Input
{
  "automaticBxgyDiscount": {
    "title": "Buy first product, get second product free",
    "startsAt": "2025-01-01T00:00:00Z",
    "endsAt": "2025-12-31T23:59:59Z",
    "customerBuys": {
      "items": {
        "products": {
          "productsToAdd": [
            "gid://shopify/Product/108828309"
          ]
        }
      },
      "value": {
        "quantity": "1"
      }
    },
    "customerGets": {
      "items": {
        "products": {
          "productsToAdd": [
            "gid://shopify/Product/20995642"
          ]
        }
      },
      "value": {
        "discountOnQuantity": {
          "quantity": "1",
          "effect": {
            "percentage": 1.0
          }
        }
      }
    },
    "usesPerOrderLimit": "1"
  }
}
#### Graphql Response
{
  "data": {
    "discountAutomaticBxgyCreate": {
      "automaticDiscountNode": {
        "id": "gid://shopify/DiscountAutomaticNode/1057371440",
        "automaticDiscount": {
          "title": "Buy first product, get second product free",
          "startsAt": "2025-01-01T00:00:00Z",
          "endsAt": "2025-12-31T23:59:59Z"
        }
      },
      "userErrors": []
    }
  }
}

### Create an automatic buy X get Y (BXGY) discount for the same product
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation CreateAutomaticBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) { discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBxgy { title startsAt endsAt } } } userErrors { field message } } }\",\n \"variables\": {\n    \"automaticBxgyDiscount\": {\n      \"title\": \"Buy one, get one free\",\n      \"startsAt\": \"2025-01-01T00:00:00Z\",\n      \"endsAt\": \"2025-12-31T23:59:59Z\",\n      \"customerBuys\": {\n        \"items\": {\n          \"products\": {\n            \"productsToAdd\": [\n              \"gid://shopify/Product/108828309\"\n            ]\n          }\n        },\n        \"value\": {\n          \"quantity\": \"1\"\n        }\n      },\n      \"customerGets\": {\n        \"items\": {\n          \"products\": {\n            \"productsToAdd\": [\n              \"gid://shopify/Product/108828309\"\n            ]\n          }\n        },\n        \"value\": {\n          \"discountOnQuantity\": {\n            \"effect\": {\n              \"percentage\": 1.0\n            },\n            \"quantity\": \"1\"\n          }\n        }\n      },\n      \"usesPerOrderLimit\": \"1\"\n    }\n  }\n}'\n"
Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n  data: {\n    \"query\": `mutation CreateAutomaticBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n      discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {\n        automaticDiscountNode {\n          id\n          automaticDiscount {\n            ... on DiscountAutomaticBxgy {\n              title\n              startsAt\n              endsAt\n            }\n          }\n        }\n        userErrors {\n          field\n          message\n        }\n      }\n    }`,\n    \"variables\": {\n      \"automaticBxgyDiscount\": {\n        \"title\": \"Buy one, get one free\",\n        \"startsAt\": \"2025-01-01T00:00:00Z\",\n        \"endsAt\": \"2025-12-31T23:59:59Z\",\n        \"customerBuys\": {\n          \"items\": {\n            \"products\": {\n              \"productsToAdd\": [\n                \"gid://shopify/Product/108828309\"\n              ]\n            }\n          },\n          \"value\": {\n            \"quantity\": \"1\"\n          }\n        },\n        \"customerGets\": {\n          \"items\": {\n            \"products\": {\n              \"productsToAdd\": [\n                \"gid://shopify/Product/108828309\"\n              ]\n            }\n          },\n          \"value\": {\n            \"discountOnQuantity\": {\n              \"effect\": {\n                \"percentage\": 1.0\n              },\n              \"quantity\": \"1\"\n            }\n          }\n        },\n        \"usesPerOrderLimit\": \"1\"\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 CreateAutomaticBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n    discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {\n      automaticDiscountNode {\n        id\n        automaticDiscount {\n          ... on DiscountAutomaticBxgy {\n            title\n            startsAt\n            endsAt\n          }\n        }\n      }\n      userErrors {\n        field\n        message\n      }\n    }\n  }\nQUERY\n\nvariables = {\n  \"automaticBxgyDiscount\": {\n    \"title\": \"Buy one, get one free\",\n    \"startsAt\": \"2025-01-01T00:00:00Z\",\n    \"endsAt\": \"2025-12-31T23:59:59Z\",\n    \"customerBuys\": {\n      \"items\": {\n        \"products\": {\n          \"productsToAdd\": [\"gid://shopify/Product/108828309\"]\n        }\n      },\n      \"value\": {\n        \"quantity\": \"1\"\n      }\n    },\n    \"customerGets\": {\n      \"items\": {\n        \"products\": {\n          \"productsToAdd\": [\"gid://shopify/Product/108828309\"]\n        }\n      },\n      \"value\": {\n        \"discountOnQuantity\": {\n          \"effect\": {\n            \"percentage\": 1.0\n          },\n          \"quantity\": \"1\"\n        }\n      }\n    },\n    \"usesPerOrderLimit\": \"1\"\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 CreateAutomaticBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n    discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {\n      automaticDiscountNode {\n        id\n        automaticDiscount {\n          ... on DiscountAutomaticBxgy {\n            title\n            startsAt\n            endsAt\n          }\n        }\n      }\n      userErrors {\n        field\n        message\n      }\n    }\n  }`,\n  {\n    variables: {\n      \"automaticBxgyDiscount\": {\n        \"title\": \"Buy one, get one free\",\n        \"startsAt\": \"2025-01-01T00:00:00Z\",\n        \"endsAt\": \"2025-12-31T23:59:59Z\",\n        \"customerBuys\": {\n          \"items\": {\n            \"products\": {\n              \"productsToAdd\": [\n                \"gid://shopify/Product/108828309\"\n              ]\n            }\n          },\n          \"value\": {\n            \"quantity\": \"1\"\n          }\n        },\n        \"customerGets\": {\n          \"items\": {\n            \"products\": {\n              \"productsToAdd\": [\n                \"gid://shopify/Product/108828309\"\n              ]\n            }\n          },\n          \"value\": {\n            \"discountOnQuantity\": {\n              \"effect\": {\n                \"percentage\": 1.0\n              },\n              \"quantity\": \"1\"\n            }\n          }\n        },\n        \"usesPerOrderLimit\": \"1\"\n      }\n    },\n  },\n);\n\nconst data = await response.json();\n"
Graphql query: "mutation CreateAutomaticBxgyDiscount($automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n  discountAutomaticBxgyCreate(automaticBxgyDiscount: $automaticBxgyDiscount) {\n    automaticDiscountNode {\n      id\n      automaticDiscount {\n        ... on DiscountAutomaticBxgy {\n          title\n          startsAt\n          endsAt\n        }\n      }\n    }\n    userErrors {\n      field\n      message\n    }\n  }\n}"
#### Graphql Input
{
  "automaticBxgyDiscount": {
    "title": "Buy one, get one free",
    "startsAt": "2025-01-01T00:00:00Z",
    "endsAt": "2025-12-31T23:59:59Z",
    "customerBuys": {
      "items": {
        "products": {
          "productsToAdd": [
            "gid://shopify/Product/108828309"
          ]
        }
      },
      "value": {
        "quantity": "1"
      }
    },
    "customerGets": {
      "items": {
        "products": {
          "productsToAdd": [
            "gid://shopify/Product/108828309"
          ]
        }
      },
      "value": {
        "discountOnQuantity": {
          "effect": {
            "percentage": 1.0
          },
          "quantity": "1"
        }
      }
    },
    "usesPerOrderLimit": "1"
  }
}
#### Graphql Response
{
  "data": {
    "discountAutomaticBxgyCreate": {
      "automaticDiscountNode": {
        "id": "gid://shopify/DiscountAutomaticNode/1057371443",
        "automaticDiscount": {
          "title": "Buy one, get one free",
          "startsAt": "2025-01-01T00:00:00Z",
          "endsAt": "2025-12-31T23:59:59Z"
        }
      },
      "userErrors": []
    }
  }
}