Contents
On this page

Create Coupon - Plugixa Car Rental

POST /plugixa-car-rental/v1/coupons

Create a coupon.

Needs the Coupons app on. The user needs the plugixa_car_rental_create capability.

Note. valid_from and valid_until accept a date with a time (2026-12-01 10:00) without complaint, but only a bare YYYY-MM-DD is kept: a date sent with a time is stored as null, which means no limit. Send dates only.

Request

POST https://your-site.example/wp-json/plugixa-car-rental/v1/coupons

Request body

Content type: application/json

Field Type Required Description
code string Yes Letters, digits, dashes and underscores: anything else is removed, then it is cut to 50 characters. Must not match another live coupon’s code, ignoring case.
amount number Yes More than 0. At most 100 for a percentage. Rounded to 2 decimals.
discount_type string No percent (the default) or fixed. A fixed discount never takes more than the subtotal.
min_days integer No Shortest rental it applies to. At least 1, the default.
usage_limit integer No Most uses. 0 (the default) for no limit.
valid_from string No First day, YYYY-MM-DD, on the site’s calendar. Empty for no start.
valid_until string No Last day, YYYY-MM-DD. On or after valid_from. Empty for no end.
description string No Your note, up to 255 characters.
status string No published (the default) or unpublished.

A coupon takes its percentage or amount off the rental, the extras and the fees together, before tax. It is counted as used when a booking that carries it is confirmed.

{
  "code": "WINTER10",
  "description": "Winter campaign",
  "discount_type": "percent",
  "amount": 10,
  "min_days": 2,
  "valid_from": "2026-12-01",
  "valid_until": "2027-02-28",
  "usage_limit": 100
}

Responses

201 Created. data is the new coupon.

{
  "success": true,
  "data": {
    "id": 7,
    "code": "WINTER10",
    "code_key": "WINTER10",
    "description": "Winter campaign",
    "discount_type": "percent",
    "amount": 10.0,
    "min_days": 2,
    "valid_from": "2026-12-01",
    "valid_until": "2027-02-28",
    "usage_limit": 100,
    "status": "published",
    "created_by": 1,
    "modified_by": 1,
    "created_at": "2026-11-12 09:30:00",
    "modified_at": "2026-11-12 09:30:00",
    "deleted_at": null,
    "used": 14
  }
}
Field Type Meaning
data.id integer The coupon’s id
data.code string The code as you wrote it
data.discount_type string percent or fixed
data.amount number Percentage, or amount off in the site’s currency
data.used integer Confirmed bookings that used it. A cancelled booking gives its use back
data.usage_limit integer Most uses, 0 for no limit
data.status string published or unpublished. An unpublished code is refused
data.code_key string The code upper-cased: codes are matched without regard to case
data.min_days integer Shortest rental it applies to, in days
data.valid_from string|null First day it can be used, YYYY-MM-DD, or null
data.valid_until string|null Last day it can be used, or null
data.description string Your note
data.created_at string UTC datetime the record was created
data.modified_at string UTC datetime of the last change. Send it back on an update to be warned of a conflicting edit
data.deleted_at string|null null unless the record is in the trash

Errors

Status Code When
422 plugixa_car_rental_invalid code is empty after cleaning, amount is not above 0 or a percentage above 100, min_days is below 1, usage_limit is negative, or valid_until is before valid_from. data.field names the field.
409 plugixa_car_rental_invalid Another live coupon already uses this code.
422 plugixa_car_rental_invalid_date valid_from or valid_until is not a date.
422 plugixa_car_rental_invalid_choice status or discount_type is not one of its values. data.allowed lists them.
422 plugixa_car_rental_not_a_number A number field was sent as something else. data.field names it.
422 plugixa_car_rental_negative_number A number field that cannot be negative is. data.field names it.
422 plugixa_car_rental_too_long A text field is longer than its column. data.field names it and data.max gives the limit.

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixa-car-rental/v1/coupons" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"code":"WINTER10","description":"Winter campaign","discount_type":"percent","amount":10,"min_days":2,"valid_from":"2026-12-01","valid_until":"2027-02-28","usage_limit":100}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-car-rental/v1/coupons');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_USERPWD        => 'admin:' . getenv('WP_APP_PASSWORD'),
    CURLOPT_HTTPHEADER     => [
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS     => json_encode([
        'code'          => 'WINTER10',
        'description'   => 'Winter campaign',
        'discount_type' => 'percent',
        'amount'        => 10,
        'min_days'      => 2,
        'valid_from'    => '2026-12-01',
        'valid_until'   => '2027-02-28',
        'usage_limit'   => 100,
    ]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const auth = Buffer.from(`admin:${process.env.WP_APP_PASSWORD}`).toString('base64');
const response = await fetch('https://your-site.example/wp-json/plugixa-car-rental/v1/coupons', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${auth}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    code: 'WINTER10',
    description: 'Winter campaign',
    discount_type: 'percent',
    amount: 10,
    min_days: 2,
    valid_from: '2026-12-01',
    valid_until: '2027-02-28',
    usage_limit: 100,
  }),
});
const { data } = await response.json();

Quick Links

Share