Why isn't my discount applying correctly in REST API with PHP?

Hi @pstanek

I checked your issue and thought the problem could have been caused by missing data when you created the draft order.

This is a sample data that Shopify provides

HTTP/1.1 201 Created
{
  "draft_order": {
    "id": 1069920475,
    "note": null,
    "email": null,
    "taxes_included": false,
    "currency": "USD",
    "invoice_sent_at": null,
    "created_at": "2022-10-03T12:19:47-04:00",
    "updated_at": "2022-10-03T12:19:47-04:00",
    "tax_exempt": false,
    "completed_at": null,
    "name": "#D5",
    "status": "open",
    "line_items": [
      {
        "id": 1066630380,
        "variant_id": 447654529,
        "product_id": 921728736,
        "title": "IPod Touch 8GB",
        "variant_title": "Black",
        "sku": "IPOD2009BLACK",
        "vendor": "Apple",
        "quantity": 1,
        "requires_shipping": true,
        "taxable": true,
        "gift_card": false,
        "fulfillment_service": "shipwire-app",
        "grams": 567,
        "tax_lines": [
          {
            "rate": 0.05,
            "title": "GST",
            "price": "9.95"
          },
          {
            "rate": 0.08,
            "title": "Tax",
            "price": "15.92"
          }
        ],
        "applied_discount": null,
        "name": "IPod Touch 8GB - Black",
        "properties": [],
        "custom": false,
        "price": "199.00",
        "admin_graphql_api_id": "gid://shopify/DraftOrderLineItem/1066630380"
      }
    ],
    "shipping_address": null,
    "billing_address": null,
    "invoice_url": "https://jsmith.myshopify.com/548380009/invoices/d0730281ac9692b04a064b4bac5f23bc",
    "applied_discount": null,
    "order_id": null,
    "shipping_line": null,
    "tax_lines": [
      {
        "rate": 0.05,
        "title": "GST",
        "price": "9.95"
      },
      {
        "rate": 0.08,
        "title": "Tax",
        "price": "15.92"
      }
    ],
    "tags": "",
    "note_attributes": [],
    "total_price": "224.87",
    "subtotal_price": "199.00",
    "total_tax": "25.87",
    "presentment_currency": "USD",
    "total_line_items_price_set": {
      "shop_money": {
        "amount": "199.00",
        "currency_code": "USD"
      },
      "presentment_money": {
        "amount": "199.00",
        "currency_code": "USD"
      }
    },
    "total_price_set": {
      "shop_money": {
        "amount": "224.87",
        "currency_code": "USD"
      },
      "presentment_money": {
        "amount": "224.87",
        "currency_code": "USD"
      }
    },
    "subtotal_price_set": {
      "shop_money": {
        "amount": "199.00",
        "currency_code": "USD"
      },
      "presentment_money": {
        "amount": "199.00",
        "currency_code": "USD"
      }
    },
    "total_tax_set": {
      "shop_money": {
        "amount": "25.87",
        "currency_code": "USD"
      },
      "presentment_money": {
        "amount": "25.87",
        "currency_code": "USD"
      }
    },
    "total_discounts_set": {
      "shop_money": {
        "amount": "0.00",
        "currency_code": "USD"
      },
      "presentment_money": {
        "amount": "0.00",
        "currency_code": "USD"
      }
    },
    "total_shipping_price_set": {
      "shop_money": {
        "amount": "0.00",
        "currency_code": "USD"
      },
      "presentment_money": {
        "amount": "0.00",
        "currency_code": "USD"
      }
    },
    "payment_terms": null,
    "admin_graphql_api_id": "gid://shopify/DraftOrder/1069920475",
    "customer": null
  }
}

You can double-check your data and refer to this material: https://shopify.dev/api/admin-rest/2022-10/resources/draftorder#post-draft-orders.

Feel free to let me know if you need any further help.