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

Booking & Appointment REST API

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

  1. WooCommerce 3.5+
  2. WordPress 4.4+
  3. Booking & Appointment Plugin 5.10.0+
  4. WordPress Pretty Permalinks – must be enabled
  5. WooCommerce Consumer and Secret Keys – must be generated
  6. 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.

  1. POST: This method is used to create Booking data on an endpoint.
  2. GET: This method is used to retrieve/read Booking data on an endpoint.
  3. PUT: This method is used to update Booking data on an endpoint.
  4. 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.

  1. Bookings endpoint: <store-url>/wc-api/v3/bkap/bookings, supports GET, POST, PUT and DELETE methods
  2. Booking Resources endpoint: <store-url>/wc-api/v3/bkap/resources, supports GET and DELETE methods
  3. 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:

POST /woo_handel/wc-api/v3/bkap/bookings HTTP/1.1
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:

  1. WooCommerce API is enabled. To do this, go to WooCommerce -> Settings -> Advanced -> Rest API.
  2. Consumer keys and Consumer Secret keys have been created with Read/Write permissions.
  3. 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.

Booking & Appointment REST API - Tyche Softwares Documentation

 

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.

Booking & Appointment REST API - Tyche Softwares Documentation

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

GET/wc-api/v3/bkap/bookings
{
    "product_id": 68,
    "customer_id": 2,
    "limit": 10,
    "quantity": 1,
    "status": "paid"
}
Response
{
    “bookings”: [
        {
            “booking_id”: 301,
            “order_id”: 300,
            “order_item_id”: “147”,
            “booking_status”: “paid”,
            “customer_id”: “2”,
            “customer”: {
                “name”: “Mba Callista”,
                “email”: “mba.callista@gmail.com”,
                “user_id”: 2
            },
            “product_id”: “68”,
            “start_date”: “20210921090000”,
            “end_date”: “20210921100000”,
            “start_time”: “09:00 AM”,
            “end_time”: “10:00 AM”,
            “start_date_formatted”: “09/21/21”,
            “end_date_formatted”: “09/21/21”,
            “resource_id”: “”,
            “fixed_block”: “”,
            “cost”: “200”,
            “quantity”: “1”,
            “variation_id”: “0”,
            “duration”: “”,
            “duration_time”: “09:00”,
            “timezone”: “”,
            “timezone_offset”: “”,
            “zoom_meeting_url”: “”,
            “zoom_meeting_date”: “”
        },
        {
            “booking_id”: 299,
            “order_id”: 298,
            “order_item_id”: “146”,
            “booking_status”: “paid”,
            “customer_id”: “2”,
            “customer”: {
                “name”: “Mba Callista”,
                “email”: “mba.callista@gmail.com”,
                “user_id”: 2
            },
            “product_id”: “68”,
            “start_date”: “20210922090000”,
            “end_date”: “20210922100000”,
            “start_time”: “09:00 AM”,
            “end_time”: “10:00 AM”,
            “start_date_formatted”: “09/22/21”,
            “end_date_formatted”: “09/22/21”,
            “resource_id”: “”,
            “fixed_block”: “”,
            “cost”: “200”,
            “quantity”: “1”,
            “variation_id”: “0”,
            “duration”: “”,
            “duration_time”: “09:00”,
            “timezone”: “”,
            “timezone_offset”: “”,
            “zoom_meeting_url”: “”,
            “zoom_meeting_date”: “”
        }
    ],
    “count”: 2
}

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

GET/wc-api/v3/bkap/bookings/<BOOKING_ID>
Response
The same response is returned as in the case of List Bookings. The only difference in the response data is that while List Bookings request returns all Booking Information, List Booking Information for a Booking ID returns only the Booking information for the Booking ID that has been provided.

Count Bookings

Here, the total count or number of booking records available in the database are returned.

Request

GET/wc-api/v3/bkap/bookings/count
Response
{
    “count”: 2
}
Create Booking

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 Resource ID
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

POST/wc-api/v3/bkap/bookings

Single Day/Dates Booking Type

