Contents
On this page

Generate Coupons - Plugixa Car Wash

POST /plugixa-carwash/v1/coupons/generate

Create many coupons with random codes and the same terms, for a mailing or a printed voucher run.

Needs the Coupons app on, and the plugixa_carwash_create capability.

Note. Coupons are created one by one. If one is refused, the answer is that error, and the coupons created before it stay.

Request

POST https://your-site.example/wp-json/plugixa-carwash/v1/coupons/generate

Request body

Content type: application/json

Field Type Required Description
count integer Yes 1 to 500.
prefix string No Letters and digits kept, upper-cased, and joined to the random part with a dash: XMAS gives codes like XMAS-K7PQ2D. Without it the code is 6 random characters.
value number Yes As on Create Coupon.
max_uses integer No Defaults to 1 here: each code works once.
type string No And every other coupon field: applied to each code.
{
  "count": 3,
  "prefix": "XMAS",
  "type": "fixed",
  "value": 5,
  "ends_on": "2026-12-31"
}

Responses

201 Created. data.codes lists the new codes.

{
  "success": true,
  "data": {
    "codes": [
      "XMAS-K7PQ2D",
      "XMAS-8ZRM4T",
      "XMAS-W3HN9C"
    ]
  }
}
Field Type Meaning
data.codes array The codes created. Fewer than count only if random codes kept colliding with existing ones

Errors

Status Code When
400 rest_missing_callback_param count is missing.
400 rest_invalid_param count is below 1 or above 500.
422 plugixa_carwash_missing_value value is missing or empty.
422 plugixa_carwash_invalid_coupon The terms are not valid, for example a percentage above 100.

Plus the errors every endpoint can return.

Examples

curl -s -X POST "https://your-site.example/wp-json/plugixa-carwash/v1/coupons/generate" \
  -u "admin:$WP_APP_PASSWORD" \
  -H "Content-Type: application/json" \
  -d '{"count":3,"prefix":"XMAS","type":"fixed","value":5,"ends_on":"2026-12-31"}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-carwash/v1/coupons/generate');
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([
        'count'   => 3,
        'prefix'  => 'XMAS',
        'type'    => 'fixed',
        'value'   => 5,
        'ends_on' => '2026-12-31',
    ]),
]);
$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-carwash/v1/coupons/generate', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${auth}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    count: 3,
    prefix: 'XMAS',
    type: 'fixed',
    value: 5,
    ends_on: '2026-12-31',
  }),
});
const { data } = await response.json();

Quick Links

Share