Swap a subscription product
This guide covers how to change the product variant of a subscription.
SKU swapping and variant swapping are terms that are used interchangeably and represent the same action. See Adding or swapping a product or SKU to understand how swaps are actioned in the merchant portal and in bulk.
Platform:
- Custom
Before you start
- By default, a prepaid subscription cannot be swapped unless the
override
parameter is passed and set totrue
. - One-time items cannot be swapped
- Use
use_shopify_variant_defaults
parameter set to "true” if you wantprice
to be updated accordingly with values from corresponding Shopify product.
Swap a subscription product
When you are looking to swap a subscription product you have two options:
-
Option 1: Leave the control to Recharge. All you need to do is pass the new
shopify_variant_id
. Recharge will then take care of pulling the other parameters based on theshopify_variant_id
provided.
Except if the flagsku_override
is set totrue
in which case the sku will not be updated -
Option 2: You want to control some of the fields to be updated. In which case pass the new
shopify_variant_id
and any other field you want to update as part of the update call. We will only pull from Shopify the fields you have note specified
Simple swap example
curl -X PUT \
https://api.rechargeapps.com/subscriptions/27363808 \
-H 'Content-Type: application/json' \
-H 'X-Recharge-Access-Token: your_api_token' \
-d '{
"charge_interval_frequency": "30",
"next_charge_scheduled_at": "2020-08-02",
"order_interval_frequency": "15",
"order_interval_unit": "day",
"quantity": 5,
"shopify_variant_id": 32309455192167
}'
import requests
import json
headers = {
"Content-Type": "application/json",
"X-Recharge-Access-Token": "your_api_token"
}
url = "https://api.rechargeapps.com/subscriptions/27363808"
data = {
"charge_interval_frequency": "30",
"next_charge_scheduled_at": "2020-08-02",
"order_interval_frequency": "15",
"order_interval_unit": "day",
"quantity": 5,
"shopify_variant_id": 32309455192167
}
result = requests.put(url, data=json.dumps(data), headers=headers)
print(json.dumps(json.loads(result.text), indent=2))
$request = new HttpRequest();
$request->setUrl('https://api.rechargeapps.com/subscriptions/27363808');
$request->setMethod(HTTP_METH_PUT);
$request->setHeaders(array(
'Content-Type' => 'application/json',
'X-Recharge-Access-Token' => 'your_api_token'
));
$request->setBody('{
"charge_interval_frequency": "30",
"next_charge_scheduled_at": "2020-08-02",
"order_interval_frequency": "15",
"order_interval_unit": "day",
"quantity": 5,
"shopify_variant_id": 32309455192167
}');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
require 'net/http'
require 'uri'
require 'json'
url = URI("https://api.rechargeapps.com/subscriptions/27363808")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request["X-Recharge-Access-Token"] = 'your_api_token'
request.body = {
"charge_interval_frequency": "30",
"next_charge_scheduled_at": "2020-08-02",
"order_interval_frequency": "15",
"order_interval_unit": "day",
"quantity": 5,
"shopify_variant_id": 32309455192167
}.to_json
response = http.request(request)
puts response.read_body
Subscription object
A subscription object contains the following product details:
product_title
recharge_product_id
shopify_product_id
shopify_variant_id
sku
*sku_override
variant_title
Updated 8 months ago