How to Use the Delivery Slots REST API

REST API is an interface that provides a secure way for developers to read and modify the data of your WordPress website from outside of your website.

You can use the Delivery Slots REST API in 2 ways:

  1. When you are building your own custom mobile or web app.
  2. When your want your website’s order information to be available to a third party – say your logistics partner.

In these cases, you might need a REST API to fetch bookable dates/timeslots and also to access the booked dates/timeslots for the orders.

Get bookable dates and timeslots

This might be needed to fetch the bookable dates and timeslot information when you are building your own custom mobile or web app. You would want this info to be available when the customer is placing an order on your app.

Delivery Slots adds 2 REST API endpoints for this purpose, these would allow you to fetch all available bookable dates and timeslots for each data.

GET /iconic_wds/v1/get_bookable_dates/

It returns all the available bookable dates, grouped by shipping methods. 

Parameters: This endpoint doesn’t accept parameters.

Example URL: https://site.com/wp-json/iconic_wds/v1/get_bookable_dates

Sample Response:

{
   "success":true,
   "shipping_methods":{
      "free_shipping:2":"Free shipping",
      "flat_rate:7":"Flat rate - Express",
      "local_pickup:8":"Local pickup",
   },
   "dates":{
      "free_shipping:2":[
         {
            "formatted":"Fri, 4th Mar",
            "header_formatted":"Mar 4",
            "admin_formatted":"04\/03\/2022",
            "timestamp":1646409206,
            "ymd":"20220304",
            "weekday_number":"5",
            "weekday":"Fri",
            "same_day":false,
            "next_day":false
         },
         {
            "formatted":"Sat, 5th Mar",
            "header_formatted":"Mar 5",
            "admin_formatted":"05\/03\/2022",
            "timestamp":1646495606,
            "ymd":"20220305",
            "weekday_number":"6",
            "weekday":"Sat",
            "same_day":false,
            "next_day":false
		},
   }
   "flat_rate:7":[
         {
            "formatted":"Fri, 4th Mar",
            "header_formatted":"Mar 4",
            "admin_formatted":"04\/03\/2022",
            "timestamp":1646409206,
            "ymd":"20220304",
            "weekday_number":"5",
            "weekday":"Fri",
            "same_day":false,
            "next_day":false
         },
         {
            "formatted":"Sat, 5th Mar",
            "header_formatted":"Mar 5",
            "admin_formatted":"05\/03\/2022",
            "timestamp":1646495606,
            "ymd":"20220305",
            "weekday_number":"6",
            "weekday":"Sat",
            "same_day":false,
            "next_day":false
		}
	}
}

GET /iconic_wds/v1/get_slots_on_date/

This returns available timeslots for the given date and shipping method. You need to pass the date and shipping method as GET parameter.

Parameters: 

  • date – Date in Ymd format. For example, 20th March 2022 would be 20220320
  • Shipping_method – The id of shipping method. Example flat_rate:7

Example URL: https://site.com/wp-json/iconic_wds/v1/get_slots_on_date

Sample Response:

{
   "success":true,
   "data":{
      "timeslot":[
         {
            "row_id":"24ji4kqmype",
            "duration":"",
            "frequency":"60",
            "timefrom":{
               "time":"18:00",
               "stripped":"1800"
            },
            "timeto":{
               "time":"19:00",
               "stripped":"1900"
            },
            "cutoff":"",
            "lockout":"",
            "shipping_methods":[
               "any",
               "free_shipping:2",
               "flat_rate:7"
            ],
            "fee":{
               "value":"",
               "formatted":"<span class=\"woocommerce-Price-amount amount\"><bdi><span class=\"woocommerce-Price-currencySymbol\">$<\/span>0.00<\/bdi><\/span>"
            },
            "days":[
               "1",
               "5",
               "6"
            ],
            "id":"24ji4kqmype\/0",
            "time_id":"18001900",
            "formatted":"18:00 PM - 19:00 PM",
            "formatted_with_fee":"18:00 PM - 19:00 PM",
            "value":"24ji4kqmype\/0|0.00",
            "slot_id":"20220304_24ji4kqmype\/0",
            "slots_available_count":1
         },
         {
            "row_id":"24ji4kqmype",
            "duration":"",
            "frequency":"60",
            "timefrom":{
               "time":"19:00",
               "stripped":"1900"
            },
            "timeto":{
               "time":"20:00",
               "stripped":"2000"
            },
            "cutoff":"",
            "lockout":"",
            "shipping_methods":[
               "any",
               "free_shipping:2",
               "flat_rate:7"
            ],
            "fee":{
               "value":"",
               "formatted":"<span class=\"woocommerce-Price-amount amount\"><bdi><span class=\"woocommerce-Price-currencySymbol\">$<\/span>0.00<\/bdi><\/span>"
            },
            "days":[
               "1",
               "5",
               "6"
            ],
            "id":"24ji4kqmype\/1",
            "time_id":"19002000",
            "formatted":"19:00 PM - 20:00 PM",
            "formatted_with_fee":"19:00 PM - 20:00 PM",
            "value":"24ji4kqmype\/1|0.00",
            "slot_id":"20220304_24ji4kqmype\/1",
            "slots_available_count":1
         },
      ]
   }
}

How to get the date and timeslot of an order

WooCommerce already provides a REST API endpoint to fetch the data for an order.

https://woocommerce.github.io/woocommerce-rest-api-docs/?php#retrieve-an-order

When you fetch an order’s data using this endpoint, WooCommerce Delivery Slots would automatically add the booked date and timeslot to the order response.

The delivery slot information is added to the iconic_delivery_meta object key in the JSON response.

{
   "id":3031,
   "parent_id":0,
   "status":"processing",
   "currency":"ANG",
   "version":"4.2.0",
   "prices_include_tax":false,
   "date_created":"2020-06-25T17:53:35",
   "date_modified":"2020-06-25T17:53:35",
   "discount_total":"0.00",
   "discount_tax":"0.00",
   "shipping_total":"40.00",
   "shipping_tax":"0.00",
   "cart_tax":"0.00",
   "total":"251.00",
   "total_tax":"0.00",
   {...}
   "iconic_delivery_meta":{
      "date":"25 June 2020",
      "timeslot":"04:15 PM - 04:30 PM",
      "timestamp":"1593081900"
   },
   {...}
}

Make delivery slots REST API public

By default, the endpoints added by delivery slots are protected, so it requires you to authenticate the request as specified by WordPress in the REST API Authentication document. However, if want to make the REST API public, you can do that with this code snippet:

add_filter(
	'iconic_wds_rest_api_permission_callback',
	function() {
		return '__return_true';
	}
);

WooCommerce Delivery Slots

Choose a delivery date and time for each order. Add a limit to the number of allowed reservations, restrict time slots to specific delivery methods, and so much more.

Was this helpful?

Please let us know if this article was useful. It is the best way to ensure our documentation is as helpful as possible.