Discount code usage is not recorded when order is created through API

Kazuki_Test_Sto
Shopify Partner
3 0 0

Hi there, it seems when we create order through REST API, discount code usage is not recorded at all.

 

Below is curl command I used (url and authorization is masked)

curl -X POST \
  https://*********.myshopify.com/admin/orders.json \
  -H 'authorization: Basic *********' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{"order": {"line_items": [{"title": "Red Leather Coat", "price": 129.99, "grams": "1700", "quantity": 1 }], "total_price": 119.00, "discount_codes": [{"code": "MYDISCOUNT", "type": "percentage", "amount": 10}]}}'

Even though order was created successfully, the usage of discount code was not recorded at all. In shopify admin UI, I see discount code is shown as 0 time used, and "sales by discount" dashboard doesn't work either.

Is there any way to mark discount code as used?

I also tried PUT discount_code API, but it didn't work either.

 

curl -X PUT https://*******.myshopify.com/admin/price_rules/42620583963/discount_codes/*******.json \
  -H 'authorization: Basic *******' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{"discount_code": {"usage_count": 3, "code": "MYDISCOUNT"}}'

Response (note usage_count remains 0):

{"discount_code":{"id":******,"price_rule_id":******,"code":"MYDISCOUNT","usage_count":0,"created_at":"2017-10-12T13:09:26-04:00","updated_at":"2017-10-12T13:09:26-04:00"}}

0 Likes
Alex
Shopify Staff
Shopify Staff
1555 81 306

Hey there.

Discounts indicated in order creation requests aren't actually attributed to existing discount codes in the shop. They're intended as fabricated discounts on the spot which you can attribute to any code you deem necessary, and is entirely seperate from existing codes.

You also won't be able to increment discount code usage as that's a read-only field.

Cheers.

0 Likes
Kazuki_Test_Sto
Shopify Partner
3 0 0

Thanks Alex. Is there any way to update discount usage via API?

0 Likes
Alex
Shopify Staff
Shopify Staff
1555 81 306

Hey again,

At this time that's a no, unfortunately.

Cheers.

0 Likes
Kazuki_Test_Sto
Shopify Partner
3 0 0

Thanks for quick response. One more follow-up question: Is there any API to calculate discount code eligibility and amount? (eg., if discount code is expired, calculate item-specific discount, etc)

0 Likes
Sante_Kotturi
Shopify Partner
4 0 1

Hey Alex, has this changed in the last 12 months? 

0 Likes
cquinterom096
Shopify Partner
3 0 0

Any news on this? I am having the same issue. Or at least an alternative? We currently have a mobile app and we use the orders endpoint to create certain orders but the usage doesn't increase.

0 Likes