Skip to main content

Documentation

Create Coupon

Create a coupon.

This method triggers the Coupon Created webhook. This webhook contains the same information as the response.

Code Samples
    • .NET

      • using System;
        using System.Text.Json;
        
        namespace RapydApiRequestSample
        {
            class Program
            {
                static void Main(string[] args)
                {
                    try
                    {
                        var requestObj = new
                        {
                            duration = "repeating",
                            duration_in_months = 3,
                            max_redemptions = 0,
                            metadata = new
                            {
                                merchant_defined = true
        
                            },
                            percent_off = 10,
                            redeem_by = 0,
                        };
        
                        string request = JsonSerializer.Serialize(requestObj);
        
                        string result = RapydApiRequestSample.Utilities.MakeRequest("POST", "/v1/coupons", request);
        
                        Console.WriteLine(result);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error completing request: " + e.Message);
                    }
                }
            }
        }
        
    • JavaScript

      • const makeRequest = require('<path-to-your-utility-file>/utilities').makeRequest;
        
        async function main() {
          try {
            const body = {
              duration: 'repeating',
              duration_in_months: 3,
              max_redemptions: 0,
              metadata: {
                merchant_defined: true
              },
              percent_off: 10,
              redeem_by: 0
            };
            const result = await makeRequest('POST', '/v1/coupons', body);
        
            console.log(result);
          } catch (error) {
            console.error('Error completing request', error);
          }
        }
        
    • PHP

      • <?php
        $path = $_SERVER['DOCUMENT_ROOT'];
        $path .= "/<path-to-your-utility-file>/utilities.php";
        include($path);
        
        $body = [
            "duration" => "repeating",
            "duration_in_months" => 3,
            "max_redemptions" => 0,
            "metadata" => array(
                "merchant_defined" => true
            ),
            "percent_off" => 10,
            "redeem_by" => 0
        ];
        
        try {
            $object = make_request('post', '/v1/coupons', $body);
            var_dump($object);
        } catch(Exception $e) {
            echo "Error =>$e";
        }
        ?>
    • Python

      • from pprint import pprint
        
        from utilities import make_request
        
        coupon = {
            "duration": "repeating",
            "duration_in_months": 3,
            "max_redemptions": 0,
            "metadata": {
                "merchant_defined": True
            },
            "percent_off": 10,
            "redeem_by": 0
        }
        result = make_request(method='post', path='/v1/coupons', body=coupon)
        pprint(result)
  • /v1/coupons

  • Percent Off

  • curl -X post 'https://sandboxapi.rapyd.net/v1/coupons' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw '{
        "duration": "repeating",
        "duration_in_months": 3,
        "id": "",
        "max_redemptions": 10,
        "percent_off": 10,
        "redeem_by": 0
    }'
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "36d538be-c787-494c-b858-34e7c0e206bd"
        },
        "data": {
            "id": "coupon_7b9934fcc584ef629d2dcad65cc0d39c",
            "amount_off": 0,
            "created": 1762175848,
            "currency": "",
            "duration": "repeating",
            "duration_in_months": 3,
            "max_redemptions": 10,
            "metadata": {},
            "percent_off": 10,
            "redeem_by": 0,
            "times_redeemed": 0,
            "discount_valid_until": 0,
            "discount_validity_in_months": 0,
            "discount_duration_in_uses": 0,
            "description": "",
            "valid": true
        }
    }
  • Amount Off

  • curl -X post 'https://sandboxapi.rapyd.net/v1/coupons' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw '{
        "amount_off": 2.25,
        "currency": "USD",
        "duration": "repeating",
        "duration_in_months": 3,
        "id": "",
        "max_redemptions": 10,
        "redeem_by": 0
    }'
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "5d09b146-fc7e-4509-b711-71bcd842e718"
        },
        "data": {
            "id": "coupon_64016edee479bb60bb6eb0f869c96d07",
            "amount_off": 2.25,
            "created": 1762091524,
            "currency": "USD",
            "duration": "repeating",
            "duration_in_months": 3,
            "max_redemptions": 10,
            "metadata": {},
            "percent_off": 0,
            "redeem_by": 0,
            "times_redeemed": 0,
            "discount_valid_until": 0,
            "discount_validity_in_months": 0,
            "discount_duration_in_uses": 0,
            "description": "",
            "valid": false
        }
    }
  • One Use

  • curl -X post 'https://sandboxapi.rapyd.net/v1/coupons' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw '{
        "amount_off": 2.75,
        "currency": "USD",
        "duration": "repeating",
        "duration_in_months": 1,
        "discount_duration_in_uses": 1,
        "max_redemptions": 1
    }'
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "adef7239-5688-4d28-ab18-0de89b57537c"
        },
        "data": {
            "id": "coupon_b1d1eb5bda5a50058cf198d0948afae0",
            "amount_off": 2.75,
            "created": 1762091613,
            "currency": "USD",
            "duration": "repeating",
            "duration_in_months": 1,
            "max_redemptions": 1,
            "metadata": {},
            "percent_off": 0,
            "redeem_by": 0,
            "times_redeemed": 0,
            "discount_valid_until": 0,
            "discount_validity_in_months": 0,
            "discount_duration_in_uses": 1,
            "description": "",
            "valid": true
        }
    }
  • Duration - Repeating for 5 months

  • curl -X post 'https://sandboxapi.rapyd.net/v1/coupons' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw '{
        "currency": "USD",
        "duration": "repeating",
        "duration_in_months": 5,
        "max_redemptions": 10,
        "percent_off": 20
    }'
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "fbcc9d02-fb93-4946-86fb-ecfe5378a326"
        },
        "data": {
            "id": "coupon_3d7c387f8158b24813c15f5704f9e6c1",
            "amount_off": 0,
            "created": 1762094734,
            "currency": "USD",
            "duration": "repeating",
            "duration_in_months": 5,
            "max_redemptions": 10,
            "metadata": {},
            "percent_off": 20,
            "redeem_by": 0,
            "times_redeemed": 0,
            "discount_valid_until": 0,
            "discount_validity_in_months": 0,
            "discount_duration_in_uses": 0,
            "description": "",
            "valid": false
        }
    }
  • Duration - Forever

  • curl -X post 'https://sandboxapi.rapyd.net/v1/coupons' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw '{
        "amount_off": 2.25,
        "currency": "USD",
        "duration": "forever",
        "max_redemptions": 1
    }'
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "0753c2ef-96d3-4828-a546-6fef11629ebb"
        },
        "data": {
            "id": "coupon_e21fa4476472cfe2de3fbf08a179c62a",
            "amount_off": 2.25,
            "created": 1762094788,
            "currency": "USD",
            "duration": "forever",
            "duration_in_months": 0,
            "max_redemptions": 1,
            "metadata": {},
            "percent_off": 0,
            "redeem_by": 0,
            "times_redeemed": 0,
            "discount_valid_until": 0,
            "discount_validity_in_months": 0,
            "discount_duration_in_uses": 0,
            "description": "",
            "valid": true
        }
    }