[#655] How to cancel booking using REST API without the access to the booking id??

Migrated from Redmine #655 | Author: mike hk
Status: New | Priority: Immediate, there is BUG! | Created: 2021-03-01


The cancel booking only accepts “booking id”, but we only have access to [code] when sending booking confirmation email to the users.
How are we supposed to get the “booking id” ??

mike hk wrote:

the [code], which is the booking code, is different from the booking id.
Please let me know how can I cancel a booking with booking code or how can I get the booking id using the booking code…

Redmine Admin wrote:

It ussume bookings were made by API and you have an ID. You can use API documentation | SimplyBook.me Online Scheduling to find bookings

mike hk wrote:

Thanks for the quick reply!

Yes noticed I need to get the booking id first, so I tried the above to get the booking details using the search filter like this:
https://user-api-v2.simplybook.me/admin/bookings?filter[code]=myrandombookingcode

but it is returning latest 10 bookings, how can I limit it to just return that one booking information that matches “myrandombookingcode”?

As it is always returning the latest 10 bookings, I am not even sure if the booking is found using the code, please help

Dmytro Bondarev wrote:

Hi! There is no code option in filter currently, you can use search as described in docs.

*search* - search string (by code, client data)

Dmytro Bondarev wrote:

?filter[search]=yourcode

mike hk wrote:

Thank you for the reply.

I tried “https://user-api-v2.simplybook.me/admin/bookings?filter[search]=mycode” as well, it keeps returning all the bookings.

Please see my full code here:

$booking_code = ‘mycode’; //just showing dummy code here as it is sensitive data, in real I am passing the correct code

$url = ‘https://user-api-v2.simplybook.me/admin/bookings?filter[search]=’.$booking_code;

$curl_handle = curl_init();

    curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'X-Company-Login: '.SIMPLY_BOOK_COMPANY_NAME,
        'X-Token: '.$_SESSION['simplybook_token']
    ));

    curl_setopt($curl_handle, CURLOPT_URL, $url);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($curl_handle);
    curl_close($curl_handle);

    echo $result; //returns all the bookings for some reason

Dmytro Bondarev wrote:

Here is example of http requests. Please try to run them and check.

POST https://user-api-v2.simplybook.me/admin/auth
Content-Type: application/json

{
  "company": "apitestsearch",
  "login": "admin",
  "password": "admin"
}

> {% client.global.set("token", response.body.token); %}

### Get single bookings by code

GET https://user-api-v2.simplybook.me/admin/bookings?filter[search]=1qdq8iis
Content-Type: application/json
X-Company-Login: apitestsearch
X-Token: {{ token }}

### Get all bookings

GET https://user-api-v2.simplybook.me/admin/bookings
Content-Type: application/json
X-Company-Login: apitestsearch
X-Token: {{ token }}

mike hk wrote:

Thank you, I was able to fetch the code booking information through the

"https://user-api-v2.simplybook.me/admin/bookings?filter[search]=mycode"

then was able to cancel the booking by passing the booking id “https://user-api-v2.simplybook.me/admin/bookings/id

$cancel_booking_url = 'https://user-api-v2.simplybook.me/admin/bookings/'.$booking_id;
curl_setopt($curl_handle, CURLOPT_URL, $cancel_booking_url);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
$cancel_result = curl_exec($curl_handle);
$cancel_final_result = json_decode($cancel_result);
curl_close($curl_handle);

now it all works fine but
one issue is that, when I pass a random booking id, which I tried with “12345”, it actually fetched some data which the booking id matched with one of my test client account having the phone number “12345”, how does it do that? How can I make sure the API only looks for booking with that particular id? it is supposed to return not found error instead of fetching any data that matches the code right?