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

URL: https://yourDomain.com/retargeting-code-generator.php

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.

Example

1 <?php
2 $myShopRestApiKey = '78jsdh432kkdjd';  \\ you will need to replace this with yout own REST API KEY
3 
4 if (isset($_GET['key']) && $_GET['key'] === $myShopRestApiKey &&
5     gettype($_GET['value']) === 'integer' && gettype($_GET['type']) === 'integer') {
6 
7     $discountCodes = [];
8 
9     for ($i = 0; $i < $_GET['count']; $i++) {
10         $code = 'RTG-'.rand(10000000000000, 99999999999999);
11 
12         /* This is an code Example */
13        $created = DiscountCode::create([
14             'value'  => $_GET['value'],
15             'type'   => $_GET['type'], // "fixed value"=0 | "percentage"=1 | "free shipping"=2
16             'code'   => $code
17        ]);
18 
19        /* Check if code was added to your database */
20        if ($created) {
21             $discountCodes[] = $code;
22        }
23     }
24 
25     echo json_encode($discountCodes);
26 } else {
27     echo json_encode(['status' => 'Incorrect REST API Key']);
28 }

1 https://yourDomain.com/retargeting-code-generator.php?key=RTG_RESTAPIKEY&value=10&type=1&count=5

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

1 ["RTG-55565732024","RTG-56264321426","RTG-88891301568","RTG-28610504947","RTG-92901684606"]

OR

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