<commit_before>---
layout: page
categories: ["API"]
title: Bookings
---

# Bookings

All API requests to `https://api.parku.ch/v4/bookings` need a __private key__.

## Create a new booking

```sh
$ curl {{ site.parku.api }}/bookings \
    -u 098f6bcd4621d373cade4e832627b4f6:parku \
    -d location_id=00cd7cfd-e42d-11e2-8bf1-8a83f3373875 \
    --data-urlencode license_plate="B-AB 1234" \
    --data-urlencode phone_number="+493057701873" \
    --data-urlencode date_start="{{ site.time | date: '%Y-%m-%d' }}T10:00:00{{ site.time | date: '%z' }}" \
    --data-urlencode date_end="{{ site.time | date: '%Y-%m-%d' }}T16:30:00{{ site.time | date: '%z' }}" \
    -d provider=paypal \
    --data-urlencode 'provider_info={
  "client": {
    "environment": "sandbox",
    "paypal_sdk_version": "2.0.1",
    "platform": "iOS",
    "product_name": "PayPal iOS SDK"
  },
  "response": {
    "create_time": "2014-03-31T12:51:14Z",
    "id": "PAY-1CM399047K4649003KM4WJQQ",
    "intent": "authorize",
    "state": "approved"
  },
  "response_type": "payment"
}'
```

> Response

```nginx
Status: 201 Created
Location: {{ site.parku.api }}/bookings/005c4826-4e28-11e3-a675-d43d7eece53d
```

```json
{
  "id": "005c4826-4e28-11e3-a675-d43d7eece53d",
  "license_plate": "B-AB 1234",
  "phone_number": "+493057701872",
  "location": {
    "id": "00cd7cfd-e42d-11e2-8bf1-8a83f3373875",
    "code": "ZHRTHW",
    "latitude": 47.365398,
    "longitude": 8.51987,
    "street": "Hopfenstrasse",
    "street_number": "20",
    "postcode": "8045",
    "city": "Zürich",
    "country": "CH",
    "description": "Doppelparkplatz. Jedoch nur für ein Auto zu vermieten. Die andere Hälfte wird benötigt. Aufteilung wie im Bild.",
    "image_urls": [
      "http://parku.ch/parkingspace/00cd7cfd-e42d-11e2-8bf1-8a83f3373875/image",
      "http://parku.ch/parkingspace/00cd7cfd-e42d-11e2-8bf1-8a83f3373875/image"
    ],
    "options": [],
    "notifications": [],
    "currency": "CHF",
    "support": {
      "phone_number": "+41 43 928 72 52"
    }
  },
  "reference": "HRS5J",
  "date_start": "{{ site.time | date: '%Y-%m-%d' }}T10:00:00{{ site.time | date: '%z' }}",
  "date_end": "{{ site.time | date: '%Y-%m-%d' }}T16:30:00{{ site.time | date: '%z' }}",
  "price": 13.75,
  "currency": "CHF",
  "violation": null
}
```

### HTTP Request

`POST {{ site.parku.api }}/bookings`

### Parameters

Parameter      | Description
---            | ---
`location_id`  | The ID of the location you get returned from the [`locations`][locations] request. __Required.__
`date_start`   | [ISO 8601][iso-8601] format: `{{ site.time | date_to_xmlschema }}`.  __Required.__
`date_end`     | [ISO 8601][iso-8601] format: `{{ site.time | date_to_xmlschema }}`.  __Required.__
`license_plate`| The license_plate of the used car. Get all cars of a user from the [`cars`][cars] request. __Required.__
`phone_number` | The phone number. Get all phone numbers of a user from the [`phone_numbers`][phone_numbers] request. __Required.__
`provider`     | The payment method. Available options are _paypal_, _braintree_ or _credit_. __Required.__
`provider_info`| The information of the payment provider to perform a payment. __Required__ for payment methods _paypal_ and _braintree_.


## Retrieve a booking

```sh
$ curl {{ site.parku.api }}/bookings/005c4826-4e28-11e3-a675-d43d7eece53d \
    -u 098f6bcd4621d373cade4e832627b4f6:parku
```

> Response

