Discounts use cases

Summary

This section provides several common use cases that demonstrate how you can create different types of discounts with various rules.

Common use cases

There are several types of discounts that you can create to establish relationships with your customers.

   New customer discounts

New customer discounts can incentivize a customer to sign up. The example below shows how you can programatically create a 20% off discount for first-time customers who place an order in your store.

     Create a one-time 20% off discount for new customers only

curl --location --request POST 'https://api.rechargeapps.com/discounts' \
--header 'X-Recharge-Access-Token: {your token} \
--header 'Content-Type: application/json' \
--data-raw '{
   "code": "FEBNEWCUSTOMER22",
   "value": 20,
   "discount_type": "percentage",
   "channel_settings": {
       "api": {
           "can_apply": true
       },
       "checkout_page": {
           "can_apply": true
       },
       "customer_portal": {
           "can_apply": true
       },
       "merchant_portal": {
           "can_apply": true
       }
   },
   "applies_to_product_type": "ONETIME",
   "duration": "usage_limit",
   "duration_usage_limit": 1,
   "status": "enabled",
   "usage_limit": 1,
   "first_time_customer_restriction": "customer_must_not_exist_in_recharge",
   "starts_at": "2022-02-08",
   "ends_at": "2023-12-31",
   "applies_to_id": 7535871328502,
   "applies_to_resource": "shopify_product"
}'
import requests
import json

url = "https://api.rechargeapps.com/discounts"

payload = json.dumps({
 "code": "FEBNEWCUSTOMER22",
 "value": 20,
 "discount_type": "percentage",
 "channel_settings": {
   "api": {
     "can_apply": True
   },
   "checkout_page": {
     "can_apply": True
   },
   "customer_portal": {
     "can_apply": True
   },
   "merchant_portal": {
     "can_apply": True
   }
 },
 "applies_to_product_type": "ONETIME",
 "duration": "usage_limit",
 "duration_usage_limit": 1,
 "status": "enabled",
 "usage_limit": 1,
 "first_time_customer_restriction": "customer_must_not_exist_in_recharge",
 "starts_at": "2022-02-08",
 "ends_at": "2023-12-31",
 "applies_to_id": 7535871328502,
 "applies_to_resource": "shopify_product"
})
headers = {
 'X-Recharge-Access-Token': {your token},
 'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
require "uri"
require "json"
require "net/http"

url = URI("https://api.rechargeapps.com/discounts")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Recharge-Access-Token"] = "{your_access_token}"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
 "code": "FEBNEW2022",
 "value": 20,
 "discount_type": "percentage",
 "channel_settings": {
   "api": {
     "can_apply": true
   },
   "checkout_page": {
     "can_apply": true
   },
   "customer_portal": {
     "can_apply": true
   },
   "merchant_portal": {
     "can_apply": true
   }
 },
 "applies_to_product_type": "ONETIME",
 "duration": "usage_limit",
 "duration_usage_limit": 1,
 "status": "enabled",
 "usage_limit": 1,
 "first_time_customer_restriction": "customer_must_not_exist_in_recharge",
 "starts_at": "2022-02-15",
 "ends_at": "2023-12-31",
 "applies_to_id": 753871328502,
 "applies_to_resource": "shopify_product"
})

