[#998] Getting the discount code(s) used for a booking through the API

Migrated from Redmine #998 | Author: Stephan Tensen
Status: Closed | Priority: Normal | Created: 2023-01-10


Some time ago I have had a conversation with Alex. I asked him if it is possible to get the discount code(s) used for a booking through the API.
He answered: “Yes, you can get this for every appointment. You would need to get the code from the invoice entity”

My developer has tried to get this done, but he didn’t succeed. I want to give it another try.

This is the message from my developer to you (the developers of Simplybook):


I am afraid that I am doing something wrong.

I checked both the regular API and the REST API, but no luck.

Can you please tell me what I am doing wrong and what return type or API call I am looking for. As an example; On the invoice I see that booking “vo4368ru7” has used 2 promo-codes: “KERSTVAKANTIE” and “36503034”, but I cannot find these 2 codes back anywhere in the API.

Looking forward for your response.
Our user ID is ‘onehourlockup’

See also Support #786: About API - API - Simplybook.me support for developers

Dmytro Bondarev wrote:

Hello,

AdminInvoiceEntity contains promotion_instances, which is array of PromotionInstanceEntity, that contains code and all required information.

Jeffrey van Hal wrote:

Hi Dmytro,

I am the Dev for onehourlockup.

The return “AdminInvoiceEntity” is not showing the results

Using API documentation | SimplyBook.me Online Scheduling

Payload:
GET https://user-api-v2.simplybook.me/admin/invoices?filter[booking_code]=vo4368ru7
With 2 headers: ‘X-Company-Login’ and ‘X-Token’ (values redacted for privacy, feel free to contact me if needed)

Will return the following JSON;
{
“data”: [
{
“client”: {
{REDACTED FOR PRIVACY}
},
“created_by_user_id”: null,
“created_by_user”: null,
“approved_by_user_id”: null,
“approved_by_user”: null,
“refunded_by_user_id”: null,
“refunded_by_user”: null,
“used_discount_amount”: null,
“booking_date_start”: null,
“client_additional_info”: ,
“id”: 2143,
“number”: “I-00001808”,
“datetime”: “2023-01-02 09:07:43”,
“due_datetime”: “2023-01-02 09:17:43”,
“payment_datetime”: “2023-01-02 09:11:26”,
“amount”: 23.75,
“recurring_amount”: 0.0,
“deposit”: 100.0,
“is_with_deposit_amount”: false,
“rest_amount”: 0.0,
“discount_amount”: 76.25,
“taxes”: [
{
“amount”: 1.961,
“id”: 1,
“name”: “BTW laag”,
“ratio”: 0.09,
“is_default”: true
}
],
“tax_amount”: 1.961,
“currency”: “EUR”,
“client_id”: 2063,
“description”: “”,
“payment_received”: true,
“payment_processor”: “mollie”,
“lines”: [
{
“booking_ids”: [
4113
],
“bookings”: null,
“tickets”: ,
“deposit”: 100.0,
“is_with_deposit_amount”: false,
“description_string”: “Dienst: VR Escapegame 3 personen (Vrijdag, 06-01-2023 16:00, vo4368ru7) x1 23.75 EUR”,
“id”: “2504”,
“invoice_id”: 2143,
“object_name”: “VR Escapegame 3 personen (Vrijdag, 06-01-2023 16:00, vo4368ru7)”,
“name”: “VR Escapegame 3 personen (Vrijdag, 06-01-2023 16:00, vo4368ru7)”,
“type”: “booking”,
“discount_ratio”: 0.05,
“discount_amount”: 75.0,
“discount”: 76.25,
“price”: 100.0,
“price_without_tax”: 91.743119266055,
“final_price”: 23.75,
“recurring_price_without_tax”: 0.0,
“qty”: 1.0,
“package_qty”: 0.0,
“tax”: {
“id”: 1,
“name”: “BTW laag”,
“ratio”: 0.09,
“is_default”: true
},
“tax_ratio”: 0.09,
“tax_amount”: 1.961,
“amount”: 23.75,
“recurring_tax_amount”: 0.0,
“rest_amount”: 0.0,
“currency”: “EUR”
}
],
“status”: “paid”,
“support_recurring_payment_method”: false,
“recurring_profile_id”: null,
“promotion_instances”: ,
“package_instances”: ,
“deposit_child_invoice”: null,
“deposit_parent_invoice”: null,
“refund_datetime”: null,
“sbpay_reference_id”: null,
“sbpay_invoice_id”: “”
}
],
“metadata”: {
“items_count”: 1,
“pages_count”: 1,
“page”: 1,
“on_page”: 10
}
}

I see the discount (76.25) but no mention of the 2 promo-codes: “KERSTVAKANTIE” and “36503034” . The “promotion_instances” (where I expect the used codes) is an empty array.

Maybe a bug in API ?

Thanks,
Jeffrey

Dmytro Bondarev wrote:

Hi, only detailed info will return this data, please try to get invoice by id.

Jeffrey van Hal wrote:

Thanks.

using GET https://user-api-v2.simplybook.me/admin/invoices/{invoiceID} will return the same AdminInvoiceEntity , but this time with the promotion_instances filled.

Solved !