```nginx
Status: 200 OK
```
```json
{
  "id": "005c4826-4e28-11e3-a675-d43d7eece53d",
  "license_plate": "B-AB 1234",
  "phone_number": "+493057701872",
  "location": {
    "id": "00cd7cfd-e42d-11e2-8bf1-8a83f3373875",
    "code": "ZHRTHW",
    "latitude": 47.365398,
    "longitude": 8.51987,
    "street": "Hopfenstrasse",
    "street_number": "20",
    "postcode": "8045",
    "city": "Zürich",
    "country": "CH",
    "description": "Doppelparkplatz. Jedoch nur für ein Auto zu vermieten. Die andere Hälfte wird benötigt. Aufteilung wie im Bild.",
    "image_urls": [
      "http://parku.ch/parkingspace/00cd7cfd-e42d-11e2-8bf1-8a83f3373875/image",
      "http://parku.ch/parkingspace/00cd7cfd-e42d-11e2-8bf1-8a83f3373875/image"
    ],
    "options": [],
    "notifications": [],
    "currency": "CHF",
    "support": {
      "phone_number": "+41 43 928 72 52"
    }
  },
  "reference": "HRS5J",
  "date_start": "{{ site.time | date: '%Y-%m-%d' }}T10:00:00{{ site.time | date: '%z' }}",
  "date_end": "{{ site.time | date: '%Y-%m-%d' }}T16:30:00{{ site.time | date: '%z' }}",
  "price": 13.75,
  "currency": "CHF",
  "violation": {
    "license_plate": "B-DC 4321",
    "comment": "This car parked on my parking space!!!",
    "image_url": "{{ site.parku.url }}/images/reports/12.jpeg"
  }
}
```

Retrieves the details of an existing booking. You need only supply the unique booking identifier that was returned upon booking creation.

### HTTP Request

`GET {{ site.parku.api }}/bookings/:booking_id`

### Parameters

Parameter      | Description
---            | ---
`booking_id`   | The identifier of the booking to be retrieved. __Required.__


## Update a booking

TBD

## Cancel a booking

```sh
$ curl {{ site.parku.api }}/bookings/005c4826-4e28-11e3-a675-d43d7eece53d \
    -u 098f6bcd4621d373cade4e832627b4f6:parku
    -X DELETE
```

> Response

```nginx
Status: 204 No Content
```

Permanently cancels a booking. It cannot be undone.

### HTTP Request

`DELETE {{ site.parku.api }}/bookings/:booking_id`

### Parameters
<commit_msg>Add backslash.<commit_after>---
layout: page
categories: ["API"]
title: Bookings
---

# Bookings

All API requests to `https://api.parku.ch/v4/bookings` need a __private key__.

## Create a new booking

```sh
$ curl {{ site.parku.api }}/bookings \
    -u 098f6bcd4621d373cade4e832627b4f6:parku \
    -d location_id=00cd7cfd-e42d-11e2-8bf1-8a83f3373875 \
    --data-urlencode license_plate="B-AB 1234" \
    --data-urlencode phone_number="+493057701873" \
    --data-urlencode date_start="{{ site.time | date: '%Y-%m-%d' }}T10:00:00{{ site.time | date: '%z' }}" \
    --data-urlencode date_end="{{ site.time | date: '%Y-%m-%d' }}T16:30:00{{ site.time | date: '%z' }}" \
    -d provider=paypal \
    --data-urlencode 'provider_info={
  "client": {
    "environment": "sandbox",
    "paypal_sdk_version": "2.0.1",
    "platform": "iOS",
    "product_name": "PayPal iOS SDK"
  },
  "response": {
    "create_time": "2014-03-31T12:51:14Z",
    "id": "PAY-1CM399047K4649003KM4WJQQ",
    "intent": "authorize",
    "state": "approved"
  },
  "response_type": "payment"
}'
```

> Response

```nginx
Status: 201 Created
Location: {{ site.parku.api }}/bookings/005c4826-4e28-11e3-a675-d43d7eece53d
```

```json
{
  "id": "005c4826-4e28-11e3-a675-d43d7eece53d",
  "license_plate": "B-AB 1234",
  "phone_number": "+493057701872",
  "location": {
    "id": "00cd7cfd-e42d-11e2-8bf1-8a83f3373875",
    "code": "ZHRTHW",
    "latitude": 47.365398,
    "longitude": 8.51987,
    "street": "Hopfenstrasse",
    "street_number": "20",
    "postcode": "8045",
    "city": "Zürich",
    "country": "CH",
    "description": "Doppelparkplatz. Jedoch nur für ein Auto zu vermieten. Die andere Hälfte wird benötigt. Aufteilung wie im Bild.",
    "image_urls": [
      "http://parku.ch/parkingspace/00cd7cfd-e42d-11e2-8bf1-8a83f3373875/image",
      "http://parku.ch/parkingspace/00cd7cfd-e42d-11e2-8bf1-8a83f3373875/image"
    ],
    "options": [],
    "notifications": [],
    "currency": "CHF",
    "support": {
      "phone_number": "+41 43 928 72 52"
    }
  },
  "reference": "HRS5J",
  "date_start": "{{ site.time | date: '%Y-%m-%d' }}T10:00:00{{ site.time | date: '%z' }}",
  "date_end": "{{ site.time | date: '%Y-%m-%d' }}T16:30:00{{ site.time | date: '%z' }}",
  "price": 13.75,
  "currency": "CHF",
  "violation": null
}
```