response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/discounts');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
 'follow_redirects' => TRUE
));
$request->setHeader(array(
 'X-Recharge-Access-Token' => '{your_access_token}',
 'Content-Type' => 'application/json',
));
$request->setBody('{\n    "code": "FEBNEW2022",\n    "value": 20,\n    "discount_type": "percentage",\n    "channel_settings": {\n        "api": {\n            "can_apply": true\n        },\n        "checkout_page": {\n            "can_apply": true\n        },\n        "customer_portal": {\n            "can_apply": true\n        },\n        "merchant_portal": {\n            "can_apply": true\n        }\n    },\n    "applies_to_product_type": "ONETIME",\n    "duration": "usage_limit",\n    "duration_usage_limit": 1,\n    "status": "enabled",\n    "usage_limit": 1,\n    "first_time_customer_restriction": "customer_must_not_exist_in_recharge",\n    "starts_at": "2022-02-15",\n    "ends_at": "2023-12-31",\n    "applies_to_id": 753871328502,\n    "applies_to_resource": "shopify_product"\n}');
try {
 $response = $request->send();
 if ($response->getStatus() == 200) {
   echo $response->getBody();
 }
 else {
   echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
   $response->getReasonPhrase();
 }
}
catch(HTTP_Request2_Exception $e) {
 echo 'Error: ' . $e->getMessage();
}
API Version 2021-11 examples in the next tabs
curl --location --request POST 'https://api.rechargeapps.com/discounts' \
--header 'X-Recharge-Access-Token: {your_access_token}\
--header 'Content-Type: application/json' \
--data-raw '{
   "applies_to": {
       "purchase_item_type": "ONETIME"
   },
   "channel_settings": {
       "api": {
           "can_apply": true
       },
       "checkout_page": {
           "can_apply": true
       },
       "customer_portal": {
           "can_apply": true
       },
       "merchant_portal": {
           "can_apply": true
       }
   },
   "code": "FEB20NEWCUSTOMER",
   "status": "enabled",
   "usage_limits": {
       "first_time_customer_restriction": true,
       "one_application_per_customer": false
   },
   "value": "20",
   "value_type": "percentage"
}'
import requests
import json

url = "https://api.rechargeapps.com/discounts"

payload = json.dumps({
 "applies_to": {
   "purchase_item_type": "ONETIME"
 },
 "channel_settings": {
   "api": {
     "can_apply": True
   },
   "checkout_page": {
     "can_apply": True
   },
   "customer_portal": {
     "can_apply": True
   },
   "merchant_portal": {
     "can_apply": True
   }
 },
 "code": "FEB22NEWCUSTOMER20",
 "status": "enabled",
 "usage_limits": {
   "first_time_customer_restriction": True,
   "one_application_per_customer": False
 },
 "value": "20",
 "value_type": "percentage"
})
headers = {
 'X-Recharge-Access-Token': {your_access_token},
 'Content-Type': 'application/json',
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
require "uri"
require "json"
require "net/http"

url = URI("https://api.rechargeapps.com/discounts")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Recharge-Access-Token"] = "sk_test_1x1_fd5d4c5ad5201a107434b4d2d967e0539e872beb0d70179af3f5ce0ec0078927"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
 "applies_to": {
   "purchase_item_type": "ONETIME"
 },
 "channel_settings": {
   "api": {
     "can_apply": true
   },
   "checkout_page": {
     "can_apply": true
   },
   "customer_portal": {
     "can_apply": true
   },
   "merchant_portal": {
     "can_apply": true
   }
 },
 "code": "FEB22NEWCUSTOMERDISCOOUNT",
 "status": "enabled",
 "usage_limits": {
   "first_time_customer_restriction": true,
   "one_application_per_customer": false
 },
 "value": "20",
 "value_type": "percentage"
})

response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/discounts');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
 'follow_redirects' => TRUE
));
$request->setHeader(array(
 'X-Recharge-Access-Token' => {your_access_token},
 'Content-Type' => 'application/json',
));
$request->setBody('{\n    "applies_to": {\n        "purchase_item_type": "ONETIME"\n    },\n    "channel_settings": {\n        "api": {\n            "can_apply": true\n        },\n        "checkout_page": {\n            "can_apply": true\n        },\n        "customer_portal": {\n            "can_apply": true\n        },\n        "merchant_portal": {\n            "can_apply": true\n        }\n    },\n    "code": "FEB22NEWCUSTOMERDISCOOUNT",\n    "status": "enabled",\n    "usage_limits": {\n        "first_time_customer_restriction": true,\n        "one_application_per_customer": false\n    },\n    "value": "20",\n    "value_type": "percentage"\n}');
try {
 $response = $request->send();
 if ($response->getStatus() == 200) {
   echo $response->getBody();
 }
 else {
   echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
   $response->getReasonPhrase();
 }
}
catch(HTTP_Request2_Exception $e) {
 echo 'Error: ' . $e->getMessage();
}

     Parameters explained

