Orders Api - Unable to create LINE_ITEM discount

Hi,

I’m trying to create an order with discounts that apply to specific line items,
followed what I’ve understood from the docs, added the discounts to the order (with scope) and the discount UID to each order line item applied_discounts,

Would appreciate any assistance,

Sandbox App Id:
sandbox-sq0idb-InQP_pPUsVWjbrQXm93ktA

Thanks,

Example for a request that failed:

{
“request”: {
“method”: “POST”,
“url”: “https://connect.squareupsandbox.com/v2/orders”,
“headers”: {
“user-agent”: “Square-TypeScript-SDK/11.0.0”,
“content-type”: “application/json”,
“authorization”: “Bearer xxxxxx”,
“Square-Version”: “2021-05-13”,
“accept”: “application/json”
},
“body”: {
“type”: “text”,
“content”: “{“order”:{“location_id”:“CF69ZFKDKYQS3”,“source”:{“name”:“app-server”},“customer_id”:“PNZT14RE5S4G1CM5PJFYFFMMX4”,“line_items”:[{“quantity”:“1”,“catalog_object_id”:“UYEZHMUYMLLNXNXAZQ43GWCG”,“modifiers”:,“applied_discounts”:[{“discount_uid”:“248c0f”}]},{“quantity”:“1”,“catalog_object_id”:“GIZRWRATYJTPE34KN35YTX7D”,“modifiers”:}],“taxes”:[{“catalog_object_id”:“ZAVPI7WZUXAVZZUL4SRZPJIJ”}],“discounts”:[{“uid”:“248c0f”,“name”:”$2 Off Pastries",“type”:“FIXED_AMOUNT”,“amount_money”:{“amount”:200,“currency”:“USD”},“scope”:“LINE_ITEM”}],“fulfillments”:[{“type”:“PICKUP”,“pickup_details”:{“recipient”:{“customer_id”:“PNZT14RE5S4G1CM5PJFYFFMMX4”,“display_name”:“OOO ppp perez”},“schedule_type”:“ASAP”,“prep_time_duration”:“P0DT0H0M1S”}}]},“idempotency_key”:“5ffc31b8-d19b-4075-afa4-c59ad9da55a4”}"
}
},
“statusCode”: 400,
“headers”: {
“date”: “Wed, 09 Jun 2021 07:49:48 GMT”,
},
“body”: “{“errors”: [{“code”: “BAD_REQUEST”,“detail”: “mixed usage of applied adjustments fields with deprecated adjustments fields is not supported”,“category”: “INVALID_REQUEST_ERROR”}]}\n”,
“result”: {
“errors”: [
{
“code”: “BAD_REQUEST”,
“detail”: “mixed usage of applied adjustments fields with deprecated adjustments fields is not supported”,
“category”: “INVALID_REQUEST_ERROR”
}
]
}

Found the issue,

I’ve used order.taxes instead of applied_taxes, this caused the issue.
when switching to applied_taxes on the order the issue is resolved,

couldn’t find applied_taxes on the new sdk bydway, maybe I’m missing something ?,

working order request, if it helps anyone in the future:

{
    "idempotencyKey": "fcf60852-9a64-4918-8d2b-9f0f94223473",
    "order": {
        "source": {
            "name": "test"
        },
        "location_id": "CF69ZFKDKYQS3",
        "applied_taxes": [
            {
                "catalog_object_id": "ZAVPI7WZUXAVZZUL4SRZPJIJ"
            }
        ],
         "discounts": [
            {
                "amount_money": {
                    "amount": 200,
                    "currency": "USD"
                },
                "name": "$2 Off Pastries",
                "scope": "LINE_ITEM",
                "type": "FIXED_AMOUNT",
                "uid": "1234"
            }
        ],
        "line_items": [
            {
                "catalog_object_id": "UYEZHMUYMLLNXNXAZQ43GWCG",
                "modifiers": [],
                "quantity": "1",
                "applied_discounts": [
                    {
                        "discount_uid": "1234"
                    }
                ]
            },
            {
                "catalog_object_id": "GIZRWRATYJTPE34KN35YTX7D",
                "modifiers": [],
                "quantity": "1"
            }
        ],
        "customer_id": "PNZT14RE5S4G1CM5PJFYFFMMX4",
        "fulfillments": [
            {
                "type": "PICKUP",
                "pickup_details": {
                    "recipient": {
                        "display_name": "OOO",
                        "customer_id": "PNZT14RE5S4G1CM5PJFYFFMMX4"
                    },
                    "schedule_type": "ASAP",
                    "prep_time_duration": "P0DT0H0M1S"
                }
            }
        ]
    }
}

Glad to hear that you figured it out. What SDK are you using?

Thanks,

Node - “square”: “^11.0.0”,

@Bryan-Square acctually the solution above did not work, what I’ve noticed is that if you use node sdk order taxes property in tandem with discounts property, if one of their scope is line items, the other should be the same or it won’t work,

can you confirm ? I’ve changed both the taxes and discounts to line items and fixed the line_items to reflect the change and now it seems much better.

the solution above simply deleted the taxes, as applied_taxes does not exist on the new node sdk, this also resolved the error but removed taxes from the order which is not the intended behaivour.