Discounts in depth
Summary
This section provides a deeper level of immersion into specific concepts and tasks that are important in understanding how you can leverage Recharge discounts in your store. This section covers the following topics and tasks:
- How to create a discount code using the Merchant Portal
- How to create an automatic discount code via URL and Recharge API
- Detailed discount lifecycle workflow (one-time and recurring)
- Async batches for discount creation
How to create a discount using the Merchant Portal
When you want to create a discount
in the Merchant Portal, there are several filters you can use to refine and limit its application. These filters set the conditions and rules so it is only applied when these conditions are met by customer orders. Once you are logged into the Merchant Portal, click on Discounts in the left pane. When you are taken to the next page, click on the Create discount code button where you can create your discount code and set the conditions and rules. An example of the Create Discount Code page is shown below.

The table below shows the direct mappings between Merchant Portal UI settings and the parameters you can pass in an API request using Recharge API v. 2021-11.
Number | Merchant Portal | Recharge API | Description |
---|---|---|---|
1 | Discount code | code | The name of the discount. |
2 | Type of discount | value_type | The type of discount. |
3 | Applies to | applies_to: resource ids purchase_item_type | The rules that specify how the discount can be applied. |
4 | Channel Controls | channel_settings | The channels (Merchant Portal, Customer Portal, API) where the discount can be applied. |
5 | Application limits | usage_limits: first_time_customer_restriction one_application _per_customer | The rules that designate the number of times a discount can be applied and whether discounts can only be applied for new customers. |
6 | Date Range | starts_at ends_at | The date range for when the discount can be applied. |
How to create an automatic discount via URL and Recharge API
You have the option when working with Recharge discounts to have them automatically applied at time of checkout so customers do not need to enter them manually. There are two ways you can automatically apply discounts to the checkout page:
- Applying a discount automatically via URL (Recharge checkout on Shopify only)
- Applying a discount automatically via Recharge API
Applying a discount automatically via URL
NOTE
Applying an automatic discount via URL requires Recharge checkout on Shopify, as automatic discounts are not supported on the Shopify Checkout Integration or Recharge Checkout on BigCommerce. If you are not using a Recharge checkout on Shopify, ignore this section.
To add an automatic discount code, all you need to do is pass the discount code in the URL. An example URL request is shown below:
/r/checkout?myshopify_domain=bootstrap-dev.myshopify.com&cart_token={your_token}&discount={discount_name}
For more information about automatically applying a discount via URL, refer to the Apply discount code automatically at checkout page.
Applying a discount automatically via Recharge API
NOTE
The checkout endpoint is only available for BigCommerce and Custom integrations. If you want to perform checkouts on Shopify, you must go through Shopify.
To apply a discount automatically using the Recharge API, you may perform the following actions:
- create a new checkout
- update a checkout
NOTE
The checkout object is currently only available for Recharge API version 2021-01. This feature will be available soon for Recharge API version 2021-11.
Create a new checkout
Before creating a checkout
, the discount you want to apply must first exist in Recharge. The first step in automatically applying a discount code to a checkout
via the Recharge API is to create the checkout
. You can apply a discount
in the checkout, update, or process steps.
The example below shows how you can create a checkout
.
curl --location --request POST 'https://api.rechargeapps.com/checkouts' \
--header 'X-Recharge-Access-Token: {your_access_token} \
--header 'Content-Type: application/json' \
--data-raw '{
"analytics_data": {
"utm_params": [{
"utm_campaign": "spring_sale",
"utm_content": "textlink",
"utm_data_source": "website_cookie",
"utm_medium": "cpc",
"utm_source": "google",
"utm_term": "mleko",
"utm_timestamp": "2020-03-05"
}]
},
"discount_code": "POPUS_25",
"email":"[email protected]",
"external_checkout_id": "<cart_token>",
"external_checkout_source": "headless",
"line_items": [
{
"charge_interval_frequency": 5,
"fulfillment_service": "manual",
"order_interval_frequency": 5,
"order_interval_unit": "day",
"product_id": 3,
"quantity": 6,
"requires_shipping": "True",
"taxable": "True",
"variant_id": 3
}
],
"shipping_address": {
"address1": "6419 Ocean Front Walk",
"address2": "Apt 2",
"city": "Los Angeles",
"company": "",
"country": "United States",
"first_name": "Novak",
"last_name": "Djokovic",
"phone": "1-800-800-8000",
"province": "California",
"zip": "90293"
}
}'
import requests
import json
url = "https://api.rechargeapps.com/checkouts"
payload = json.dumps({
"analytics_data": {
"utm_params": [
{
"utm_campaign": "spring_sale",
"utm_content": "textlink",
"utm_data_source": "website_cookie",
"utm_medium": "cpc",
"utm_source": "google",
"utm_term": "mleko",
"utm_timestamp": "2020-03-05"
}
]
},
"discount_code": "POPUS_25",
"email": "[email protected]",
"external_checkout_id": "<cart_token>",
"external_checkout_source": "headless",
"line_items": [
{
"charge_interval_frequency": 5,
"fulfillment_service": "manual",
"order_interval_frequency": 5,
"order_interval_unit": "day",
"product_id": 3,
"quantity": 6,
"requires_shipping": "True",
"taxable": "True",
"variant_id": 3
}
],
"shipping_address": {
"address1": "6419 Ocean Front Walk",
"address2": "Apt 2",
"city": "Los Angeles",
"company": "",
"country": "United States",
"first_name": "Novak",
"last_name": "Djokovic",
"phone": "1-800-800-8000",
"province": "California",
"zip": "90293"
}
})
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 "json"
require "net/http"
url = URI("https://api.rechargeapps.com/checkouts")
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({
"analytics_data": {
"utm_params": [{
"utm_campaign": "spring_sale",
"utm_content": "textlink",
"utm_data_source": "website_cookie",
"utm_medium": "cpc",
"utm_source": "google",
"utm_term": "mleko",
"utm_timestamp": "2020-03-05"
}]
},
"discount_code": "POPUS_25",
"email": "[email protected]",
"external_checkout_id": "<cart_token>",
"external_checkout_source": "headless",
"line_items": [{
"charge_interval_frequency": 5,
"fulfillment_service": "manual",
"order_interval_frequency": 5,
"order_interval_unit": "day",
"product_id": 3,
"quantity": 6,
"requires_shipping": "True",
"taxable": "True",
"variant_id": 3
}],
"shipping_address": {
"address1": "6419 Ocean Front Walk",
"address2": "Apt 2",
"city": "Los Angeles",
"company": "",
"country": "United States",
"first_name": "Novak",
"last_name": "Djokovic",
"phone": "1-800-800-8000",
"province": "California",
"zip": "90293"
}
})
response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/checkouts');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'X-Recharge-Access-Token' => '{your_access_token}',
));
$request->setBody('{\n "analytics_data": {\n "utm_params": [{\n "utm_campaign": "spring_sale",\n "utm_content": "textlink",\n "utm_data_source": "website_cookie",\n "utm_medium": "cpc",\n "utm_source": "google",\n "utm_term": "mleko",\n "utm_timestamp": "2020-03-05"\n }]\n },\n "discount_code": "POPUS_25",\n "email":"someran[email protected]",\n "external_checkout_id": "<cart_token>",\n "external_checkout_source": "headless",\n "line_items": [\n {\n "charge_interval_frequency": 5,\n "fulfillment_service": "manual",\n "order_interval_frequency": 5,\n "order_interval_unit": "day",\n "product_id": 3,\n "quantity": 6,\n "requires_shipping": "True",\n "taxable": "True",\n "variant_id": 3\n }\n ],\n "shipping_address": {\n "address1": "6419 Ocean Front Walk",\n "address2": "Apt 2",\n "city": "Los Angeles",\n "company": "",\n "country": "United States",\n "first_name": "Novak",\n "last_name": "Djokovic",\n "phone": "1-800-800-8000",\n "province": "California",\n "zip": "90293"\n }\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 |
---|
|
Update the checkout with a discount code
When the checkout
has been created, you may update the checkout
with a discount code so it can be applied to the checkout before processing. The example below shows how you can update a checkout
.
curl --location --request PUT 'https://api.rechargeapps.com/checkouts/f34ba13ff3d54b55944d135e0864aaf5' \
--header 'X-Recharge-Access-Token: {your_access_token} \
--header 'Content-Type: application/json' \\
--data-raw '{
"shipping_address": {
"address1": "6419 Ocean Front Walk",
"address2": "",
"city": "Apt 2",
"province": "California",
"first_name": "Novak",
"last_name": "Djokovic",
"zip": "90293",
"company": "Tennis Serbia",
"phone": "1-800-800-8000",
"country": "United States",
"original_shipping_lines": [
{
"price": "43.20",
"code": "Standard Shipping",
"title": "Standard Shipping"
}
],
"shipping_lines_override": null,
"discount_code": "FEB22DISCOUNT"
}
}'
import requests
import json
url = "https://api.rechargeapps.com/checkouts/f34ba13ff3d54b55944d135e0864aaf5"
payload = json.dumps({
"shipping_address": {
"address1": "6419 Ocean Front Walk",
"address2": "",
"city": "Apt 2",
"province": "California",
"first_name": "Novak",
"last_name": "Djokovic",
"zip": "90293",
"company": "Tennis Serbia",
"phone": "1-800-800-8000",
"country": "United States",
"original_shipping_lines": [
{
"price": "43.20",
"code": "Standard Shipping",
"title": "Standard Shipping"
}
],
"shipping_lines_override": None,
"discount_code": "FEB22DISCOUNT"
}
})
headers = {
'X-Recharge-Access-Token': {your_access_token},
'Content-Type': 'application/json',
}
response = requests.request("PUT", url, headers=headers, data=payload)
print(response.text)
require "uri"
require "json"
require "net/http"
url = URI("https://api.rechargeapps.com/checkouts/0e51712b541f4d168486fb87ce8eb87d")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Put.new(url)
request["X-Recharge-Access-Token"] = "{your_access_token}"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"shipping_address": {
"address1": "6419 Ocean Front Walk",
"address2": "",
"city": "Apt 2",
"province": "California",
"first_name": "Novak",
"last_name": "Djokovic",
"zip": "90293",
"company": "Tennis Serbia",
"phone": "1-800-800-8000",
"country": "United States",
"original_shipping_lines": [{
"price": "43.20",
"code": "Standard Shipping",
"title": "Standard Shipping"
}],
"shipping_lines_override": nil,
"discount_code": "FEB22DISCOUNT"
}
})
response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/checkouts/0e51712b541f4d168486fb87ce8eb87d');
$request->setMethod(HTTP_Request2::METHOD_PUT);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'X-Recharge-Access-Token' => '{your_access_token}',
'Content-Type' => 'application/json',
));
$request->setBody('{\n "shipping_address": {\n "address1": "6419 Ocean Front Walk",\n "address2": "",\n "city": "Apt 2",\n "province": "California",\n "first_name": "Novak",\n "last_name": "Djokovic",\n "zip": "90293",\n "company": "Tennis Serbia",\n "phone": "1-800-800-8000",\n "country": "United States",\n "original_shipping_lines": [\n {\n "price": "43.20",\n "code": "Standard Shipping",\n "title": "Standard Shipping"\n }\n ],\n "shipping_lines_override": null,\n "discount_code": "FEB22DISCOUNT"\n }\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 |
---|
|
Detailed Discount Flow
Discounts can be applied in several different ways, depending on whether you want to apply a discount
for a one-time charge, or recurring charge.
There are 3 validations that will happen during the life of the discount:
- At creation, we check that all the 'Required' params were specified before creating the
discount
. - At application, we check that the rules defined for the checkout are being respected by the checkout or charge this discount is supposed to be applied to.
- At recurring charges,for every recurring charge processed we check: does the discount still apply?
The flowchart below illustrates the step-by-step process of how a discount can be applied for these two workflows.

For more detailed information about discount modeling, please refer to the Discount Overview page.
Async batches for discount creation
The Async batches resource can be used for processing large volumes of operations asynchronously, in order to reduce aggregate processing time and network traffic when interacting with many unique objects. For example, a user can leverage this resource to create 1000 discounts with only 3 API requests. Using async batches for discount code creation requires you to perform several steps to accomplish this task. These steps include:
- Creating a batch
- Adding a task list to a batch
- Processing the batch
- Retrieving the batch to verify discount creation
NOTE
Async batches are only available in Recharge API version 2021-01. This feature will be coming soon for API version 2021-11.
Creating a batch
To create a new batch, you need to make a POST
API request to the async_batches
endpoint. This request creates a new ID for the batch that you will need to use in subsequent batch operations.
curl --location --request POST 'https://api.rechargeapps.com/async_batches' \
--header 'X-Recharge-Access-Token: {your_access_token} \
--header 'Content-Type: application/json' \
--data-raw '{
"batch_type": "discount_create"
}'
import requests
import json
url = "https://api.rechargeapps.com/async_batches"
payload = json.dumps({
"batch_type": "discount_create"
})
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/async_batches")
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({
"batch_type": "discount_create"
})
response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/async_batches');
$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 "batch_type": "discount_create"\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 |
---|
|
After you have created the batch, make sure to copy down the batch_id
value. You will need this batch_id
to add tasks to a batch and process the batch. An example of the response with the batch_id
is shown below.

Adding a task to a batch
Once you have created the batch, you need to then add a list of tasks you want performed in the batch, with each task representing a single API request. To add tasks to a batch, you need to make a POST
request to the async_batches
endpoint, with the list of tasks you want to have performed in the body of the request.
NOTE
Be sure to include the
batch_id
in your request.
curl --location --request POST 'https://api.rechargeapps.com/async_batches/{batch_id}/tasks' \
--header 'X-Recharge-Access-Token: {your_access_token} \
--header 'Content-Type: application/json' \
--data-raw '{
"tasks": [
{
"body": {
"code": "indexing",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "maroon",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "web services",
"value": 100,
"discount_type": "shipping",
"duration": "forever",
"status": "enabled"
}
},
{
"body": {
"code": "PCI",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "Cheese",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "overriding",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "bandwidth-monitored",
"value": 100,
"discount_type": "shipping",
"duration": "forever",
"status": "enabled"
}
},
{
"body": {
"code": "Falkland Islands (Malvinas)",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "Computer",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "digital",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
}
]
}'
import requests
import json
url = "https://api.rechargeapps.com/async_batches/{batch_id}/tasks"
payload = json.dumps({
"tasks": [
{
"body": {
"code": "indexing",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "maroon",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "web services",
"value": 100,
"discount_type": "shipping",
"duration": "forever",
"status": "enabled"
}
},
{
"body": {
"code": "PCI",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "Cheese",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "overriding",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "bandwidth-monitored",
"value": 100,
"discount_type": "shipping",
"duration": "forever",
"status": "enabled"
}
},
{
"body": {
"code": "Falkland Islands (Malvinas)",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "Computer",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "digital",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
}
]
})
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/async_batches/763041/tasks")
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({
"tasks": [{
"body": {
"code": "indexing",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "maroon",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "web services",
"value": 100,
"discount_type": "shipping",
"duration": "forever",
"status": "enabled"
}
},
{
"body": {
"code": "PCI",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "Cheese",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "overriding",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "bandwidth-monitored",
"value": 100,
"discount_type": "shipping",
"duration": "forever",
"status": "enabled"
}
},
{
"body": {
"code": "Falkland Islands (Malvinas)",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "Computer",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
},
{
"body": {
"code": "digital",
"discount_type": "shipping",
"duration": "forever",
"status": "enabled",
"value": 100
}
}
]
})
response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/async_batches/763041/tasks');
$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 "tasks": [\n {\n "body": {\n "code": "indexing",\n "discount_type": "shipping",\n "duration": "forever",\n "status": "enabled",\n "value": 100\n }\n },\n {\n "body": {\n "code": "maroon",\n "discount_type": "shipping",\n "duration": "forever",\n "status": "enabled",\n "value": 100\n }\n },\n {\n "body": {\n "code": "web services",\n "value": 100,\n "discount_type": "shipping",\n "duration": "forever",\n "status": "enabled"\n }\n },\n {\n "body": {\n "code": "PCI",\n "discount_type": "shipping",\n "duration": "forever",\n "status": "enabled",\n "value": 100\n }\n },\n {\n "body": {\n "code": "Cheese",\n "discount_type": "shipping",\n "duration": "forever",\n "status": "enabled",\n "value": 100\n }\n },\n {\n "body": {\n "code": "overriding",\n "discount_type": "shipping",\n "duration": "forever",\n "status": "enabled",\n "value": 100\n }\n },\n {\n "body": {\n "code": "bandwidth-monitored",\n "value": 100,\n "discount_type": "shipping",\n "duration": "forever",\n "status": "enabled"\n }\n },\n {\n "body": {\n "code": "Falkland Islands (Malvinas)",\n "discount_type": "shipping",\n "duration": "forever",\n "status": "enabled",\n "value": 100\n }\n },\n {\n "body": {\n "code": "Computer",\n "discount_type": "shipping",\n "duration": "forever",\n "status": "enabled",\n "value": 100\n }\n },\n {\n "body": {\n "code": "digital",\n "discount_type": "shipping",\n "duration": "forever",\n "status": "enabled",\n "value": 100\n }\n }\n ]\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();
}
NOTE
The example above show just some of the parameters you can pass in the request body. For a complete list of parameters that can be passed, refer to the Create Discounts endpoint in the Recharge API Reference Guide.
Parameters explained
2021-01 |
---|
|
Processing the batch
The next step you need to take is to process the batch and have it perform the tasks you just added to it. This requires you to make a POST
request to the async_batches
endpoint like the example below.
curl --location --request POST 'https://api.rechargeapps.com/async_batches/{batch_id}/process' \
--header 'X-Recharge-Access-Token: {your_access_token} \
--header 'Content-Type: application/json' \
--data-raw '{}'
import requests
import json
url = "https://api.rechargeapps.com/async_batches/batch_id/process"
payload = json.dumps({})
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/async_batches/763041/process")
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({})
response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/async_batches/763041/process');
$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('{}');
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();
}
Retrieving the batch to verify discount creation
The final step you want to take is to verify that the batch has been created. You can verify the discounts were created by making a GET
API request to the async_batches
endpoint with the batch_id
, similar to the example below.
curl --location --request GET 'https://api.rechargeapps.com/async_batches/{batch_id} \
--header 'X-Recharge-Access-Token: {your_access_token} \
import requests
url = "https://api.rechargeapps.com/async_batches/{batch_id}"
payload={}
headers = {
'X-Recharge-Access-Token': {your_access_token},
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
require "uri"
require "net/http"
url = URI("https://api.rechargeapps.com/async_batches/763041")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-Recharge-Access-Token"] = "{your_access_token}”
response = https.request(request)
puts response.read_body
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.rechargeapps.com/async_batches/763041');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'X-Recharge-Access-Token' => '{your_access_token}',
));
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();
}
For more detailed information about how you can use the async batches feature, please refer to the Async batches section of the Recharge API Reference Guide.
Discount codes sync with other platforms
The discount code sync feature is an efficient tool that enables you to bulk import discount codes from Shopify into Recharge. For more information on how discount code synchronization works, refer to the Using the Shopify Discount Import feature support article.
This eliminates the manual process of having to create a CSV file and then contacting the Recharge Support team, or building out your own integration.
When creating discount codes in bulk, you can click a few buttons in Recharge to import these discount codes into Recharge.
When using this feature, be aware of the following conditions:
- This is a one-way import from Shopify into Recharge. This feature does not make any updates in Shopify.
- There are certain discount codes that cannot be imported from Shopify. For a list of unsupported discount codes, refer to the Using the Shopify Discount Import feature page.
- Discount codes cannot be kept in sync automatically because Shopify does not have webooks available for discounts.
- There is a limit of 100,000 discount codes for each import. If you need to import more than 100,000 discount codes in an import, refer to the Managing discount codes in bulk page and then contact Recharge Support.
Updated 6 months ago