2021-012021-11

  • value - the amount of the discount

  • discount_type - the type of discount

  • applies_to_product_type - specifies whether the discount will be applied to onetimes, subscriptions, or all purchase types

  • duration - specifies whether there is a usage limit for the discount

  • duration_usage_limit - specifies that the discount can only be applied once

  • usage_limit - the maximum number of times the discount can be used by customers

  • first_time_customer_restriction - specifies that the discount can only be applied by a customer not already in Recharge


  • purchase_item_type - specifies that this is a one time discount

  • first_time_customer_restriction - specifies whether the discount is limited to only new customers

  • value - amount of the discount

  • value_type - the type of discount being created

   Redemption limits and applications

Redemption limits are useful to create discounts whose value is spread across time. This increases customer lifetime and gives a user the opportunity to create a new habit for the product.

     3 redemptions for $10 limited to 100 applications

This example shows how you can create a discount that has a limit of 3 redemptions for $10 each, with a maximum number of discount applications in the entire store set to 100.

📘

NOTE

This feature will be coming soon to Recharge API version 2021-11. The example below illustrates this feature for Recharge API version 2021-01.

curl --location --request POST 'https://api.rechargeapps.com/discounts' \
--header 'X-Recharge-Access-Token: {your_access_token} \
--header 'Content-Type: application/json' \
--data-raw '{
   "code": "FEB22REDEMPTIONDISCOUNT",
   "value": "10",
   "discount_type": "fixed_amount",
   "channel_settings": {
       "api": {
           "can_apply": false
       },
       "checkout_page": {
           "can_apply": true
       },
       "customer_portal": {
           "can_apply": true
       },
       "merchant_portal": {
           "can_apply": false
       }
   },
   "applies_to_product_type": "ALL",
   "duration": "usage_limit",
   "duration_usage_limit": "3",
   "status": "enabled",
   "usage_limit": "100",
   "starts_at": "2022-02-10",
   "ends_at": "2023-12-31",
   "applies_to_id": "7535871328502",
   "applies_to_resource": "shopify_product"
import requests
import json

url = "https://api.rechargeapps.com/discounts"

payload = json.dumps({
 "code": "FEB22REDEMPTIONDISCOUNT",
 "value": "10",
 "discount_type": "fixed_amount",
 "channel_settings": {
   "api": {
     "can_apply": False
   },
   "checkout_page": {
     "can_apply": True
   },
   "customer_portal": {
     "can_apply": True
   },
   "merchant_portal": {
     "can_apply": False
   }
 },
 "applies_to_product_type": "ALL",
 "duration": "usage_limit",
 "duration_usage_limit": "3",
 "status": "enabled",
 "usage_limit": "100",
 "starts_at": "2022-02-10",
 "ends_at": "2023-12-31",
 "applies_to_id": "7535871328502",
 "applies_to_resource": "shopify_product"
})
headers = {
 'X-Recharge-Access-Token': {your_access+token},
 'Content-Type': 'application/json',
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
require "uri"
require "json"
require "net/http"

url = URI("https://api.rechargeapps.com/discounts")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Recharge-Access-Token"] = "{your_access_token}"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
 "code": "FEBTRIPLEDISCOUNT2022",
 "value": 10,
 "discount_type": "fixed_amount",
 "channel_settings": {
   "api": {
     "can_apply": true
   },
   "checkout_page": {
     "can_apply": true
   },
   "customer_portal": {
     "can_apply": true
   },
   "merchant_portal": {
     "can_apply": true
   }
 },
 "applies_to_product_type": "ALL",
 "duration": "usage_limit",
 "duration_usage_limit": 3,
 "status": "enabled",
 "usage_limit": 100,
 "starts_at": "2022-02-15",
 "ends_at": "2023-12-31",
 "applies_to_id": 753871328502,
 "applies_to_resource": "shopify_product"
})

response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/discounts');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
 'follow_redirects' => TRUE
));
$request->setHeader(array(
 'X-Recharge-Access-Token' => '{your_access_token}',
 'Content-Type' => 'application/json',
));
$request->setBody('{\n    "code": "FEBTRIPLEDISCOUNT2022",\n    "value": 10,\n    "discount_type": "fixed_amount",\n    "channel_settings": {\n        "api": {\n            "can_apply": true\n        },\n        "checkout_page": {\n            "can_apply": true\n        },\n        "customer_portal": {\n            "can_apply": true\n        },\n        "merchant_portal": {\n            "can_apply": true\n        }\n    },\n    "applies_to_product_type": "ALL",\n    "duration": "usage_limit",\n    "duration_usage_limit": 3,\n    "status": "enabled",\n    "usage_limit": 100,\n    "starts_at": "2022-02-15",\n    "ends_at": "2023-12-31",\n    "applies_to_id": 753871328502,\n    "applies_to_resource": "shopify_product"\n}');
try {
 $response = $request->send();
 if ($response->getStatus() == 200) {
   echo $response->getBody();
 }
 else {
   echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
   $response->getReasonPhrase();
 }
}
catch(HTTP_Request2_Exception $e) {
 echo 'Error: ' . $e->getMessage();
}

     Parameters explained

