# discountCodeFreeShippingCreate - admin-graphql - MUTATION Version: 2025-01 ## Description Creates an [free shipping discount](https://help.shopify.com/manual/discounts/discount-types/free-shipping) that's applied on a cart and at checkout when a customer enters a code. > Note: > To create discounts that are automatically applied on a cart and at checkout, use the [`discountAutomaticFreeShippingCreate`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/discountAutomaticFreeShippingCreate) mutation. ### Access Scopes Apps must have `write_discounts` access scope. ## Arguments * [freeShippingCodeDiscount](/docs/api/admin-graphql/2025-01/input-objects/DiscountCodeFreeShippingInput): DiscountCodeFreeShippingInput! - The input data used to create the discount code. ## Returns * [codeDiscountNode](/docs/api/admin-graphql/2025-01/objects/DiscountCodeNode): DiscountCodeNode The discount code 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 a discount code for free shipping 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 discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) { discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) { codeDiscountNode { id codeDiscount { ... on DiscountCodeFreeShipping { title startsAt endsAt maximumShippingPrice { amount } customerSelection { ... on DiscountCustomerAll { allCustomers } } destinationSelection { ... on DiscountCountryAll { allCountries } } minimumRequirement { ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount } } } codes(first: 2) { nodes { code } } } } } userErrors { field code message } } }\",\n \"variables\": {\n \"freeShippingCodeDiscount\": {\n \"startsAt\": \"2022-06-22T21:12:07.000Z\",\n \"appliesOncePerCustomer\": false,\n \"title\": \"FreeShipping\",\n \"code\": \"FreeShipping\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 20.0\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"destination\": {\n \"all\": true\n }\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) {\n discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeFreeShipping {\n title\n startsAt\n endsAt\n maximumShippingPrice {\n amount\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n destinationSelection {\n ... on DiscountCountryAll {\n allCountries\n }\n }\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n }\n }\n }\n codes(first: 2) {\n nodes {\n code\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }`,\n \"variables\": {\n \"freeShippingCodeDiscount\": {\n \"startsAt\": \"2022-06-22T21:12:07.000Z\",\n \"appliesOncePerCustomer\": false,\n \"title\": \"FreeShipping\",\n \"code\": \"FreeShipping\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 20.0\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"destination\": {\n \"all\": true\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 discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) {\n discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeFreeShipping {\n title\n startsAt\n endsAt\n maximumShippingPrice {\n amount\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n destinationSelection {\n ... on DiscountCountryAll {\n allCountries\n }\n }\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n }\n }\n }\n codes(first: 2) {\n nodes {\n code\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"freeShippingCodeDiscount\": {\n \"startsAt\": \"2022-06-22T21:12:07.000Z\",\n \"appliesOncePerCustomer\": false,\n \"title\": \"FreeShipping\",\n \"code\": \"FreeShipping\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 20.0\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"destination\": {\n \"all\": true\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 discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) {\n discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeFreeShipping {\n title\n startsAt\n endsAt\n maximumShippingPrice {\n amount\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n destinationSelection {\n ... on DiscountCountryAll {\n allCountries\n }\n }\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n }\n }\n }\n codes(first: 2) {\n nodes {\n code\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n }`,\n {\n variables: {\n \"freeShippingCodeDiscount\": {\n \"startsAt\": \"2022-06-22T21:12:07.000Z\",\n \"appliesOncePerCustomer\": false,\n \"title\": \"FreeShipping\",\n \"code\": \"FreeShipping\",\n \"minimumRequirement\": {\n \"subtotal\": {\n \"greaterThanOrEqualToSubtotal\": 20.0\n }\n },\n \"customerSelection\": {\n \"all\": true\n },\n \"destination\": {\n \"all\": true\n }\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation discountCodeFreeShippingCreate($freeShippingCodeDiscount: DiscountCodeFreeShippingInput!) {\n discountCodeFreeShippingCreate(freeShippingCodeDiscount: $freeShippingCodeDiscount) {\n codeDiscountNode {\n id\n codeDiscount {\n ... on DiscountCodeFreeShipping {\n title\n startsAt\n endsAt\n maximumShippingPrice {\n amount\n }\n customerSelection {\n ... on DiscountCustomerAll {\n allCustomers\n }\n }\n destinationSelection {\n ... on DiscountCountryAll {\n allCountries\n }\n }\n minimumRequirement {\n ... on DiscountMinimumSubtotal {\n greaterThanOrEqualToSubtotal {\n amount\n }\n }\n }\n codes(first: 2) {\n nodes {\n code\n }\n }\n }\n }\n }\n userErrors {\n field\n code\n message\n }\n }\n}" #### Graphql Input { "freeShippingCodeDiscount": { "startsAt": "2022-06-22T21:12:07.000Z", "appliesOncePerCustomer": false, "title": "FreeShipping", "code": "FreeShipping", "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": 20.0 } }, "customerSelection": { "all": true }, "destination": { "all": true } } } #### Graphql Response { "data": { "discountCodeFreeShippingCreate": { "codeDiscountNode": { "id": "gid://shopify/DiscountCodeNode/1057371199", "codeDiscount": { "title": "FreeShipping", "startsAt": "2022-06-22T21:12:07Z", "endsAt": null, "maximumShippingPrice": null, "customerSelection": { "allCustomers": true }, "destinationSelection": { "allCountries": true }, "minimumRequirement": { "greaterThanOrEqualToSubtotal": { "amount": "20.0" } }, "codes": { "nodes": [ { "code": "FreeShipping" } ] } } }, "userErrors": [] } } }