Payment Services

POST /vouchers/handout/{voucherGroupId}

Requires authentication with server access token.

Get generated voucher codes. The codes that are returned in this endpoint gets their status changed to "handed out". They will not be returned again by repeated calls to this endpoint. Handed out vouchers are in limbo until used. The person or system that hands out vouchers must be responsible for remembering them or making sure they are used. See the separate endpoint for automatically giving a voucher to a user.

Request

POST /api/2/vouchers/handout/{voucherGroupId}

voucherGroupId

required path parameter

ID of the voucher group to hand out vouchers for

amount

optional

The number of vouchers to retrieve. Defaults to 1.

Example request

cURL
Minimal example
curl https://login.schibsted.com/api/2/vouchers/handout/324673248 \
   -X POST \
   -d "oauth_token=[access token]"
With all parameters
curl https://login.schibsted.com/api/2/vouchers/handout/324673248 \
   -X POST \
   -d "oauth_token=[access token]" \
   -d "amount=99"
Java
Minimal example
SpidOAuthToken token = spidClient.getServerToken();
String responseJSON = spidClient.
    POST(token, "/vouchers/handout/324673248").
    getResponseBody();
With all parameters
Map<String, String> params = new HashMap<>() {{
    put("amount", "99");
}};

SpidOAuthToken token = spidClient.getServerToken();
String responseJSON = spidClient.
    POST(token, "/vouchers/handout/324673248", params).
    getResponseBody();

This example is an excerpt, see a full example

PHP
Minimal example
<?php
$client->auth();
echo var_dump($client->api("/vouchers/handout/324673248", "POST"));
With all parameters
<?php
$params = array(
    "amount" => "99"
);

$client->auth();
echo var_dump($client->api("/vouchers/handout/324673248", "POST", $params));

This example is an excerpt, see a full example

Clojure
Minimal example
(ns example
  (:require [spid-client-clojure.core :as spid]))

(let [client (spid/create-client "[client-id]" "[secret]")
      token (spid/create-server-token client)]
  (spid/POST client token "/vouchers/handout/324673248"))
With all parameters
(ns example
  (:require [spid-client-clojure.core :as spid]))

(let [client (spid/create-client "[client-id]" "[secret]")
      token (spid/create-server-token client)]
  (spid/POST client token "/vouchers/handout/324673248" {"amount" "99"}))

Response

This endpoint supports the JSON and JSON-P response formats.

Success: 200 OK

Returns a list of vouchers

Voucher

Vouchers are mainly described by the voucher group they belong to. Shared vouchers can be redeemed multiple times and as such never changes its status to redeemed. Unique vouchers have unique codes for each user and can only be redeemed once.

voucherId

integer (as string)

Unique ID of the voucher. Endpoints only ever use the voucherCode to access vouchers

voucherGroupId

integer (as string)

ID of the voucher group the voucher belongs to

userId

integer (as string)

userId of the user that redeemed the voucher or that the voucher is handed out to

type

Voucher type

Voucher group type

count

integer (as string)

Number of time the voucher has been redeemed. Only available for shared vouchers.

voucherCode

string

A unique string that gives access to this voucher

status

Voucher status

handoutBy

integer (as string)

userId of the user that handed out the voucher

createdBy

integer (as string)

userId of the user that generated the voucher

updated

datetime

When the voucher was last updated (i.e. had its status changed)

created

datetime

When the voucher was created

The check mark indicates that the field always contains a valid non-empty value.

Failure cases

Some HTTP response codes are used for multiple error situations. There is no consistent way to tell these apart, but the error object will contain a textual explanation of the reason for the error. For explanation on OAuth related failures and errors see OAuth authentication failures.

  • 401 Unauthorized You don't have administration rights for this client.
  • 401 Unauthorized Your client doesn't have administration rights for this client.
  • 403 Forbidden Client is not authorized to access this API endpoint. Contact SPiD to request access.
  • 403 Forbidden Requesting IP is not whitelisted
  • 403 Forbidden Client does not have access to this voucher group
  • 403 Forbidden Access token rejected
  • 404 Not Found Unknown client ID
  • 404 Not Found Client ID mismatch. The client making the request is no the owner of this resource, and does not have administrative privileges for it.
  • 404 Not Found Voucher group not found
  • 404 Not Found The requested amount exceeds the available amount. See error object for actual numbers.
  • 404 Not Found Handout failed
  • 420 Request Ratelimit exceeded

Sample response

JSON
[
  {
    "voucherId": "557916",
    "voucherGroupId": "47",
    "voucherCode": "64-HB2I-OPBL",
    "type": "8",
    "createdBy": "[ID of admin user, or client]",
    "created": "2014-08-06 11:47:27"
  }
]
JSON-P
callback([
  {
    "voucherId": "557916",
    "voucherGroupId": "47",
    "voucherCode": "64-HB2I-OPBL",
    "type": "8",
    "createdBy": "[ID of admin user, or client]",
    "created": "2014-08-06 11:47:27"
  }
]);

Comments/feedback

Do you have questions, or just want to contribute some newly gained insight? Want to share an example? Please leave a comment. SPiD reads and responds to every question. Additionally, your experience can help others using SPiD, and it can help us continuously improve our documentation.