2021-01


  • value - the value of the discount

  • code>discount_type - the type of discount being created

  • duration_usage_limit - sets the maximum number of times the discount can be applied

  • usage_limit - the maximum number of times the discount can be used by customers

   Free shipping for one customer with end date

Offering free shipping to a customer can be a way for you to potentially prevent the customer from abandoning their cart because of shipping costs.

curl --location --request POST 'https://api.rechargeapps.com/discounts' \
--header 'X-Recharge-Access-Token: {your token} \
--header 'Content-Type: application/json' \
--data-raw '{
   "code": "FREESHIPPINGFEB22",
   "value": 100,
   "discount_type": "percentage",
   "channel_settings": {
       "api": {
           "can_apply": true
       },
       "checkout_page": {
           "can_apply": true
       },
       "customer_portal": {
           "can_apply": true
       },
       "merchant_portal": {
           "can_apply": true
       }
   },
   "applies_to_product_type": "ONETIME",
   "duration": "usage_limit",
   "duration_usage_limit": 1,
   "status": "enabled",
   "usage_limit": 1,
   "starts_at": "2022-02-08",
   "ends_at": "2023-12-31"
}'
import requests
import json

url = "https://api.rechargeapps.com/discounts"

payload = json.dumps({
 "code": "FREESHIPPINGFEB22",
 "value": 100,
 "discount_type": "percentage",
 "channel_settings": {
   "api": {
     "can_apply": True
   },
   "checkout_page": {
     "can_apply": True
   },
   "customer_portal": {
     "can_apply": True
   },
   "merchant_portal": {
     "can_apply": True
   }
 },
 "applies_to_product_type": "ONETIME",
 "duration": "usage_limit",
 "duration_usage_limit": 1,
 "status": "enabled",
 "usage_limit": 1,
 "starts_at": "2021-02-08",
 "ends_at": "2023-12-31"
})
headers = {
 'X-Recharge-Access-Token': {your token},
 'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
require "uri"
require "json"
require "net/http"

url = URI("https://api.rechargeapps.com/discounts")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Recharge-Access-Token"] = "{your_access_token}"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
 "code": "FEB22FREESHIPPING",
 "value": "100",
 "discount_type": "percentage",
 "channel_settings": {
   "api": {
     "can_apply": true
   },
   "checkout_page": {
     "can_apply": true
   },
   "customer_portal": {
     "can_apply": true
   },
   "merchant_portal": {
     "can_apply": true
   }
 },
 "applies_to_product_type": "ONETIME",
 "duration": "usage_limit",
 "duration_usage_limit": "1",
 "status": "enabled",
 "usage_limit": "1",
 "starts_at": "2022-02-15",
 "ends_at": "2023-12-31"
})

response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/discounts');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
 'follow_redirects' => TRUE
));
$request->setHeader(array(
 'X-Recharge-Access-Token' => '{your_access_token}',
 'Content-Type' => 'application/json',
));
$request->setBody('{\n    "code": "FEB22FREESHIPPING",\n    "value": "100",\n    "discount_type": "percentage",\n    "channel_settings": {\n        "api": {\n            "can_apply": true\n        },\n        "checkout_page": {\n            "can_apply": true\n        },\n        "customer_portal": {\n            "can_apply": true\n        },\n        "merchant_portal": {\n            "can_apply": true\n        }\n    },\n    "applies_to_product_type": "ONETIME",\n    "duration": "usage_limit",\n    "duration_usage_limit": "1",\n    "status": "enabled",\n    "usage_limit": "1",\n    "starts_at": "2022-02-15",\n    "ends_at": "2023-12-31"\n}');
try {
 $response = $request->send();
 if ($response->getStatus() == 200) {
   echo $response->getBody();
 }
 else {
   echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
   $response->getReasonPhrase();
 }
}
catch(HTTP_Request2_Exception $e) {
 echo 'Error: ' . $e->getMessage();
}
API Version 2021-11 examples in the next tabs
curl --location --request POST 'https://api.rechargeapps.com/discounts' \
--header 'X-Recharge-Access-Token: {your_access_token}\
--header 'Content-Type: application/json' \
--data-raw '{
   "code": "FREESHIPPINGCUSTOMER22",
   "value": "100.00",
   "value_type": "shipping",
   "usage_limit": "1",
   "ends_at": "2023-12-31"
}'
import requests
import json