{
    "product_id": 273,
    "quantity": 1,
    "start_date": "2021-09-24",
    "end_date": "2021-09-24",
    "price": 150,
    "customer_id": 1
}

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
}
Response
{
    “created_booking_type”: “created_booking_in_new_order”,
    “booking_id”: 309,
    “order_id”: 308,
    “order_key”: “wc_order_G51dUoeE07OGK”,
    “order_number”: “308”,
    “date_created”: “2021-09-21T04:23:33Z”,
    “date_updated”: “2021-09-21T04:23:34Z”,
    “order_status”: “pending”,
    “booking_status”: “pending-confirmation”,
    “customer_id”: 2,
    “product_id”: 68,
    “start_date”: “20210922090000”,
    “end_date”: “20210922100000”,
    “start_date_formatted”: “09/22/21”,
    “end_date_formatted”: “09/22/21”,
    “currency”: “USD”,
    “total”: “200”,
    “subtotal”: “200”,
    “order_url”: “https://staging.tychesoftwares.com/woo_handel/my-account/view-order/308/”,
    “payment_url”: “https://staging.tychesoftwares.com/woo_handel/checkout/order-pay/308/?   pay_for_order=true&key=wc_order_G51dUoeE07OGK”,
    “start_time”: “09:00 AM”,
    “end_time”: “10:00 AM”,
    “cost”: “200”,
    “quantity”: “1”,
    “duration_time”: “09:00”
}

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

PUT/wc-api/v3/bkap/bookings/<BOOKING_ID>

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"
}
Response
{
    “booking_id”: 309,
    “start_date”: “2021-09-29”,
    “start_time”: “10:00”,
    “end_time”: “11:00”,
    “time_slot”: “10:00 – 11:00”,
    “quantity”: 2,
    “status”: “paid”,
    “price”: 400,
    “duration_time”: “10:00”,
    “end_date”: “20210929110000”,
    “start_date_formatted”: “09/29/21”,
    “end_date_formatted”: “09/29/21”,
    “cost”: “200”
}

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

DELETE/wc-api/v3/bkap/bookings/<BOOKING_ID>
Response
{
    “message”: “Booking has been deleted”
}

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

