How to create an order with REST API with a line item discount

Hi all,

I am trying to create an order that contains a line item discount with the REST API. I can create an order-level discount using the field “discount_codes”; however, I cannot seem to create a line item discount at the time of creation. I have read the API documentation about “discount_applications” and “discount_allocations” but these fields cannot seem to be included in the creation call.

For context, I am testing this using curl on the command line where the order object is passed in the body of the API call. For example:

curl -d '{"order":{"line_items": [{"title": "Hockey Card Pack", "quantity": "1", "price": "2.99"}], "discount_codes": [{"code": "Discount Code 1", "amount": "0.5"}], "test": true }}' \
-X POST "https://{my_shopify_store}/admin/api/2022-07/orders.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"

Thanks in advance!

1 Like

curl -d ‘{“order”:{“line_items”:[{“variant_id”:447654529,“quantity”:1}],“email":"jane@example.com”,“phone”:“18885551234”,“billing_address”:{“first_name”:“John”,“last_name”:“Smith”,“address1”:“123 Fake Street”,“phone”:“555-555-5555”,“city”:“Fakecity”,“province”:“Ontario”,“country”:“Canada”,“zip”:“K2P 1L4”},“shipping_address”:{“first_name”:“Jane”,“last_name”:“Smith”,“address1”:“123 Fake Street”,“phone”:“777-777-7777”,“city”:“Fakecity”,“province”:“Ontario”,“country”:“Canada”,“zip”:“K2P 1L4”},“transactions”:[{“kind”:“sale”,“status”:“success”,“amount”:50.0}],“financial_status”:“paid”,“discount_codes”:[{“code”:“FAKE30”,“amount”:“9.00”,“type”:“percentage”}]}}’
-X POST “https://your-development-store.myshopify.com/admin/api/2023-01/orders.json
-H “X-Shopify-Access-Token: {access_token}”
-H “Content-Type: application/json”

1 Like

Hello @slarter
Here is format in which you can apply discount for line items (Buy 2 X get 20% Off) i,e discount on product item

{
    "checkout": {
         "line_items": [{
            "variant_id": 42599574044911,
            "quantity": 4,
            "applied_discounts": [
          {
            
            "amount": "48",
            "description": "Quantity Discount 20%",
            "created_at": "2008-01-10T11:00:00-05:00",
            "application_type": "automatic"
          }
        ]
        },
        {
            "variant_id": 42210289877231,
            "quantity": 3,
             "applied_discounts": [
          {
            
            "amount": "105.0",
            "description": "Quantity Discount 10%",
            "created_at": "2008-01-10T11:00:00-05:00",
            "application_type": "automatic"
          }
        ]
        },
        {
            "variant_id": 42210289844463,
            "quantity": 1,
             "applied_discounts": [
          {
            
            "amount": "70",
            "description": "Quantity Discount 20% OFF",
            "created_at": "2008-01-10T11:00:00-05:00",
            "application_type": "automatic"
          }
        ]
        }
        ],
"applied_discount": {
    "title": "CHRISMAS",
    "description": "Promotional item for blackfriday.",
    "code":"CHRISMAS10",
    "amount":"141",
    "value_type":"fixed_amount",
    "non_applicable_reason": null,
    "applicable": true,
    "application_type": "automatic"
  }
}     
}

Thanks!!

Hi many thanks for this reply, but do we need to use the checkout call? can we create an order and then send it to checkout?