url = "https://api.rechargeapps.com/discounts"

payload = json.dumps({
 "code": "FREESHIPPINGCUSTOMER22",
 "value": "100.00",
 "value_type": "shipping",
 "usage_limit": "1",
 "ends_at": "2023-12-31"
})
headers = {
 'X-Recharge-Access-Token': {your_access_token},
 'Content-Type': 'application/json',
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
require "uri"
require "json"
require "net/http"

url = URI("https://api.rechargeapps.com/discounts")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Recharge-Access-Token"] = “ {
  your_access_token
}”
request["Content-Type"] = "application/json"
request.body = JSON.dump({
  "code": "FEB2022FREESHIPPING",
  "value": "100.00",
  "value_type": "shipping",
  "usage_limit": "1",
  "ends_at": "2023-12-31"
})

response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/discounts');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
 'follow_redirects' => TRUE
));
$request->setHeader(array(
 'X-Recharge-Access-Token' => {your_access_token},
 'Content-Type' => 'application/json',
));
$request->setBody('{\n    "code": "FEB2022FREESHIPPING",\n    "value": "100.00",\n    "value_type": "shipping",\n    "usage_limit" : "1",\n    "ends_at" : "2023-12-31"\n}');
try {
 $response = $request->send();
 if ($response->getStatus() == 200) {
   echo $response->getBody();
 }
 else {
   echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
   $response->getReasonPhrase();
 }
}
catch(HTTP_Request2_Exception $e) {
 echo 'Error: ' . $e->getMessage();
}

     Parameters explained

2021-01 & 2021-11


  • value - value of the discount

  • discount_type - type of discount

  • usage_limit - the maximum number of times the discount can be applied

  • ends_at - expiration date for the discount


   Multiple rules for discount redemptions

Occasionally, you may wish to create a discount with very specific limitations on how the discount can be applied to maximize its effectiveness. You can choose to limit the channels where the discount can be applied, the products or collections that can be associated with the discount, as well as the number of times a customer may apply the discount. All of these filters provide you with a strong measure of control in how discounts are applied in your store.

The example below shows how to create a discount with a limited number of redemptions (3), the channel where the discount can be applied (only in the Customer Portal), and whether the discount can be applied to products or collections (collections only).

     3 redemptions on Customer Portal only for a collection

The example below shows how you can create a discount with a limit of 3 redemptions for a customer, limit the redemption to the Customer Portal, and limits the application of the discount to a list of products (called collection)

curl --location --request POST 'https://api.rechargeapps.com/discounts' \
--header 'X-Recharge-Access-Token: {your access token} \
--header 'Content-Type: application/json' \
--data-raw '{
   "code": "RedemptionsCollections",
   "value": 15,
   "discount_type": "percentage",
   "channel_settings": {
       "api": {
           "can_apply": false
       },
       "checkout_page": {
           "can_apply": false
       },
       "customer_portal": {
           "can_apply": true
       },
       "merchant_portal": {
           "can_apply": false
       }
   },
   "applies_to_product_type": "SUBSCRIPTION",
   "duration": "usage_limit",
   "duration_usage_limit": 3,
   "status": "enabled",
   "usage_limit": 1,
   "starts_at": "2022-02-08",
   "ends_at": "2023-12-31",
   "applies_to_id": 389334466806,
   "applies_to_resource": "shopify_collection_id"
}'
import requests
import json

url = "https://api.rechargeapps.com/discounts"

