Coupons

This API allows to create, view, update, and delete coupons.

Coupon Properties #

AttributeTypeDescription
coupon_idintegerUnique identifier for the object. ( Read-Only )
coupon_titlestringTitle of the Coupon.
coupon_statusstring Status of the coupon. Only works if the status is published.
coupon_authorintegerID of the user.
coupon_datedateCreated date of the coupon.
coupon_date_gtmdateCreated date of coupon in GTM.
coupon_metasarrayCoupon meta data.

Coupon_metas

AttributeTypeDescription
coupon_codeintegerCoupon Code.
coupon_valuestringDiscounted coupon value.
coupon_expiry_datestring Expiry date of the coupon.
restricted_tripsintegerID’s of restricted trips.
coupon_limit_numberdateLimit count for the coupon.

Add Coupon #

This API helps to add a new coupon.

POST

/wp-json/wptravel/v1/add-coupon

curl --location 'https://example.com/wp-json/wptravel/v1/add-coupon' \
--header 'Authorization: Basic <application-key>' \
--form 'coupon_title="Coupon One"' \
--form 'coupon_code="cpn-001"' \
--form 'coupon_value="10"' \
--form 'coupon_expiry_date="2023-04-05"' \
--form 'restricted_trips="10"' \
--form 'coupon_limit_number="20"'
var myHeaders = new Headers();
myHeaders.append("Authorization", "Basic <application-key>");

var formdata = new FormData();
formdata.append("coupon_title", "Coupon One");
formdata.append("coupon_code", "cpn-001");
formdata.append("coupon_value", "10");
formdata.append("coupon_expiry_date", "2023-04-05");
formdata.append("restricted_trips", "10");
formdata.append("coupon_limit_number", "20");

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: formdata,
  redirect: 'follow'
};

