Contents
On this page

Update Space Type Prices - Plugixa Car Parking

PUT /plugixa-car-parking/v1/space-types/{id}/prices

Replace a space type’s whole price list in one go.

The signed-in user needs the plugixa_carparking_edit capability (change records).

Note. This is a full replace. Every stored price row of the space type is deleted and the rows you send are written in their place, so a unit or location left out of the list loses its price. Read the list first with Space Type Prices and send it back with your change. An empty prices list removes every price.

The rows are checked first and saved together: if one row is refused, nothing changes.

Request

PUT https://your-site.example/wp-json/plugixa-car-parking/v1/space-types/2/prices

Path parameters

Name Type Description
id integer The space type’s id

Request body

Content type: application/json

Field Type Required Description
prices array Yes The price rows.
prices[].use_type string Yes initial, rental_minute, rental_hour, rental_day, rental_week or rental_month.
prices[].amount number Yes Not negative. A number or a numeric string, with a dot for decimals.
prices[].location_id integer No An existing location (a trashed one is accepted) to make this row apply there only. Empty, 0 or null means every location.
prices[].currency string No At most 10 characters. Stored and returned, not used in the price calculation.

Each unit can have one price per location: two rows with the same use_type and the same location_id (or both site-wide) are refused.

{
  "prices": [
    { "use_type": "initial", "amount": 2 },
    { "use_type": "rental_hour", "amount": 3.5 },
    { "use_type": "rental_day", "amount": 18 },
    { "use_type": "rental_day", "amount": 22, "location_id": 4 }
  ]
}

Responses

200 OK. data holds the prices as now stored.

{
  "success": true,
  "data": {
    "space_type_id": 2,
    "prices": [
      { "use_type": "initial", "amount": 2, "location_id": null, "currency": null },
      { "use_type": "rental_hour", "amount": 3.5, "location_id": null, "currency": null },
      { "use_type": "rental_day", "amount": 18, "location_id": null, "currency": null },
      { "use_type": "rental_day", "amount": 22, "location_id": 4, "currency": null }
    ]
  }
}
Field Type Meaning
data.space_type_id integer The space type
data.prices[] array The rows as stored, in the order sent. Same fields as Space Type Prices

Changing prices does not change the space type’s own modified_at, and there is no conflict check on this route.

Errors

A refused row carries data.line, its position in prices from 1, and data.field when one field is to blame.

Status Code When
404 plugixa_carparking_not_found No space type with that id, or it is in the trash.
422 plugixa_carparking_invalid_prices prices is missing or not a list, or a row is not an object.
422 plugixa_carparking_missing_price_field A row has no use_type or no amount.
422 plugixa_carparking_invalid_choice use_type is not one of the six units.
422 plugixa_carparking_not_a_number amount is not a number.
422 plugixa_carparking_negative_number amount is negative.
422 plugixa_carparking_number_too_large amount is above 99999999.
422 plugixa_carparking_invalid_location location_id is not an existing location.
422 plugixa_carparking_duplicate_price Two rows have the same unit at the same location.
422 plugixa_carparking_too_long currency is longer than 10 characters.
500 plugixa_carparking_insert_failed The database refused the rows. Nothing was changed.

Plus the errors every endpoint can return.

Examples

curl -s -X PUT "https://your-site.example/wp-json/plugixa-car-parking/v1/space-types/2/prices" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"prices":[{"use_type":"initial","amount":2},{"use_type":"rental_hour","amount":3.5},{"use_type":"rental_day","amount":18},{"use_type":"rental_day","amount":22,"location_id":4}]}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-car-parking/v1/space-types/2/prices');
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([
        'prices' => [
            ['use_type' => 'initial', 'amount' => 2],
            ['use_type' => 'rental_hour', 'amount' => 3.5],
            ['use_type' => 'rental_day', 'amount' => 18],
            ['use_type' => 'rental_day', 'amount' => 22, 'location_id' => 4],
        ],
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-car-parking/v1/space-types/2/prices', {
  method: 'PUT',
  headers: {
    'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    prices: [
      { use_type: 'initial', amount: 2 },
      { use_type: 'rental_hour', amount: 3.5 },
      { use_type: 'rental_day', amount: 18 },
      { use_type: 'rental_day', amount: 22, location_id: 4 },
    ],
  }),
});
const { data } = await response.json();

Quick Links

Share