payload = json.dumps({
 "code": "RedemptionsCollections",
 "value": 15,
 "discount_type": "percentage",
 "channel_settings": {
   "api": {
     "can_apply": False
   },
   "checkout_page": {
     "can_apply": False
   },
   "customer_portal": {
     "can_apply": True
   },
   "merchant_portal": {
     "can_apply": False
   }
 },
 "applies_to_product_type": "SUBSCRIPTION",
 "duration": "usage_limit",
 "duration_usage_limit": 3,
 "status": "enabled",
 "usage_limit": 1,
 "starts_at": "2022-02-08",
 "ends_at": "2023-12-31",
 "applies_to_id": 389334466806,
 "applies_to_resource": "shopify_collection_id"
})
headers = {
 'X-Recharge-Access-Token': {your access token},
 'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
require "uri"
require "json"
require "net/http"

url = URI("https://api.rechargeapps.com/discounts")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Recharge-Access-Token"] = "{your_access_token}"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
 "code": "FEB22COLLECTIONDISCOUNT",
 "value": "15",
 "discount_type": "percentage",
 "channel_settings": {
   "api": {
     "can_apply": false
   },
   "checkout_page": {
     "can_apply": false
   },
   "customer_portal": {
     "can_apply": true
   },
   "merchant_portal": {
     "can_apply": false
   }
 },
 "applies_to_product_type": "SUBSCRIPTION",
 "duration": "usage_limit",
 "duration_usage_limit": "3",
 "status": "enabled",
 "usage_limit": "1",
 "starts_at": "2022-02-15",
 "ends_at": "2023-12-31",
 "applies_to_id": "389334466806",
 "applies_to_resource": "shopify_collection_id"
})

response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/discounts');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
 'follow_redirects' => TRUE
));
$request->setHeader(array(
 'X-Recharge-Access-Token' => {your_access_token},
 'Content-Type' => 'application/json',
));
$request->setBody('{\n    "code": "FEB22COLLECTIONDISCOUNT",\n    "value": "15",\n    "discount_type": "percentage",\n    "channel_settings": {\n        "api": {\n            "can_apply": false\n        },\n        "checkout_page": {\n            "can_apply": false\n        },\n        "customer_portal": {\n            "can_apply": true\n        },\n        "merchant_portal": {\n            "can_apply": false\n        }\n    },\n    "applies_to_product_type": "SUBSCRIPTION",\n    "duration": "usage_limit",\n    "duration_usage_limit": "3",\n    "status": "enabled",\n    "usage_limit": "1",\n    "starts_at": "2022-02-15",\n    "ends_at": "2023-12-31",\n    "applies_to_id": "389334466806",\n    "applies_to_resource": "shopify_collection_id"\n}');
try {
 $response = $request->send();
 if ($response->getStatus() == 200) {
   echo $response->getBody();
 }
 else {
   echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
   $response->getReasonPhrase();
 }
}
catch(HTTP_Request2_Exception $e) {
 echo 'Error: ' . $e->getMessage();
}
API Version 2021-11 examples in the next tabs
curl --location --request POST 'https://api.rechargeapps.com/discounts' \
--header 'X-Recharge-Access-Token: {your_access_token}\
--header 'Content-Type: application/json' \
--header 'Cookie: session=eyJfcmNzaSI6eyJkIjpudWxsLCJoIjoiYXBpLnJlY2hhcmdlYXBwcy5jb20iLCJ2IjoyfX0.YgNgDA.Yi-iCfSckUsDo_nBEhoyH5-BGGg' \
--data-raw '{
   "applies_to": {
       "purchase_item_type": "ALL",
       "applies_to_ids": "389334466806",
       "applies_to_resource": "shopify_collection_id"
   },
   "channel_settings": {
       "api": {
           "can_apply": false
       },
       "checkout_page": {
           "can_apply": false
       },
       "customer_portal": {
           "can_apply": true
       },
       "merchant_portal": {
           "can_apply": false
       }
   },
   "code": "TRIPREDEMPTIONSFEB2022",
   "status": "enabled",
   "usage_limits": {
       "max_subsequent_redemptions": "2",
       "first_time_customer_restriction": false,
       "one_application_per_customer": false
   },
   "value": "20",
   "value_type": "fixed_amount"
}'
import requests
import json

url = "https://api.rechargeapps.com/discounts"

