Skip to content

Table booking

Request Summary

URL: https://personalkollen.se/api/v1/table-booking/
Method: POST
Authentication: HTTP Authorization header with authentication secret
Content-Type: application/json

Introduction

This API is used to update table booking information in Personalkollen.

Use the API by posting a list of bookings and the time period that should be updated. The API first clears the period of current bookings and then add the new ones.

Data structure

This section describes the data that should be passed to the table booking API. Below is an example of how the request could look like with headers and body provided.

Request Example

The API only accept POST requests with the content type JSON.

Headers

POST https://personalkollen.se/api/v1/table-booking/ HTTP/1.1
Authorization: Token {secret_token}
Content-Type: application/json

Body

{
    "period": {
        "start": "2022-04-06T17:00:00Z",
        "end": "2022-04-19T17:00:00Z"
    },
    "bookings": [
        {
            "guests": 5,
            "date_and_start_hour": "2022-04-06T17:00:00Z"
        },
        {
            "guests": 10,
            "date_and_start_hour": "2022-04-10T18:00:00Z"
        },
        {
            "guests": 22,
            "date_and_start_hour": "2022-04-16T17:00:00Z"
        }
    ]
}

Body parameters & data types

Required Field name Data type Description
Yes period Period The affected time period that will be updated.
Yes bookings Bookings The list of booking objects. Required but can be left empty.

Period

Required Field name Data type Description
Yes start DateTime start date time
Yes end DateTime end date time

Bookings

Zero or more objects with the following fields.

Required Field name Data type Description
Yes guests Integer Number of new guests for the hour
Yes date_and_start_hour DateTime Timestamp Start time. Must have whole hours

Warning

All table bookings must be within the given time period and have an unique date_and_start_hour

DateTime

Represented as an ISO 8601 string in UTC.

Info

Every DateTime field in this API must be sent in whole hours e.g 2022-04-16T17:00:00Z

Integer

Represents an integer with no decimals allowed.

HTTP requests and responses

204 NO CONTENT

The request was successfully processed. No content is returned.

401 PERMISSION DENIED

{
    "message": "Invalid token.",
    "code": "authentication_failed"
}

400 BAD REQUEST

Invalid format, data types, or data values not passing the validation rules.

Bad Request Examples

Period end is before start
{
    "period": { "start": "2022-05-06T19:00:00Z", "end": "2022-04-09T17:00:00Z" },
    "bookings": [
        { "date_and_start_hour": "2022-04-06T17:00:00Z", "guests": 11 },
        { "date_and_start_hour": "2022-04-07T17:00:00Z", "guests": 22 }
    ]
}
{
    "period": {
        "non_field_errors": [
            {
                "message": "period end must occur after start",
                "code": "invalid"
            }
        ]
    }
}
Time not in whole hours
{
    "period": { "start": "2022-04-06T19:00:00Z", "end": "2022-04-09T17:00:00Z" },
    "bookings": [
        { "date_and_start_hour": "2022-04-06T17:00:00Z", "guests": 11 },
        { "date_and_start_hour": "2022-04-07T17:30:00Z", "guests": 22 }
    ]
}
{
    "bookings": {
        "0": {
            "date_and_start_hour": [
                {
                    "message": "invalid time '19:30:00'. only full hours are allowed",
                    "code": "invalid"
                }
            ]
        }
    }
}
Booking outside time period
{
    "period": { "start": "2022-04-06T19:00:00Z", "end": "2022-04-09T17:00:00Z" },
    "bookings": [
        { "date_and_start_hour": "2022-04-06T17:00:00Z", "guests": 11 },
        { "date_and_start_hour": "2022-05-08T18:00:00Z", "guests": 68 }
    ]
}
{
    "non_field_errors": [
        {
            "message": "booking '2022-04-06 19:00:00+02:00' must be within given time period '2022-04-06 21:00:00+02:00 - 2022-04-09 19:00:00+02:00'",
            "code": "invalid"
        }
    ]
}
Bookings with the same date and start hour
 
{
    "period": {
        "start": "2022-03-08T04:00:00.000Z",
        "end": "2022-03-09T04:00:00.000Z"
    },
    "bookings": [
        {
            "guests": 4,
            "date_and_start_hour": "2022-03-08T18:00:00.000Z"
        },
        {
            "guests": 8,
            "date_and_start_hour": "2022-03-08T18:00:00.000Z"
        }
    ]
}
{
    "bookings": [
        {
            "message": "booking '2022-03-08 19:00:00+01:00' occurs more than once. Date and start hour must be unique",
            "code": "invalid"
        }
    ]
}

405 Method not allowed

Response code 405 indicates either the request method is wrong or something has caused the request to redirect and then getting the wrong request method.

Make sure that the request method is POST, and that the url has https not http and that it has a trailing slash.

https://personalkollen.se/api/v1/table-booking/