Subscriptions
Create Subscription
Create a new subscription
POST
/
v1
/
subscriptions
Create a subscription
curl --request POST \
--url https://billing.example.com/v1/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"plan_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"entity_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"coupon_code": "<string>",
"start_date": "2023-11-07T05:31:56Z",
"trial_days": 1
}
'import requests
url = "https://billing.example.com/v1/subscriptions"
payload = {
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"plan_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"entity_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"coupon_code": "<string>",
"start_date": "2023-11-07T05:31:56Z",
"trial_days": 1
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customer_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
plan_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
entity_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
coupon_code: '<string>',
start_date: '2023-11-07T05:31:56Z',
trial_days: 1
})
};
fetch('https://billing.example.com/v1/subscriptions', 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",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'plan_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'entity_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'coupon_code' => '<string>',
'start_date' => '2023-11-07T05:31:56Z',
'trial_days' => 1
]),
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"
payload := strings.NewReader("{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"entity_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"coupon_code\": \"<string>\",\n \"start_date\": \"2023-11-07T05:31:56Z\",\n \"trial_days\": 1\n}")
req, _ := http.NewRequest("POST", 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.post("https://billing.example.com/v1/subscriptions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"entity_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"coupon_code\": \"<string>\",\n \"start_date\": \"2023-11-07T05:31:56Z\",\n \"trial_days\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/subscriptions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"entity_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"coupon_code\": \"<string>\",\n \"start_date\": \"2023-11-07T05:31:56Z\",\n \"trial_days\": 1\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>"
}
}Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
customer_id | string | Yes | Customer ID |
plan_id | string | Yes | Plan ID |
entity_id | string (uuid) | No | Multi-Entity Books: the issuing legal entity. Omit for the tenant’s primary entity |
coupon_code | string | No | Coupon code to apply |
start_date | string | No | Start date (ISO 8601); defaults to now |
trial_days | integer | No | Days > 0 start the subscription in trialing; it converts to active (issuing its first invoice) when the trial ends |
billing_anchor_type | string | No | acquisition (default) or first_of_month |
payment_terms | string | No | net0, net15, net30, or net60 |
Example Request
curl -X POST https://api.recurso.dev/v1/subscriptions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"customer_id": "cust_abc123",
"plan_id": "plan_pro"
}'
Response
{
"id": "sub_xyz789",
"object": "subscription",
"customer_id": "cust_abc123",
"plan_id": "plan_pro",
"status": "created",
"quantity": 1,
"current_period_start": "2024-01-15T00:00:00Z",
"current_period_end": "2024-02-15T00:00:00Z",
"cancel_at_period_end": false,
"created_at": "2024-01-15T10:30:00Z"
}
Activation issues the subscription’s first invoice. Collect it on the hosted
checkout page —
https://api.recurso.dev/checkout/{invoice_id} (gateway
chosen from the invoice currency) — or automatically via a saved mandate.
Find the invoice with GET /v1/invoices?subscription_id=....Errors
| Status | Code | When | Fix |
|---|---|---|---|
| 400 | validation_failed | The request body is not valid JSON or fails binding. | Send a well-formed JSON body with customer_id and plan_id. |
| 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 referenced customer or plan does not exist in your tenant. | Verify customer_id and plan_id; cross-tenant IDs also return 404. |
Authorizations
Tenant API key obtained from POST /auth/register or POST /v1/developer/keys.
Body
application/json
Multi-Entity Books: the issuing legal entity. Omit for the tenant's primary entity.
Available options:
acquisition, first_of_month Available options:
net0, net15, net30, net60 When greater than zero, the subscription starts in trialing and converts to active (generating its first invoice) when the trial ends.
Required range:
x >= 0Response
Subscription created.
Available options:
trialing, active, past_due, paused, canceled, unpaid ⌘I
Create a subscription
curl --request POST \
--url https://billing.example.com/v1/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"plan_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"entity_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"coupon_code": "<string>",
"start_date": "2023-11-07T05:31:56Z",
"trial_days": 1
}
'import requests
url = "https://billing.example.com/v1/subscriptions"
payload = {
"customer_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"plan_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"entity_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"coupon_code": "<string>",
"start_date": "2023-11-07T05:31:56Z",
"trial_days": 1
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customer_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
plan_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
entity_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
coupon_code: '<string>',
start_date: '2023-11-07T05:31:56Z',
trial_days: 1
})
};
fetch('https://billing.example.com/v1/subscriptions', 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",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'plan_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'entity_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'coupon_code' => '<string>',
'start_date' => '2023-11-07T05:31:56Z',
'trial_days' => 1
]),
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"
payload := strings.NewReader("{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"entity_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"coupon_code\": \"<string>\",\n \"start_date\": \"2023-11-07T05:31:56Z\",\n \"trial_days\": 1\n}")
req, _ := http.NewRequest("POST", 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.post("https://billing.example.com/v1/subscriptions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"entity_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"coupon_code\": \"<string>\",\n \"start_date\": \"2023-11-07T05:31:56Z\",\n \"trial_days\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/subscriptions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customer_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"plan_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"entity_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"coupon_code\": \"<string>\",\n \"start_date\": \"2023-11-07T05:31:56Z\",\n \"trial_days\": 1\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>"
}
}