GET/wc-api/v3/bkap/resources
{
    "product_id": 68,
    "customer_id": 2,
    "limit": 10,
    "quantity": 1,
}
Response
{
    “resources”: [
        {
            “resource_id”: 312,
            “resource_title”: “Resource Label Pop Up”,
            “base_cost”: 0,
            “block_cost”: 0,
            “resource_quantity”: “8”,
            “resource_availability”: [
                {
                    “bookable”: “1”,
                    “type”: “custom”,
                    “priority”: 10,
                    “from”: “2021-03-20”,
                    “to”: “2021-11-20”
                },
                {
                    “bookable”: “0”,
                    “type”: “custom”,
                    “priority”: 10,
                    “from”: “”,
                    “to”: “”
                }
            ]
        }
    ],
    “count”: 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

GET/wc-api/v3/bkap/resources/<RESOURCE_ID>
Response
The same response is returned as in the case of List Booking Resources.

Count Booking Resources

Here, the total count or number of records for booking resources that are available in the database are returned.

Request

GET/wc-api/v3/bkap/resources/count
Response
{
    “count”: 4
}

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

DELETE/wc-api/v3/bkap/resources/<RESOURCE_ID>
Response
{
    “message”: “Resource has been deleted”
}

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

GET/wc-api/v3/bkap/products
{
    "booking_type": "only_day",
    "limit": 2,
    "price": 50,
}
Response
{
    “products”: [
        {
            “title”: “Amusement park”,
            “id”: 273,
            “created_at”: “2021-09-06T05:51:55Z”,
            “updated_at”: “2021-09-24T18:42:45Z”,
            “type”: “variable”,
            “status”: “publish”,
            “permalink”: “https://staging.tychesoftwares.com/woo_handel/product/amusement-park/”,
            “price”: “200”,
            “parent_id”: 0,
            “categories”: [
                “Uncategorized”
            ],
            “virtual”: false,
            “taxable”: false,
            “tax_status”: “taxable”,
            “booking_type”: “only_day”,
            “booking_calendar_type”: “inline”,
            “booking_requires_confirmation”: “no”,
            “booking_cancellation”: {
                “status”: “on”,
                “duration”: “1”,
                “period”: “day”
            },
            “booking_availability_weekday”: {
                “status”: “on”,
                “available_dates”: [
                    {
                        “day”: “sunday”,
                        “lockout”: 50
                    },
                    {
                        “day”: “monday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “tuesday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “wednesday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “thursday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “friday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “saturday”,
                        “lockout”: 0
                    }
                ]
            },
            “booking_availability_specific_date”: {
                “status”: “on”,
                “specific_dates”: [
                    {
                        “date”: “29-9-2021”,
                        “lockout”: 8
                    },
                    {
                        “date”: “28-9-2021”,
                        “lockout”: 8
                    },
                    {
                        “date”: “25-9-2021”,
                        “lockout”: 8
                    }
                ]
            },
            “booking_custom_range”: [
                {
                    “start”: “29-9-2021”,
                    “end”: “30-9-2021”,
                    “years_to_recur”: “”,
                    “range_type”: “”
                }
            ]
        },
        {
            “title”: “City Tour”,
            “id”: 128,
            “created_at”: “2021-08-16T04:41:13Z”,
            “updated_at”: “2021-08-16T04:46:55Z”,
            “type”: “simple”,
            “status”: “publish”,
            “permalink”: “https://staging.tychesoftwares.com/woo_handel/product/city-tour/”,
            “price”: “200”,
            “parent_id”: 0,
            “categories”: [
                “Uncategorized”
            ],
            “virtual”: false,
            “regular_price”: “200”,
            “taxable”: false,
            “tax_status”: “taxable”,
            “booking_type”: “multidates_fixedtime”,
            “booking_calendar_type”: “default”,
            “booking_requires_confirmation”: “no”,
            “booking_cancellation”: {
                “status”: “on”,
                “duration”: “”,
                “period”: “day”
            },
            “booking_availability_weekday”: {
                “status”: “on”,
                “available_dates”: [
                    {
                        “day”: “monday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “tuesday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “thursday”,
                        “lockout”: 0
                    }
                ]
            }
        }
    ],
    “count”: 2
}

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

GET/wc-api/v3/bkap/products/<PRODUCT_ID>
Response
The same response is returned as in the case of List Booking Products.

Count Booking Products

Here, the total count or number of booking products available in the database are returned.

Request

GET/wc-api/v3/bkap/products/count
Response
{
    “count”: 213
}

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

PUT/wc-api/v3/bkap/products/<PRODUCT_ID>

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”: sundaymondaytuesdaywednesdaythursdayfriday 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_datescustom_rangerange_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"
    }
}
Response
 {
            “title”: “Amusement Park”,
            “id”: 273,
            “created_at”: “2021-09-06T05:51:55Z”,
            “updated_at”: “2021-09-24T18:42:45Z”,
            “type”: “variable”,
            “status”: “publish”,
            “permalink”: “https://staging.tychesoftwares.com/woo_handel/product/amusement-park/”,
            “price”: “200”,
            “parent_id”: 0,
            “categories”: [
                “Uncategorized”
            ],
            “virtual”: false,
            “taxable”: false,
            “tax_status”: “taxable”,
            “booking_type”: “only_day”,
            “booking_calendar_type”: “inline”,
            “booking_requires_confirmation”: “no”,
            “booking_cancellation”: “off”,
            “booking_availability_weekday”: {
                “status”: “on”,
                “available_dates”: [
                    {
                        “day”: “sunday”,
                        “lockout”: 50
                    },
                    {
                        “day”: “monday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “tuesday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “wednesday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “thursday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “friday”,
                        “lockout”: 0
                    },
                    {
                        “day”: “saturday”,
                        “lockout”: 0
                    }
                ]
            },
            “booking_availability_specific_date”: {
                “status”: “on”,
                “specific_dates”: [
                    {
                        “date”: “29-9-2021”,
                        “lockout”: 8
                    },
                    {
                        “date”: “28-9-2021”,
                        “lockout”: 8
                    },
                    {
                        “date”: “25-9-2021”,
                        “lockout”: 8
                    }
                ]
            },
            “booking_custom_range”: [
                {
                    “start”: “29-9-2021”,
                    “end”: “30-9-2021”,
                    “years_to_recur”: “”,
                    “range_type”: “”
                }
            ]
        }

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

DELETE/wc-api/v3/bkap/products/<PRODUCT_ID>
Response
{
    “message”: “Product has been deleted”
}

Was this article helpful to you? Yes No

How can we help?