Generate Discounts

This method can be applied on your server-side, in order to generate and store the discount codes in your store, which will be allocated to the customers (via email triggers, sms triggers or newsletter).

Method: GET


Function parameters

Field Type Required Description
key text True The REST API Key can be found into your account Settings -> Integration -> REST API Key, second field.
value number True Discount Value, for example 10
type number True FIXED=0 | PERCENTAGE=1 | NIL(Free delivery as example)=2
count number True Number of discount code to generate

Your account status must be in one of the states: PAID, PAYMENT ERROR or ACCOUNT SUSPENDED.

If your account is INACTIVE or CLOSED this API call will not be sent.

Your link will need to respond with JSON format.


$myShopRestApiKey = '78jsdh432kkdjd';  \\ you will need to replace this with yout own REST API KEY

if (isset($_GET['key']) && $_GET['key'] === $myShopRestApiKey &&
    gettype($_GET['value']) === 'integer' && gettype($_GET['type']) === 'integer') {

    $discountCodes = [];

    for ($i = 0; $i < $_GET['count']; $i++) {
        $code = 'RTG-'.rand(10000000000000, 99999999999999);

        /* This is an code Example */
       $created = DiscountCode::create([
            'value'  => $_GET['value'],
            'type'   => $_GET['type'], // "fixed value"=0 | "percentage"=1 | "free shipping"=2
            'code'   => $code

       /* Check if code was added to your database */
       if ($created) {
            $discountCodes[] = $code;

    echo json_encode($discountCodes);
} else {
    echo json_encode(['status' => 'Incorrect REST API Key']);

If the API call succeeds, then the response will return 5 discount codes as seen below:



{"status":"Incorrect REST API Key"}