Introduction
In our continuous effort to enhance the functionality and compatibility of the Booking & Appointment Plugin for WooCommerce, we have implemented significant updates to align with the latest WooCommerce REST API standards. This document outlines the changes, ensuring you can seamlessly transition and leverage the new capabilities.
Background
Previously, the Booking & Appointment Plugin for WooCommerce depended on the WooCommerce Legacy API. With the release of WooCommerce v9.0, the Legacy API has been deprecated. To ensure the plugin remains functional and future-proof, we have updated it to be fully compatible with the WooCommerce REST API.
Key Enhancements
1. Compatibility with WooCommerce REST API
We have updated the plugin to ensure full compatibility with the current WooCommerce REST API standards. This enhancement improves the plugin’s robustness, scalability, and performance, ensuring that your booking and appointment management integrates seamlessly with WooCommerce.
2. New Endpoints
New endpoints have been added to the plugin’s API, allowing for more comprehensive interactions and data management. These endpoints offer more flexibility and control over booking operations, enhancing the user experience for administrators and customers.
3. Backward Compatibility
We have retained the old endpoints from the WooCommerce Legacy API to support existing integrations and workflows. This means your current integrations will continue functioning without interruption, providing a smooth transition to the new API.
What to Expect in this Post
In this post, we will learn about the new endpoints added, how they enhance the functionality of the plugin, and how they are designed to align with the latest WooCommerce REST API standards (wc/v3). We will also cover detailed information on managing resources, products, and bookings through these endpoints.
Requirements
- WooCommerce 9.0+
- WordPress 5.0+
- Booking & Appointment Plugin 6.5.0+
- WordPress Pretty Permalinks – must be enabled
- WooCommerce Consumer and Secret Keys – must be generated
HTTP Methods
Several 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.
Namespace – `wc/v3`
The wc/v3
namespace is part of the WooCommerce REST API, which provides a more standardized and consistent interface for interacting with WooCommerce data. This namespace represents the third version of the API, reflecting the latest updates and improvements.
Base – `bkap`
The bkap
base in the Booking & Appointment Plugin for WooCommerce API is designed to facilitate the management of booking-related operations. This base is built on top of the WooCommerce REST API framework, ensuring seamless integration and compatibility with WooCommerce’s existing infrastructure.
The bkap base provides endpoints for various operations related to bookings, resources, and products, allowing developers to programmatically manage these aspects of their WooCommerce store. Below are detailed descriptions of the key endpoints available under the bkap base.
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: supports GET, POST, PUT and DELETE methods
Endpoint – <store-url>/wp-json/wc/v3/bkap/bookings - Resources: supports GET and DELETE methods
Endpoint – <store-url>/wp-json/wc/v3/bkap/resources - Products: supports GET, PUT, and DELETE methods
Endpoint – <store-url>/wp-json/wc/v3/bkap/products
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 and 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 for 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