# discountAutomaticBxgyUpdate - admin-graphql - MUTATION Version: 2024-10 ## Description Updates an existing [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 update code discounts, use the [`discountCodeBxgyUpdate`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountCodeBxgyUpdate) mutation instead. ### Access Scopes Apps must have `write_discounts` access scope. ## Arguments * [automaticBxgyDiscount](/docs/api/admin-graphql/2024-10/input-objects/DiscountAutomaticBxgyInput): DiscountAutomaticBxgyInput! - The input data used to update the automatic BXGY discount. * [id](/docs/api/admin-graphql/2024-10/scalars/ID): ID! - The ID of the automatic BXGY discount to update. ## Returns * [automaticDiscountNode](/docs/api/admin-graphql/2024-10/objects/DiscountAutomaticNode): DiscountAutomaticNode The automatic discount that was updated. * [userErrors](/docs/api/admin-graphql/2024-10/objects/DiscountUserError): DiscountUserError! The list of errors that occurred from executing the mutation. ## Examples ### Update an automatic buy X get Y (BXGY) discount Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) { discountAutomaticBxgyUpdate(id: $id, automaticBxgyDiscount: $automaticBxgyDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBxgy { title startsAt endsAt } } } userErrors { field message } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/DiscountAutomaticBxgy/198286294\",\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 UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n discountAutomaticBxgyUpdate(id: $id, 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 \"id\": \"gid://shopify/DiscountAutomaticBxgy/198286294\",\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 UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n discountAutomaticBxgyUpdate(id: $id, 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 \"id\": \"gid://shopify/DiscountAutomaticBxgy/198286294\",\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 UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n discountAutomaticBxgyUpdate(id: $id, 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 \"id\": \"gid://shopify/DiscountAutomaticBxgy/198286294\",\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 UpdateBxgyDiscount($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n discountAutomaticBxgyUpdate(id: $id, 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 { "id": "gid://shopify/DiscountAutomaticBxgy/198286294", "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": { "discountAutomaticBxgyUpdate": { "automaticDiscountNode": { "id": "gid://shopify/DiscountAutomaticNode/198286294", "automaticDiscount": { "title": "Buy first product, get second product free", "startsAt": "2025-01-01T00:00:00Z", "endsAt": "2025-12-31T23:59:59Z" } }, "userErrors": [] } } } ### Updating a BXGY discount with invalid input returns an error Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation discountAutomaticBxgyUpdate($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) { discountAutomaticBxgyUpdate(id: $id, automaticBxgyDiscount: $automaticBxgyDiscount) { automaticDiscountNode { id } userErrors { field message } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/DiscountAutomaticBxgy/198286294\",\n \"automaticBxgyDiscount\": {\n \"title\": \"Invalid discount percentage\",\n \"customerGets\": {\n \"value\": {\n \"discountOnQuantity\": {\n \"quantity\": \"1\",\n \"effect\": {\n \"percentage\": 1.5\n }\n }\n }\n }\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation discountAutomaticBxgyUpdate($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n discountAutomaticBxgyUpdate(id: $id, automaticBxgyDiscount: $automaticBxgyDiscount) {\n automaticDiscountNode {\n id\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/DiscountAutomaticBxgy/198286294\",\n \"automaticBxgyDiscount\": {\n \"title\": \"Invalid discount percentage\",\n \"customerGets\": {\n \"value\": {\n \"discountOnQuantity\": {\n \"quantity\": \"1\",\n \"effect\": {\n \"percentage\": 1.5\n }\n }\n }\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 discountAutomaticBxgyUpdate($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n discountAutomaticBxgyUpdate(id: $id, automaticBxgyDiscount: $automaticBxgyDiscount) {\n automaticDiscountNode {\n id\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/DiscountAutomaticBxgy/198286294\",\n \"automaticBxgyDiscount\": {\n \"title\": \"Invalid discount percentage\",\n \"customerGets\": {\n \"value\": {\n \"discountOnQuantity\": {\n \"quantity\": \"1\",\n \"effect\": {\n \"percentage\": 1.5\n }\n }\n }\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 discountAutomaticBxgyUpdate($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n discountAutomaticBxgyUpdate(id: $id, automaticBxgyDiscount: $automaticBxgyDiscount) {\n automaticDiscountNode {\n id\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/DiscountAutomaticBxgy/198286294\",\n \"automaticBxgyDiscount\": {\n \"title\": \"Invalid discount percentage\",\n \"customerGets\": {\n \"value\": {\n \"discountOnQuantity\": {\n \"quantity\": \"1\",\n \"effect\": {\n \"percentage\": 1.5\n }\n }\n }\n }\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation discountAutomaticBxgyUpdate($id: ID!, $automaticBxgyDiscount: DiscountAutomaticBxgyInput!) {\n discountAutomaticBxgyUpdate(id: $id, automaticBxgyDiscount: $automaticBxgyDiscount) {\n automaticDiscountNode {\n id\n }\n userErrors {\n field\n message\n }\n }\n}" #### Graphql Input { "id": "gid://shopify/DiscountAutomaticBxgy/198286294", "automaticBxgyDiscount": { "title": "Invalid discount percentage", "customerGets": { "value": { "discountOnQuantity": { "quantity": "1", "effect": { "percentage": 1.5 } } } } } } #### Graphql Response { "data": { "discountAutomaticBxgyUpdate": { "automaticDiscountNode": null, "userErrors": [ { "field": [ "automaticBxgyDiscount", "customerGets", "value", "discountOnQuantity", "effect", "percentage" ], "message": "Value must be between 0.0 and 1.0" } ] } } }