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' -d '{ "duration": "repeating", "duration_in_months": 3, "max_redemptions": 0, "metadata": { "merchant_defined": true }, "percent_off": 10, "redeem_by": 0 } '
{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "a582f08b-9d24-4742-b938-2ead31384886" }, "data": { "id": "coupon_72b8f33846b06f9e7fb0d12cccf98061", "amount_off": 0, "created": 1646817710, "currency": "", "duration": "repeating", "duration_in_months": 3, "max_redemptions": 0, "metadata": { "merchant_defined": true }, "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": false } }
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' -d '{ "amount_off": 2, "currency": "USD", "duration": "repeating", "duration_in_months": 3, "id": "", "max_redemptions": 0, "metadata": { "merchant_defined": true }, "percent_off": null, "redeem_by": 0 } '
{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "4136bb02-a810-4fa4-93b3-6e9c9db3d635" }, "data": { "id": "coupon_4dad14cea027ceb54a6c39837744d91c", "amount_off": 2, "created": 1646818171, "currency": "USD", "duration": "repeating", "duration_in_months": 3, "max_redemptions": 0, "metadata": { "merchant_defined": true }, "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' -d '{ "amount_off": 2, "currency": "USD", "duration": "repeating", "duration_in_months": 1, "discount_duration_in_uses": 1, "max_redemptions": 1, "metadata": { "merchant_defined": true }, "percent_off": null, "redeem_by": 0 } '
{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "5cc78ea0-d657-4a16-a0f1-a4af2b8ac34d" }, "data": { "id": "coupon_dc3d519ebfee0818d883686d516fc780", "amount_off": 2, "created": 1647155932, "currency": "USD", "duration": "repeating", "duration_in_months": 1, "max_redemptions": 1, "metadata": { "merchant_defined": true }, "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' -d '{ "currency": "USD", "duration": "repeating", "duration_in_months": 5, "max_redemptions": 0, "metadata": { "merchant_defined": true }, "percent_off": 20, "redeem_by": 0 } '
{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "86cac233-444e-464c-878b-c10bbf94b13d" }, "data": { "id": "coupon_71ac2a65139aced4ef0d09aec75e19ba", "amount_off": 0, "created": 1646825405, "currency": "USD", "duration": "repeating", "duration_in_months": 5, "max_redemptions": 0, "metadata": { "merchant_defined": true }, "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' -d '{ "amount_off": 2, "currency": "USD", "duration": "forever", "max_redemptions": 1, "metadata": { "merchant_defined": true }, "percent_off": null, "redeem_by": 0 } '
{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "d776c09c-daa6-453d-8bb3-1af260606d43" }, "data": { "id": "coupon_4ab30530e8a7352ffe715deecfab57b9", "amount_off": 2, "created": 1646825743, "currency": "USD", "duration": "forever", "duration_in_months": 0, "max_redemptions": 1, "metadata": { "merchant_defined": true }, "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 } }