Validate Activate

Voucher validation

To be sure that a voucher exists and is active in Vouchstar we need to first validate it.

How does this work?

After we provide our voucher code we send it to the API for a validation.

Requirements

  • $API_ACCESS_TOKEN - API access token - partners API access token that was provided with the activation Email
If you haven't got an API access token go back to Getting started

Validation endpoint

API domain

https://vouchstar.shop

API endpoint

/api/vouchers/validate/<voucher-code> - change <voucher-code> to the voucher code you want to validate.

eg.

  • our voucher code: 91f53b25-51be-41dd-afeb-18cf534d1d23
  • the full endpoint url should look like: /api/vouchers/validate/91f53b25-51be-41dd-afeb-18cf534d1d23
  • $FULL_API_VALIDATION_URL - full url: https://vouchstar.shop/api/vouchers/validate/91f53b25-51be-41dd-afeb-18cf534d1d23

Request method

$HTTP_REQUEST_METHOD - Request method needs to be set as POST

Request header

$HTTP_REQUEST_HEADER - A custom Request header is needed: X-Access-Token

The API access token has been provided with the email invitation

Example

CURL will be used here to show you an example of working validation integration.

Parameters:

  • -X - define the request method
  • -H - define additional request headers

We will be using an additional header defined as -H 'accept: application/json'so that the data is requested as JSON

curl -X '$HTTP_REQUEST_METHOD' '$FULL_API_VALIDATION_URL' -H '$HTTP_REQUEST_HEADER' -H 'accept: application/json'

Response codes

  • price - the value of the voucher
  • status - status given to the voucher before proper activation. Status UNUSED is the only status we should see on a proper validation.
  • detail - shows us the error description
  • SUCCESS CODE is 200
  • ERROR CODE is 404
API successful response (200)
Code
{
    "price":27.0,
    "status":"UNUSED"
}
API voucher not found response (404)
Code
{
    "detail":"Voucher not found"
}
API partner not found response (404)
Code
{
    "detail":"Partner not found"
}
API bad request method response (404)
Code
{
    "detail":"Method Not Allowed"
}

Copyright © 2024