Subscriptions
Update Subscription
Update an existing subscription
PUT
/
v1
/
subscriptions
/
{id}
Change a subscription's plan (upgrade/downgrade)
curl --request PUT \
--url https://billing.example.com/v1/subscriptions/{id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"plan_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'import requests
url = "https://billing.example.com/v1/subscriptions/{id}"
payload = { "plan_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({plan_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a'})
};
fetch('https://billing.example.com/v1/subscriptions/{id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://billing.example.com/v1/subscriptions/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'plan_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://billing.example.com/v1/subscriptions/{id}"
payload := strings.NewReader("{\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://billing.example.com/v1/subscriptions/{id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/subscriptions/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"tenant_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"plan_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "trialing",
"current_period_start": "2023-11-07T05:31:56Z",
"current_period_end": "2023-11-07T05:31:56Z",
"cancel_at_period_end": true,
"canceled_at": "2023-11-07T05:31:56Z",
"cancellation_reason": "<string>",
"cancellation_feedback": "<string>",
"billing_anchor": "2023-11-07T05:31:56Z",
"billing_anchor_type": "<string>",
"billing_anchor_day": 123,
"payment_terms": "<string>",
"coupon_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"reference_id": "<string>",
"mandate_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"razorpay_subscription_id": "<string>",
"stripe_subscription_id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The subscription ID |
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
plan_id | string | No | New plan ID to switch to |
quantity | integer | No | Updated seat or unit quantity |
proration_behavior | string | No | create_prorations, none, or always_invoice |
metadata | object | No | Custom key-value data |
Example Request
curl -X PUT https://api.recurso.dev/v1/subscriptions/sub_xyz789 \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"plan_id": "plan_enterprise_01",
"quantity": 10,
"proration_behavior": "create_prorations",
"metadata": {
"upgraded_by": "admin@acme.com"
}
}'
Response
{
"id": "sub_xyz789",
"object": "subscription",
"customer_id": "cust_abc123",
"plan_id": "plan_enterprise_01",
"status": "active",
"quantity": 10,
"current_period_start": "2024-03-15T00:00:00Z",
"current_period_end": "2024-04-15T00:00:00Z",
"cancel_at_period_end": false,
"proration_behavior": "create_prorations",
"metadata": {
"upgraded_by": "admin@acme.com"
},
"created_at": "2024-03-01T10:30:00Z",
"updated_at": "2024-03-20T16:45:00Z"
}
When changing plans with
proration_behavior set to create_prorations, a credit is issued for the unused portion of the current plan and a charge is created for the new plan.Errors
| Status | Code | When | Fix |
|---|---|---|---|
| 400 | validation_failed | id is not a valid UUID, or the request body is malformed JSON. | Pass the subscription’s UUID and a valid JSON body. |
| 401 | unauthorized | API key missing or invalid (invalid_api_key), or a live/test mode mismatch (key_mode_mismatch). | Send Authorization: Bearer <api_key> with a key for the right mode. |
| 404 | not_found | The subscription or the target plan does not exist in your tenant. | Verify both IDs; preview the change first with GET /v1/subscriptions/{id}/preview-change?plan_id=.... |
Authorizations
Tenant API key obtained from POST /auth/register or POST /v1/developer/keys.
Path Parameters
Body
application/json
Response
Updated subscription.
Available options:
trialing, active, past_due, paused, canceled, unpaid ⌘I
Change a subscription's plan (upgrade/downgrade)
curl --request PUT \
--url https://billing.example.com/v1/subscriptions/{id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"plan_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'import requests
url = "https://billing.example.com/v1/subscriptions/{id}"
payload = { "plan_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({plan_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a'})
};
fetch('https://billing.example.com/v1/subscriptions/{id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://billing.example.com/v1/subscriptions/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'plan_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://billing.example.com/v1/subscriptions/{id}"
payload := strings.NewReader("{\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://billing.example.com/v1/subscriptions/{id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/subscriptions/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"tenant_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"plan_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "trialing",
"current_period_start": "2023-11-07T05:31:56Z",
"current_period_end": "2023-11-07T05:31:56Z",
"cancel_at_period_end": true,
"canceled_at": "2023-11-07T05:31:56Z",
"cancellation_reason": "<string>",
"cancellation_feedback": "<string>",
"billing_anchor": "2023-11-07T05:31:56Z",
"billing_anchor_type": "<string>",
"billing_anchor_day": 123,
"payment_terms": "<string>",
"coupon_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"reference_id": "<string>",
"mandate_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"razorpay_subscription_id": "<string>",
"stripe_subscription_id": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}