fetch("https://example.com/wp-json/wptravel/v1/add-coupon", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
<?php
$client = new Client();
$headers = [
  'Authorization' => 'Basic <application-key>'
];
$options = [
  'multipart' => [
    [
      'name' => 'coupon_title',
      'contents' => 'Coupon One'
    ],
    [
      'name' => 'coupon_code',
      'contents' => 'cpn-001'
    ],
    [
      'name' => 'coupon_value',
      'contents' => '10'
    ],
    [
      'name' => 'coupon_expiry_date',
      'contents' => '2023-04-05'
    ],
    [
      'name' => 'restricted_trips',
      'contents' => '10'
    ],
    [
      'name' => 'coupon_limit_number',
      'contents' => '20'
    ]
]];
$request = new Request('POST', 'https://example.com/wp-json/wptravel/v1/add-coupon', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();

Update Coupon #

This API helps to update existing coupons by ID.

POST

/wp-json/wptravel/v1/update-coupon/93

curl --location 'https://example.com/wp-json/wptravel/v1/update-coupon/93' \

--header 'Authorization: Basic <application-key>' \

--form 'coupon_title="Coupon One"' \
--form 'coupon_code="1111"' \
--form 'coupon_value="1111"' \
--form 'coupon_expiry_date="2023-03-31"' \
--form 'restricted_trips="1111"' \
--form 'coupon_limit_number="20"'
var myHeaders = new Headers();
myHeaders.append("Authorization", "Basic <application-key>");

var formdata = new FormData();
formdata.append("coupon_title", "Coupon one");
formdata.append("coupon_code", "1111");
formdata.append("coupon_value", "1111");
formdata.append("coupon_expiry_date", "2023-03-31");
formdata.append("restricted_trips", "1111");
formdata.append("coupon_limit_number", "20");

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: formdata,
  redirect: 'follow'
};

fetch("https://example.com/wp-json/wptravel/v1/update-coupon/93", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
<?php
$client = new Client();
$headers = [
  'Authorization' => 'Basic <application-key>'
];
$options = [
  'multipart' => [
    [
      'name' => 'coupon_title',
      'contents' => 'Coupon one'
    ],
    [
      'name' => 'coupon_code',
      'contents' => '1111'
    ],
    [
      'name' => 'coupon_value',
      'contents' => '1111'
    ],
    [
      'name' => 'coupon_expiry_date',
      'contents' => '2023-03-31'
    ],
    [
      'name' => 'restricted_trips',
      'contents' => '1111'
    ],
    [
      'name' => 'coupon_limit_number',
      'contents' => '20'
    ]
]];
$request = new Request('POST', 'https://example.com/wp-json/wptravel/v1/update-coupon/93', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();

Delete Coupon #

This API helps to delete existing coupons by ID.

DELETE

/wp-json/wptravel/v1/delete-coupon/93

curl --location --request DELETE 'https://example.com/wp-json/wptravel/v1/delete-coupon/93' \
--header 'Authorization: Basic <application-key>'
var myHeaders = new Headers();
myHeaders.append("Authorization", "Basic <application-key>");

var requestOptions = {
  method: 'DELETE',
  headers: myHeaders,
  redirect: 'follow'
};

fetch("https://example.com/wp-json/wptravel/v1/delete-coupon/93", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
<?php
$client = new Client();
$headers = [
  'Authorization' => 'Basic <application-key>'
];
$request = new Request('DELETE', 'https://example.com/wp-json/wptravel/v1/delete-coupon/93', $headers);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();

Get Coupon #

This API helps you to get a coupon by ID.

GET

/wp-json/wptravel/v1/get-coupon/93

curl --location 'https://example.com/wp-json/wptravel/v1/get-coupon/92'
var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("https://example.com/wp-json/wptravel/v1/get-coupon/92", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
<?php
$client = new Client();
$request = new Request('GET', 'https://example.com/wp-json/wptravel/v1/get-coupon/92');
$res = $client->sendAsync($request)->wait();
echo $res->getBody();

JSON Response

{
        "coupon_id": 92,
        "coupon_title": "Coupon One",
        "coupon_status": "publish",
        "coupon_author": "1",
        "coupon_date": "2023-04-03 11:02:06",
        "coupon_date_gmt": "2023-04-03 11:02:06",
        "coupon_metas": {
            "general": {
                "coupon_code": "cpn-001",
                "coupon_value": "10",
                "coupon_expiry_date": "2023-04-05"
            },
            "restriction": {
                "restricted_trips": "10",
                "coupon_limit_number": "20"
            }
        }
    }

Get All Coupons #

This API helps to get all coupons.

GET

/wp-json/wptravel/v1/get-coupons/

curl --location 'https://example.com/wp-json/wptravel/v1/get-coupons'
var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("https://example.com/wp-json/wptravel/v1/get-coupons", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
<?php
$client = new Client();
$request = new Request('GET', 'https://example.com/wp-json/wptravel/v1/get-coupons');
$res = $client->sendAsync($request)->wait();
echo $res->getBody();

JSON Response

{
    {
        "coupon_id": 92,
        "coupon_title": "Coupon One",
        "coupon_status": "publish",
        "coupon_author": "1",
        "coupon_date": "2023-04-03 11:02:06",
        "coupon_date_gmt": "2023-04-03 11:02:06",
        "coupon_metas": {
            "general": {
                "coupon_code": "cpn-001",
                "coupon_value": "10",
                "coupon_expiry_date": "2023-04-05"
            },
            "restriction": {
                "restricted_trips": "10",
                "coupon_limit_number": "20"
            }
        }
    },
    {
        "coupon_id": 91,
        "coupon_title": "hellodfgfdgdfg",
        "coupon_status": "publish",
        "coupon_author": "1",
        "coupon_date": "2023-04-03 10:51:47",
        "coupon_date_gmt": "2023-04-03 10:51:47",
        "coupon_metas": {
            "general": {
                "coupon_code": "1111",
                "coupon_value": "1111",
                "coupon_expiry_date": "2023-03-31"
            },
            "restriction": {
                "restricted_trips": "1111",
                "coupon_limit_number": "20"
            }
        }
    },
    {
        "coupon_id": 89,
        "coupon_title": "helloone two",
        "coupon_status": "publish",
        "coupon_author": "1",
        "coupon_date": "2023-04-03 10:46:12",
        "coupon_date_gmt": "2023-04-03 10:46:12",
        "coupon_metas": {
            "general": {
                "coupon_code": "1001dfdg",
                "coupon_value": "",
                "coupon_expiry_date": ""
            },
            "restriction": {
                "restricted_trips": "",
                "coupon_limit_number": ""
            }
        }
    },
}