Swap a subscription product
Change the product variant of a subscription.
A subscription object contains the following product details:
product_title
recharge_product_id
shopify_product_id
shopify_variant_id
sku
*sku_override
variant_title
When you are looking to swap a subscription product you have two options:
-
Option 1 leave the control to us. 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
Updating the price
Please use
use_shopify_variant_defaults
parameter set to "true” if you wantprice
to be updated accordingly with values from corresponding Shopify product.
Swapping product on a prepaid subscription
By default, a prepaid subscription cannot be swapped unless the
override
parameter is passed and set totrue
.
Onetimes
Onetime items cannot be swapped
Quick example of simple swap
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
Updated almost 2 years ago