Introduction
The 5.10.0 version of the Booking & Appointment Plugin for WooCommerce ( BKAP ) has introduced the REST API feature which allows Booking data to be created, read, updated and deleted.
The Booking & Appointment REST API has been implemented as an extension of the WooCommerce API, which makes the API inherit and implement all the security and structural advantages that the WooCommerce API has to offer.
Requirements
- WooCommerce 3.5+
- WordPress 4.4+
- Booking & Appointment Plugin 5.10.0+
- WordPress Pretty Permalinks – must be enabled
- WooCommerce Consumer and Secret Keys – must be generated
- Legacy REST API – must be enabled
Please read this tutorial for further information on setting up the above requirements. Technical documentation for the WooCommerce REST API can also be found here.
HTTP Methods
A number of HTTP methods or verbs have been used in the Booking & Appointment API.
- POST: This method is used to create Booking data on an endpoint.
- GET: This method is used to retrieve/read Booking data on an endpoint.
- PUT: This method is used to update Booking data on an endpoint.
- DELETE: This method is used to delete Booking data on an endpoint.
API Endpoints
There are three endpoints available in the Booking & Appointment API, with each endpoint providing the means through which external services can interact and carry out various functions.
- Bookings endpoint: <store-url>/wc-api/v3/bkap/bookings, supports GET, POST, PUT and DELETE methods
- Booking Resources endpoint: <store-url>/wc-api/v3/bkap/resources, supports GET and DELETE methods
- Booking Products: <store-url>/wc-api/v3/bkap/products, supports GET, PUT and DELETE methods
API Authentication
The following data are required for proper authentication:
- Consumer Key
- Consumer Secret
The authorization can be done based on base64 basic authorization, where the Consumer Key and Consumer Secret Key are concatenated and subsequently encoded.
Here is a sample request:
Host: staging.tychesoftwares.com
Authorization: Basic Y2tfYzhjZmQyNjc3M2IxMjhkZTg2NmNlZDBlOTExMjY1ZTE2MGI2MDI5Njpjc185M2E4ZGI4YzQ3YWRkNTkyNzQ5YzFlODI1NjYxYTcyMGI1M2Y5YjFi
Content-Type: application/json
Testing the API on Postman
Postman can be used to conduct some test runs on the API before production. Please install Postman via this download link: https://www.postman.com/downloads/
Make sure to confirm that the following have been done:
- WooCommerce API is enabled. To do this, go to WooCommerce -> Settings -> Advanced -> Rest API.
- Consumer keys and Consumer Secret keys have been created with Read/Write permissions.
- Legacy API for WooCommerce has been enabled.
Launch Postman set the Authorization Type to Basic Auth. Key in your Consumer and Secret Key in the Authorization tab. Key them in the Username and Password text boxes respectively. Please see the image below.
Request parameters for any of the endpoints in the Booking & Appointment API are usually sent in JSON format on the Postman app. To do this, go to the Body tab ( before Headers tab and after Pre-request Script tab), set the request as raw and select JSON as the format. Please see the image below.
Bookings API Endpoint
List Bookings
Here, all the bookings in the database are returned. Filters can also be used to limit the data returned.
Parameters
Parameter | Type | Description |
---|---|---|
product_id |
integer | Limit response data to bookings placed for a Product ID |
variation_id |
integer | Limit response data to bookings placed for a Variation ID |
customer_id |
integer | Limit response data to bookings placed by a Customer ( using the Customer ID ) |
resource_id |
integer | Limit response data to bookings placed for a Resource ID |
order_id |
integer | Limit response data to bookings attached to an Order ( using the Order ID ) |
quantity |
integer | Limit response data to bookings placed having a quantity greater than or equal to the quantity specified |
price |
float | Limit response data to bookings placed having a price greater than or equal to the price specified |
start_date |
string | Limit response data to bookings placed after a date. Dates provided must be in YYYY-MM-DD format |
end_date |
string | Limit response data to bookings placed before a date. If both start_date and end_date are specified, bookings are returned for that range. |
status |
string | Limit response data to bookings that have a particular booking status. Options: draft , cancelled , confirmed , paid , pending-confirmation |
limit |
integer | Limit the number of bookings returned in data. Bookings are sorted by date in descending order by default. |
fields |
array | Limit response data to contain only certain fields. Options: booking_id , order_id , order_item_id , booking_status , customer_id , customer , product_id , start_date , end_date , start_time , end_time , cost , quantity , variation_id , resource , zoom_meeting_url , zoom_meeting_date |
Request
{ "product_id": 68, "customer_id": 2, "limit": 10, "quantity": 1, "status": "paid" }
List Booking Information for a Booking ID
Here, Booking information for a particular Booking ID can be requested. The Booking ID has to be passed in the URL as shown in the Request below. Replace <BOOKING_ID> with the ID of the Booking.
Request
Count Bookings
Here, the total count or number of booking records available in the database are returned.
Request
This creates a new booking.
Parameters
Parameter | Type | Description |
---|---|---|
product_id |
integer | Product ID |
variation_id |
integer | Variation ID |
customer_id |
integer | Customer ID |
resource_id |
integer|array | Single Resource ID ( integer ) for Single Resource Type Products or an array of Resource IDs for Multiple Resource Type Booking Products. |
order_id |
integer | Order ID. Use this if the booking to be created needs to be attached to an existing order |
quantity |
integer | Quantity |
price |
float | Price |
start_date |
string | Start Date, in YYYY-MM-DD format |
end_date |
string | End Date, in YYYY-MM-DD format |
start_time |
string | Start Time, in H:i format |
end_time |
string | End Time, in H:i format |
fixed_block |
string | The Fixed Block for Days. This is for the Multiple Nights Booking Type. |
duration |
string | Duration ( in minutes ). This is for the Duration Booking Type. |
Request
Single Day/Dates Booking Type – Single Selection Resource Type
{ "product_id": 273, "quantity": 1, "start_date": "2021-09-24", "end_date": "2021-09-24", "price": 150, "customer_id": 1, "resource_id":10 }
Single Day/Dates Booking Type – Multiple Selection Resource Type
{ "product_id": 273, "quantity": 1, "start_date": "2021-09-24", "end_date": "2021-09-24", "price": 150, "customer_id": 1, "resource_id": [ 18, 22, 35 ] }
Multiple Nights Booking Type
{ "product_id": 273, "quantity": 1, "start_date": "2021-09-24", "end_date": "2021-09-24", "price": 150, "customer_id": 1, "fixed_block": 4 }
Fixed Time/ Dates & Time Booking Type
{ "product_id": 273, "quantity": 1, "start_date": "2021-09-24", "end_date": "2021-09-24", "start_time": "13:30", "end_time": "14:30", "price": 150, "customer_id": 1 }
Duration-based Booking Type
{ "product_id": 273, "quantity": 1, "start_date": "2021-09-24", "end_date": "2021-09-24", "price": 150, "customer_id": 1, "duration": 60 }
Multiple Dates Booking Type – Dates
{ "product_id": 273, "quantity": 1, "price": 150, "customer_id": 1, "dates": [ "2021-09-24", "2021-09-25" ] }
Multiple Dates Booking Type – Dates & Fixed Time
{ "product_id": 273, "quantity": 1, "price": 150, "customer_id": 1, "dates": [ { "start_time":"13:30", "end_time": "14:30", "date": "2021-09-23" }, { "start_time":"07:00", "end_time": "10:00", "date": "2021-09-24" } ] }
Update Booking
Here, Booking information for a particular Booking ID can be updated. The Booking ID has to be passed in the URL as shown in the Request below. Replace <BOOKING_ID> with the ID of the Booking.
Request
Request parameters are the same as that of Create Booking.
{ "quantity":2, "status":"paid", "price":400, "start_date": "2021-09-29", "start_time": "10:00", "end_time": "11:00" }
Delete Booking
This deletes an existing booking. The Booking ID has to be passed in the URL as shown in the Request below. Replace <BOOKING_ID> with the ID of the Booking.
Request
Booking Availability
Here, information about the availability of bookings for a bookable product can be queried – Product X has Y available bookings for Z date.
Request
To get available booking information for a range of days, use start_date and end_date.
Optional Parameters:
- variation_id: for a variable product.
- resource_id: for a resource.
- limit: limit response data.
{ "product_id":48, "start_date":"paid", "start_date": "2021-09-25", "end_date": "2021-09-29", }
Booking Price
Here, is information about getting the booking price based on the passed booking parameters.
Request
Pass the following parameters to get booking price information of the different booking types.
Single Day
{ "product_id": 68, "start_date": "2024-09-29", "quantity": 1 }
Multiple Nights
{ "product_id": 69, "start_date": "2024-09-29", "end_date": "2024-10-05", "quantity": 1 }
Fixed Time
{ "product_id": 70, "start_date": "2024-09-10", "start_time": "09:00", "end_time": "10:00", "quantity": 1 }
Duration Based Time
{ "product_id": 71, "start_date": "2024-09-15", "start_time": "09:00", "duration": 2, "quantity": 1 }
Response
{
"total_price_calculated": "1000.00",
"bkap_price_charged": "1000.00",
"bkap_price": "Total: 1,000.00 $"
}
Booking Resources API Endpoint
List Booking Resources
Here, all the booking resources in the database are returned. Filters can also be used to limit the data returned.
Parameters
Parameter | Type | Description |
---|---|---|
product_id |
integer | Limit response data to list all booking resources that have been assigned to a Product. |
customer_id |
integer | Limit response data to booking resources that have been paid for by a Customer ( using the Customer ID ) |
quantity |
integer | Limit response data to booking resources that have been paid for having a quantity greater than or equal to the quantity specified |
limit |
integer | Limit the number of booking resources returned in data. Booking resources are sorted by date in descending order by default. |
Request
{ "product_id": 68, "customer_id": 2, "limit": 10, "quantity": 1 }
List Booking Resources for a Resource ID
Here, Booking Resources information for a particular Resource ID can be requested. The Resource ID has to be passed in the URL as shown in the Request below. Replace <RESOURCE_ID> with the ID of the Resource.
Request
Count Booking Resources
Here, the total count or number of records for booking resources that are available in the database are returned.
Request
Delete Booking Resource
This deletes an existing booking resource. The Resource ID has to be passed in the URL as shown in the Request below. Replace <RESOURCE_ID> with the ID of the Booking resource.
Request
Booking Products API Endpoint
List Booking Products
Here, all the products that are bookable ( have bookings available for orders that are associated with them ) are returned. Filters can also be used to limit the data returned.
Parameters
Parameter | Type | Description |
---|---|---|
status |
string | Limit response data based on booking product status. Options: draft , published , pending |
limit |
integer | Limit the number of booking products returned in data. Booking products are sorted by date in descending order by default. |
booking_type |
array | Limit response data to certain booking types. Options: only_day , multiple_days , date_time , duration_time , multidates , multidates_fixedtime |
start_date |
string | Limit response data to contain booking products created after Start Date, in YYYY-MM-DD format |
end_date |
string | Limit response data to contain booking products created after End Date, in YYYY-MM-DD format |
price |
float | Limit response data to contain booking products that have prices greater than a specified price |
Request
{ "booking_type": "only_day", "limit": 2, "price": 50, }
List Booking Product for a Product ID
Here, Booking Product information for a particular Product ID can be requested. The Product ID has to be passed in the URL as shown in the Request below. Replace <BOOKING_ID> with the ID of the Product.
Request
Count Booking Products
Here, the total count or number of booking products available in the database are returned.
Request
Update Booking Product
Here, a Booking Product can be updated, with the Product ID passed in the URL as shown in the Request below. Replace <PRODUCT_ID> with the ID of the Product. An array of booking product options is passed as a booking
parameter in the request.
Request
Booking Product Parameters
Parameter | Type | Description |
---|---|---|
enable_booking |
string | Toggles Booking functionality. Options: on , off |
booking_type |
string | Updates the booking type. Options: only_day , multiple_days , date_time , duration_time , multidates , multidates_fixedtime |
booking_date_fixed_time_selection |
string | Selection Type for Multidates – Dates & Fixed Time Booking type. Options: fixed or range |
booking_date_fixed_time_number_dates |
integer | Number of dates for Multidates – Dates & Fixed Time Booking type |
booking_date_fixed_time_min_dates |
string | Minimum number of Dates for Range-based Selection for Multidates – Dates & Fixed Time Booking type. |
booking_date_fixed_time_max_dates |
string | Maximum number of Dates for Range-based Selection for Multidates – Dates & Fixed Time Booking type. |
enable_inline_calendar |
string | Toggle visibility of Inline Calendar. Options: on or off |
purchase_without_date |
string | Purchase booking without choosing a date. Options: on or off |
booking_requires_confirmation |
string | Bookings placed must require confirmation by the Admin. Options: on or off |
booking_can_be_cancelled |
string | Whether Bookings have cancellation property. Options: on or off |
booking_can_be_cancelled_duration |
integer | Duration for bookings to be cancelled if Bookings have cancellation property. |
booking_can_be_cancelled_period |
string | Period for cancellation property for Bookings. Options: day , hour , minute |
booking_advance_period |
integer | Advanced Booking Period ( in hours ) |
booking_maximum_dates |
integer | Number of dates to choose |
booking_maximum_bookings_on_date |
integer | For Multiple Nights Booking Type – Maximum Bookings on any Date |
booking_minimum_number_nights_book |
integer | For Multiple Nights Booking Type – Minimum number of nights to book |
booking_maximum_number_nights_book |
integer | For Multiple Nights Booking Type – Maximum number of nights to book |
availability_weekday |
array | An array of values for setting the availability of bookings.
[
“weekday”:
sunday , monday , tuesday , wednesday , thursday , friday or saturday , “status”:
on or off , “lockout”: 0,
“price”: 0,
]
|
availability_dates_months |
array | An array of date ranges for availability for Specific Date, Range of Months, Holidays, Custom Range. Months are formatted in lowercase and dates in the YYYY-MM-DD format.
[
“type”:
specific_dates , custom_range , range_months or holidays , “date”: [
“2021-09-05”,
“2021-10-03”,
“2021-11.11”
],
“lockout”: 0,
“price”: 0,
“date_from”: “2021-03-01”,
“date_to”: “2021-05-04”,
“maximum_booking”: 0,
“month_from”: “january”,
“month_to”: “march”,
]
|
Request parameters are the same as that of Create Booking.
{ "booking": { "enable_booking": "on", "booking_type": "only_day", "enable_inline_calendar": "on", "booking_can_be_cancelled": "off" } }
Delete Booking Product
This deletes an existing booking product. The Product ID has to be passed in the URL as shown in the Request below. Replace <PRODUCT_ID> with the ID of the Product.
Request