1. Home
  2. Booking & Appointment Plugin for WooCommerce
  3. Booking API Endpoints

Booking API Endpoints

Introduction

Booking & Appointment Plugin for WooCommerce is fully integrated with the WordPress REST API. This allows Booking data to be read using requests in JSON format and using WordPress REST API Authentication methods and standard HTTP verbs which are understood by most HTTP clients.

API Documentation

Authentication

For authentication to succeed you must first ensure the REST API is enabled on the WooCommerce > Settings > Advanced >  page.

See the Rest API V2 Authentication article.

 

We have created Booking as a Custom Post Type of WordPress. All the Booking data are stored in the posts and postmeta table of WordPress with the post_type as bkap_booking. One can explore these tables OR the booking data can be seen at Booking-> View Bookings page. To get Booking ID information, check the ID column of posts table OR Booking ID column on Booking-> View Bookings page.

API Path

The API can be accessed as the route from the WordPress REST API. This should look something like this:

https://www.example.com/wp-json/wp/v2/bkap-bookings?consumer_key=[key]&consumer_secret=[secret]

For example, to obtain the Booking with ID 15, your request would be made to the following:

https://www.example.com/wp-json/wp/v2/bkap-bookings/15?consumer_key=[key]&consumer_secret=[secret]

Sending Requests

PHP

Following is the PHP code snippet that can be used to fetch all the Bookings Data of the Website via API.

$consumer_key    = 'your consumer key';
$consumer_secret = 'your consumer secret';

$url = rest_url( 'wp/v2/bkap-bookings/' );
// Adding Consumer Key and Consumer Secret to URL. 
$url = add_query_arg(
    array(
        'consumer_key'    => $consumer_key,
	'consumer_secret' => $consumer_secret
    ),
    $url
);

// Make the request to the API.
$response = wp_remote_get( $url, array( 'sslverify' => false ) );

// Check the response code.
if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ) {
	// If not a 200, HTTP request failed.
	die( 'There was an error attempting to access the API.' );
}

// Result is in the response body and is json encoded.
$bookings = json_decode( wp_remote_retrieve_body( $response ) );

In this example, the $bookings variable contains the response from the API request.

Endpoints

GET /bkap-bookings

Gets all bookings.

Path

https://www.example.com/wp-json/wp/v2/bkap-bookings/?consumer_key=[key]&consumer_secret=[secret]

Response [json]

The response will contain a JSON object which contains the booking details. An example can be found below:

Example Response

