Contents
On this page

Update Opening Hours - Plugixa Car Parking

PUT /plugixa-car-parking/v1/locations/{id}/hours

Replace a location’s weekly opening hours. POST is accepted as well as PUT.

The user needs the plugixa_carparking_edit capability.

Note. This replaces the whole week. A weekday left out of hours loses its saved row, and the location is then open all day on that weekday. Sending "hours": [] removes every row: has_hours becomes false and the location takes bookings around the clock.

Request

PUT https://your-site.example/wp-json/plugixa-car-parking/v1/locations/4/hours

Path parameters

Name Type Description
id integer The location’s id

Request body

Content type: application/json

Field Type Required Description
hours object[] Yes One row per weekday.
hours[].day_of_week integer Yes 0 for Sunday to 6 for Saturday. A row with any other value is skipped. When two rows name the same day, the last wins.
hours[].open_time string No HH:MM or HH:MM:SS, 24-hour clock. Missing or in any other form, it becomes 09:00:00.
hours[].close_time string No Same form. Missing or in any other form, it becomes 18:00:00.
hours[].is_closed boolean No Closed all day. Defaults to false.

A time that is not valid is replaced with the default rather than refused, so check the times in the response.

{
  "hours": [
    {
      "day_of_week": 0,
      "open_time": "06:00",
      "close_time": "23:00",
      "is_closed": true
    },
    {
      "day_of_week": 1,
      "open_time": "06:00",
      "close_time": "23:00",
      "is_closed": false
    },
    {
      "day_of_week": 2,
      "open_time": "06:00",
      "close_time": "23:00",
      "is_closed": false
    },
    {
      "day_of_week": 3,
      "open_time": "06:00",
      "close_time": "23:00",
      "is_closed": false
    },
    {
      "day_of_week": 4,
      "open_time": "06:00",
      "close_time": "23:00",
      "is_closed": false
    },
    {
      "day_of_week": 5,
      "open_time": "06:00",
      "close_time": "23:00",
      "is_closed": false
    },
    {
      "day_of_week": 6,
      "open_time": "06:00",
      "close_time": "23:00",
      "is_closed": false
    }
  ]
}

Responses

200 OK. data is the saved week, as Opening Hours returns it.

{
  "success": true,
  "data": {
    "location_id": 4,
    "hours": [
      {
        "day_of_week": 0,
        "open_time": "06:00:00",
        "close_time": "23:00:00",
        "is_closed": true
      },
      {
        "day_of_week": 1,
        "open_time": "06:00:00",
        "close_time": "23:00:00",
        "is_closed": false
      },
      {
        "day_of_week": 2,
        "open_time": "06:00:00",
        "close_time": "23:00:00",
        "is_closed": false
      },
      {
        "day_of_week": 3,
        "open_time": "06:00:00",
        "close_time": "23:00:00",
        "is_closed": false
      },
      {
        "day_of_week": 4,
        "open_time": "06:00:00",
        "close_time": "23:00:00",
        "is_closed": false
      },
      {
        "day_of_week": 5,
        "open_time": "06:00:00",
        "close_time": "23:00:00",
        "is_closed": false
      },
      {
        "day_of_week": 6,
        "open_time": "06:00:00",
        "close_time": "23:00:00",
        "is_closed": false
      }
    ],
    "has_hours": true
  }
}
Field Type Meaning
data.location_id integer The location
data.hours object[] Always seven rows, one per weekday, Sunday first
data.hours[].day_of_week integer 0 for Sunday to 6 for Saturday
data.hours[].open_time string Opening time, HH:MM:SS
data.hours[].close_time string Closing time, HH:MM:SS
data.hours[].is_closed boolean Closed all day
data.has_hours boolean Whether any hours are saved for the location

Errors

Status Code When
404 plugixa_carparking_not_found No location with that id, or it is in the trash.
422 plugixa_carparking_invalid_hours hours is missing or is not a list.

Plus the errors every endpoint can return.

Examples

curl -s -X PUT "https://your-site.example/wp-json/plugixa-car-parking/v1/locations/4/hours" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"hours":[{"day_of_week":0,"open_time":"06:00","close_time":"23:00","is_closed":true},{"day_of_week":1,"open_time":"06:00","close_time":"23:00","is_closed":false},{"day_of_week":2,"open_time":"06:00","close_time":"23:00","is_closed":false},{"day_of_week":3,"open_time":"06:00","close_time":"23:00","is_closed":false},{"day_of_week":4,"open_time":"06:00","close_time":"23:00","is_closed":false},{"day_of_week":5,"open_time":"06:00","close_time":"23:00","is_closed":false},{"day_of_week":6,"open_time":"06:00","close_time":"23:00","is_closed":false}]}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-car-parking/v1/locations/4/hours');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'PUT',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD        => 'admin:' . getenv('WP_APP_PASSWORD'),
    CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS     => json_encode([
        'hours' => [
            [
                'day_of_week' => 0,
                'open_time'   => '06:00',
                'close_time'  => '23:00',
                'is_closed'   => true,
            ],
            [
                'day_of_week' => 1,
                'open_time'   => '06:00',
                'close_time'  => '23:00',
                'is_closed'   => false,
            ],
            [
                'day_of_week' => 2,
                'open_time'   => '06:00',
                'close_time'  => '23:00',
                'is_closed'   => false,
            ],
            [
                'day_of_week' => 3,
                'open_time'   => '06:00',
                'close_time'  => '23:00',
                'is_closed'   => false,
            ],
            [
                'day_of_week' => 4,
                'open_time'   => '06:00',
                'close_time'  => '23:00',
                'is_closed'   => false,
            ],
            [
                'day_of_week' => 5,
                'open_time'   => '06:00',
                'close_time'  => '23:00',
                'is_closed'   => false,
            ],
            [
                'day_of_week' => 6,
                'open_time'   => '06:00',
                'close_time'  => '23:00',
                'is_closed'   => false,
            ],
        ],
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-car-parking/v1/locations/4/hours', {
  method: 'PUT',
  headers: {
    'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    hours: [
      {
        day_of_week: 0,
        open_time: '06:00',
        close_time: '23:00',
        is_closed: true,
      },
      {
        day_of_week: 1,
        open_time: '06:00',
        close_time: '23:00',
        is_closed: false,
      },
      {
        day_of_week: 2,
        open_time: '06:00',
        close_time: '23:00',
        is_closed: false,
      },
      {
        day_of_week: 3,
        open_time: '06:00',
        close_time: '23:00',
        is_closed: false,
      },
      {
        day_of_week: 4,
        open_time: '06:00',
        close_time: '23:00',
        is_closed: false,
      },
      {
        day_of_week: 5,
        open_time: '06:00',
        close_time: '23:00',
        is_closed: false,
      },
      {
        day_of_week: 6,
        open_time: '06:00',
        close_time: '23:00',
        is_closed: false,
      },
    ],
  }),
});
const { data } = await response.json();

Quick Links

Share