### HTTP Request

`POST {{ site.parku.api }}/bookings`

### Parameters

Parameter      | Description
---            | ---
`location_id`  | The ID of the location you get returned from the [`locations`][locations] request. __Required.__
`date_start`   | [ISO 8601][iso-8601] format: `{{ site.time | date_to_xmlschema }}`.  __Required.__
`date_end`     | [ISO 8601][iso-8601] format: `{{ site.time | date_to_xmlschema }}`.  __Required.__
`license_plate`| The license_plate of the used car. Get all cars of a user from the [`cars`][cars] request. __Required.__
`phone_number` | The phone number. Get all phone numbers of a user from the [`phone_numbers`][phone_numbers] request. __Required.__
`provider`     | The payment method. Available options are _paypal_, _braintree_ or _credit_. __Required.__
`provider_info`| The information of the payment provider to perform a payment. __Required__ for payment methods _paypal_ and _braintree_.


## Retrieve a booking

```sh
$ curl {{ site.parku.api }}/bookings/005c4826-4e28-11e3-a675-d43d7eece53d \
    -u 098f6bcd4621d373cade4e832627b4f6:parku
```

> Response

```nginx
Status: 200 OK
```
```json
{
  "id": "005c4826-4e28-11e3-a675-d43d7eece53d",
  "license_plate": "B-AB 1234",
  "phone_number": "+493057701872",
  "location": {
    "id": "00cd7cfd-e42d-11e2-8bf1-8a83f3373875",
    "code": "ZHRTHW",
    "latitude": 47.365398,
    "longitude": 8.51987,
    "street": "Hopfenstrasse",
    "street_number": "20",
    "postcode": "8045",
    "city": "Zürich",
    "country": "CH",
    "description": "Doppelparkplatz. Jedoch nur für ein Auto zu vermieten. Die andere Hälfte wird benötigt. Aufteilung wie im Bild.",
    "image_urls": [
      "http://parku.ch/parkingspace/00cd7cfd-e42d-11e2-8bf1-8a83f3373875/image",
      "http://parku.ch/parkingspace/00cd7cfd-e42d-11e2-8bf1-8a83f3373875/image"
    ],
    "options": [],
    "notifications": [],
    "currency": "CHF",
    "support": {
      "phone_number": "+41 43 928 72 52"
    }
  },
  "reference": "HRS5J",
  "date_start": "{{ site.time | date: '%Y-%m-%d' }}T10:00:00{{ site.time | date: '%z' }}",
  "date_end": "{{ site.time | date: '%Y-%m-%d' }}T16:30:00{{ site.time | date: '%z' }}",
  "price": 13.75,
  "currency": "CHF",
  "violation": {
    "license_plate": "B-DC 4321",
    "comment": "This car parked on my parking space!!!",
    "image_url": "{{ site.parku.url }}/images/reports/12.jpeg"
  }
}
```

Retrieves the details of an existing booking. You need only supply the unique booking identifier that was returned upon booking creation.

### HTTP Request

`GET {{ site.parku.api }}/bookings/:booking_id`

### Parameters

Parameter      | Description
---            | ---
`booking_id`   | The identifier of the booking to be retrieved. __Required.__


## Update a booking

TBD

## Cancel a booking

```sh
$ curl {{ site.parku.api }}/bookings/005c4826-4e28-11e3-a675-d43d7eece53d \
    -u 098f6bcd4621d373cade4e832627b4f6:parku \
    -X DELETE
```

> Response

```nginx
Status: 204 No Content
```

Permanently cancels a booking. It cannot be undone.

### HTTP Request

`DELETE {{ site.parku.api }}/bookings/:booking_id`

### Parameters

{'fraction_non_alphanumeric': 0.1830017420005501, 'fraction_numerical': 0.0962684514531952, 'mean_word_length': 3.5544885177453027, 'pattern_counts': {'":': 132, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4068647', 'n_tokens_mistral': 4936, 'n_tokens_neox': 4323, 'n_words': 909}