[
  {
    "ID": 16214,
    "post_author": "0",
    "post_date": "2021-06-07 08:09:39",
    "post_date_gmt": "2021-06-07 07:09:39",
    "post_content": "",
    "post_title": "Booking –",
    "post_excerpt": "",
    "post_status": "paid",
    "comment_status": "closed",
    "ping_status": "closed",
    "post_password": "",
    "post_name": "booking-5321",
    "to_ping": "",
    "pinged": "",
    "post_modified": "2021-06-07 08:09:59",
    "post_modified_gmt": "2021-06-07 07:09:59",
    "post_content_filtered": "",
    "post_parent": 16213,
    "guid": "https://localhost/rental/?bkap_booking=booking-5321",
    "menu_order": 0,
    "post_type": "bkap_booking",
    "post_mime_type": "",
    "comment_count": "0",
    "filter": "raw",
    "booking_post_meta": {
      "_bkap_order_item_id": [
        "9580"
      ],
      "_bkap_product_id": [
        "16199"
      ],
      "_bkap_resource_id": [
        ""
      ],
      "_bkap_fixed_block": [
        ""
      ],
      "_bkap_persons": [
        "a:0:{}"
      ],
      "_bkap_cost": [
        "150"
      ],
      "_bkap_start": [
        "20210625000000"
      ],
      "_bkap_end": [
        "20210625000000"
      ],
      "_bkap_all_day": [
        "1"
      ],
      "_bkap_parent_id": [
        "16213"
      ],
      "_bkap_customer_id": [
        "0"
      ],
      "_bkap_qty": [
        "1"
      ],
      "_bkap_variation_id": [
        "0"
      ],
      "_bkap_gcal_event_uid": [
        ""
      ],
      "_bkap_duration": [
        ""
      ],
      "_bkap_timezone_name": [
        ""
      ],
      "_bkap_timezone_offset": [
        ""
      ],
      "_bkap_vendor_id": [
        "1"
      ]
    }
  },
  {
    "ID": 16212,
    "post_author": "1",
    "post_date": "2021-06-04 21:09:37",
    "post_date_gmt": "2021-06-04 20:09:37",
    "post_content": "",
    "post_title": "Booking –",
    "post_excerpt": "",
    "post_status": "paid",
    "comment_status": "closed",
    "ping_status": "closed",
    "post_password": "",
    "post_name": "booking-5320",
    "to_ping": "",
    "pinged": "",
    "post_modified": "2021-06-04 21:09:52",
    "post_modified_gmt": "2021-06-04 20:09:52",
    "post_content_filtered": "",
    "post_parent": 16211,
    "guid": "https://localhost/rental/?bkap_booking=booking-5320",
    "menu_order": 0,
    "post_type": "bkap_booking",
    "post_mime_type": "",
    "comment_count": "0",
    "filter": "raw",
    "booking_post_meta": {
      "_bkap_order_item_id": [
        "9579"
      ],
      "_bkap_product_id": [
        "16208"
      ],
      "_bkap_resource_id": [
        ""
      ],
      "_bkap_fixed_block": [
        ""
      ],
      "_bkap_persons": [
        "a:0:{}"
      ],
      "_bkap_cost": [
        "1000"
      ],
      "_bkap_start": [
        "20210630000000"
      ],
      "_bkap_end": [
        "20210630000000"
      ],
      "_bkap_all_day": [
        "1"
      ],
      "_bkap_parent_id": [
        "16211"
      ],
      "_bkap_customer_id": [
        "1"
      ],
      "_bkap_qty": [
        "10"
      ],
      "_bkap_variation_id": [
        "16210"
      ],
      "_bkap_gcal_event_uid": [
        ""
      ],
      "_bkap_duration": [
        ""
      ],
      "_bkap_timezone_name": [
        ""
      ],
      "_bkap_timezone_offset": [
        ""
      ],
      "_bkap_vendor_id": [
        "1"
      ]
    }
  },
  {
    "ID": 16207,
    "post_author": "1",
    "post_date": "2021-06-04 20:41:47",
    "post_date_gmt": "2021-06-04 19:41:47",
    "post_content": "",
    "post_title": "Booking –",
    "post_excerpt": "",
    "post_status": "paid",
    "comment_status": "closed",
    "ping_status": "closed",
    "post_password": "",
    "post_name": "booking-5319",
    "to_ping": "",
    "pinged": "",
    "post_modified": "2021-06-04 20:42:01",
    "post_modified_gmt": "2021-06-04 19:42:01",
    "post_content_filtered": "",
    "post_parent": 16205,
    "guid": "https://localhost/rental/?bkap_booking=booking-5319",
    "menu_order": 0,
    "post_type": "bkap_booking",
    "post_mime_type": "",
    "comment_count": "0",
    "filter": "raw",
    "booking_post_meta": {
      "_bkap_order_item_id": [
        "9578"
      ],
      "_bkap_product_id": [
        "16199"
      ],
      "_bkap_resource_id": [
        ""
      ],
      "_bkap_fixed_block": [
        ""
      ],
      "_bkap_persons": [
        "a:0:{}"
      ],
      "_bkap_cost": [
        "150"
      ],
      "_bkap_start": [
        "20210629000000"
      ],
      "_bkap_end": [
        "20210629000000"
      ],
      "_bkap_all_day": [
        "1"
      ],
      "_bkap_parent_id": [
        "16205"
      ],
      "_bkap_customer_id": [
        "1"
      ],
      "_bkap_qty": [
        "2"
      ],
      "_bkap_variation_id": [
        "0"
      ],
      "_bkap_gcal_event_uid": [
        ""
      ],
      "_bkap_duration": [
        ""
      ],
      "_bkap_timezone_name": [
        ""
      ],
      "_bkap_timezone_offset": [
        ""
      ],
      "_bkap_vendor_id": [
        "1"
      ],
      "_edit_lock": [
        "1622836309:1"
      ]
    }
  }
]

Required Properties

There are no required properties.

Optional Properties

  • after – Date in YYYY-MM-DD format – List Bookings that is greater than the specified date
    e.g after=2021-05-30 : This will list all the bookings whose start date is greater than 2021-05-30
  • before – Date in YYYY-MM-DD format – List Booking that is less than the specified date
    e.g before=2021-06-30 : This will list all the bookings whose end date is less than 2021-06-30To fetch the bookings between date range 2021-04-01 to 2021-06-01 then query params should be as follows

    https://www.example.com/wp-json/wp/v2/bkap-bookings/?consumer_key=[key]&consumer_secret=[secret]&after=2021-04-01&before=2021-06-01
  • start_time – Time in H:i format – List Booking that is less than the specified start time
  • end_time – Time in H:i format – List Booking that is less than the specified end timeTo fetch the bookings between date range 2021-04-01 10:00 to 2021-06-01 22:00 then query params should be as follows
    https://www.example.com/wp-json/wp/v2/bkap-bookings/?consumer_key=[key]&consumer_secret=[secret]&after=2021-04-01&before=2021-06-01&start_time=10:00&end_time=22:00
  • product_id – Product ID ( Integer )
  • resource_id – Resource ID  ( Integer )
  • customer_id – Customer ID  ( Integer )
  • inclusive – Inclusive end time ( Boolean ) – Include Start & End date for fetching booking.
    e.g To fetch the bookings that falls between start date >= 2021-04-01 and end date <= 2021-06-01 then query params should be as follows

    https://www.example.com/wp-json/wp/v2/bkap-bookings/?consumer_key=[key]&consumer_secret=[secret]&after=2021-04-01&before=2021-06-01&inclusive=true

Sample Usage

Fetching booking that is placed for Product ID 16173 and having booking start time greater than 3rd June, 2021 09:30:00

https://www.example.com/wp-json/wp/v2/bkap-bookings/?consumer_key=[key]&consumer_secret=[secret]&product_id=16173&after=2021-06-03&start_time=09:30

 

Booking can be fetched based on the order id using the following route.

https://www.example.com/wp-json/wp/v2/bkap-bookings/order/16143?consumer_key=[key]&consumer_secret=[secret]
Was this article helpful to you? Yes No

How can we help?