payload = json.dumps({
 "applies_to": {
   "purchase_item_type": "ALL",
   "applies_to_ids": "389334466806",
   "applies_to_resource": "shopify_collection_id"
 },
 "channel_settings": {
   "api": {
     "can_apply": False
   },
   "checkout_page": {
     "can_apply": False
   },
   "customer_portal": {
     "can_apply": True
   },
   "merchant_portal": {
     "can_apply": False
   }
 },
 "code": "TRIPREDEMPTIONSFEB2022",
 "status": "enabled",
 "usage_limits": {
   "max_subsequent_redemptions": "2",
   "first_time_customer_restriction": False,
   "one_application_per_customer": False
 },
 "value": "20",
 "value_type": "fixed_amount"
})
headers = {
 'X-Recharge-Access-Token': {your_access_token}',
 'Content-Type': 'application/json',
 'Cookie': 'session=eyJfcmNzaSI6eyJkIjpudWxsLCJoIjoiYXBpLnJlY2hhcmdlYXBwcy5jb20iLCJ2IjoyfX0.YgNgDA.Yi-iCfSckUsDo_nBEhoyH5-BGGg'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
require "uri"
require "json"
require "net/http"

url = URI("https://api.rechargeapps.com/discounts")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Recharge-Access-Token"] = "{your_access_token}"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
  "applies_to": {
    "purchase_item_type": "ALL",
    "applies_to_ids": "389334466806",
    "applies_to_resource": "shopify_collection_id"
  },
  "channel_settings": {
    "api": {
      "can_apply": false
    },
    "checkout_page": {
      "can_apply": false
    },
    "customer_portal": {
      "can_apply": true
    },
    "merchant_portal": {
      "can_apply": false
    }
  },
  "code": "NEWCUSTOMERDISCOUNTFEB2022",
  "status": "enabled",
  "usage_limits": {
    "max_subsequent_redemptions": "3",
    "first_time_customer_restriction": false,
    "one_application_per_customer": false
  },
  "value": "20",
  "value_type": "percentage"
})

response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/discounts');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
 'follow_redirects' => TRUE
));
$request->setHeader(array(
 'X-Recharge-Access-Token' => '{your_access_token}',
 'Content-Type' => 'application/json',
));
$request->setBody('{\n    "applies_to": {\n        "purchase_item_type": "ALL",\n        "applies_to_ids": "389334466806",\n        "applies_to_resource": "shopify_collection_id"\n    },\n    "channel_settings": {\n        "api": {\n            "can_apply": false\n        },\n        "checkout_page": {\n            "can_apply": false\n        },\n        "customer_portal": {\n            "can_apply": true\n        },\n        "merchant_portal": {\n            "can_apply": false\n        }\n    },\n    "code": "NEWCUSTOMERDISCOUNTFEB2022",\n    "status": "enabled",\n    "usage_limits": {\n        "max_subsequent_redemptions" : "3",\n        "first_time_customer_restriction": false,\n        "one_application_per_customer": false\n    },\n    "value": "20",\n    "value_type": "percentage"\n}');
try {
 $response = $request->send();
 if ($response->getStatus() == 200) {
   echo $response->getBody();
 }
 else {
   echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
   $response->getReasonPhrase();
 }
}
catch(HTTP_Request2_Exception $e) {
 echo 'Error: ' . $e->getMessage();
}

     Parameters explained

2021-012021-11


  • value - value of the discount

  • discount_type - type of discount

  • customer_portal - the Customer Portal channel

  • applies_to_product_type - specifies whether the discount applies to onetimes, subscriptions, or all purchase types

  • duration - specifies whether there is a usage limit for the discount

  • duration usage limit - sets the maximum number of times the discount can be applied

  • applies to_id - the product or collection that the discount can be applied to

  • applies_to_resource - the resource that the product or collection belongs to




  • purchase_item_type - specifies that this discount can be applied to all orders

  • applies to_id - the product that the discount can be applied to

  • applies_to_resource - the resource that the product or collection belongs to

  • customer_portal - boolean value that specifies whether the discount can be applied in the Customer Portal channel

  • max_subsequent_redemptions - the number of redemptions that can be applied after the first redemption

  • value - value of the discount

  • value_type - the type of discount being created



Need Help? Contact Us