curl --request POST \
--url https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"anchor": "2023-11-07T05:31:56Z",
"items": [
{}
]
}
'import requests
url = "https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions"
payload = {
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"anchor": "2023-11-07T05:31:56Z",
"items": [{}]
}
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({
customerId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
productVersionId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
anchor: '2023-11-07T05:31:56Z',
items: [{}]
})
};
fetch('https://api-sandbox.beinfi.com/billing/products/{productID}/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://api-sandbox.beinfi.com/billing/products/{productID}/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([
'customerId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'productVersionId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'anchor' => '2023-11-07T05:31:56Z',
'items' => [
[
]
]
]),
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://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions"
payload := strings.NewReader("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\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://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.beinfi.com/billing/products/{productID}/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 \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"subscription": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "trialing",
"billingCycle": "weekly",
"collectionMethod": "charge_automatically",
"billingMode": "arrears",
"anchor": "2023-11-07T05:31:56Z",
"nextBillingDate": "2023-11-07T05:31:56Z",
"startedAt": "2023-11-07T05:31:56Z",
"canceledAt": "2023-11-07T05:31:56Z",
"items": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"kind": "recurring_fee",
"timing": "advance",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"createdAt": "2023-11-07T05:31:56Z",
"canceledAt": "2023-11-07T05:31:56Z"
}
]
},
"period": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"subscriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"periodStart": "2023-11-07T05:31:56Z",
"periodEnd": "2023-11-07T05:31:56Z",
"status": "open",
"invoiceId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"errors": [
{
"field": "<string>",
"value": "<string>",
"constraint": "<string>",
"description": "<string>"
}
]
}Create a subscription
Subscribes the customer to the product and opens the first billing period. The response carries the subscription and that period.
customerId is the customer’s product enrollment id (from POST /metering/products/{productID}/customers), not the customer id.
curl --request POST \
--url https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"anchor": "2023-11-07T05:31:56Z",
"items": [
{}
]
}
'import requests
url = "https://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions"
payload = {
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"anchor": "2023-11-07T05:31:56Z",
"items": [{}]
}
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({
customerId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
productVersionId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
anchor: '2023-11-07T05:31:56Z',
items: [{}]
})
};
fetch('https://api-sandbox.beinfi.com/billing/products/{productID}/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://api-sandbox.beinfi.com/billing/products/{productID}/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([
'customerId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'productVersionId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'anchor' => '2023-11-07T05:31:56Z',
'items' => [
[
]
]
]),
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://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions"
payload := strings.NewReader("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\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://api-sandbox.beinfi.com/billing/products/{productID}/subscriptions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.beinfi.com/billing/products/{productID}/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 \"customerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productVersionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"anchor\": \"2023-11-07T05:31:56Z\",\n \"items\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"subscription": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"customerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "trialing",
"billingCycle": "weekly",
"collectionMethod": "charge_automatically",
"billingMode": "arrears",
"anchor": "2023-11-07T05:31:56Z",
"nextBillingDate": "2023-11-07T05:31:56Z",
"startedAt": "2023-11-07T05:31:56Z",
"canceledAt": "2023-11-07T05:31:56Z",
"items": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"kind": "recurring_fee",
"timing": "advance",
"productVersionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"createdAt": "2023-11-07T05:31:56Z",
"canceledAt": "2023-11-07T05:31:56Z"
}
]
},
"period": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"subscriptionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"periodStart": "2023-11-07T05:31:56Z",
"periodEnd": "2023-11-07T05:31:56Z",
"status": "open",
"invoiceId": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>"
}{
"message": "<string>",
"error_code": "internal_error",
"tracer_id": "<string>",
"errors": [
{
"field": "<string>",
"value": "<string>",
"constraint": "<string>",
"description": "<string>"
}
]
}Authorizations
Your account's secret key: Authorization: Bearer sk_test_… or sk_live_…. Server-side only.
Headers
A unique key per operation (a UUID works). Retrying with the same key returns the original response.
Path Parameters
Product ID.
Body
The customer's enrollment id for this product.
The product version the subscription bills. Defaults to the latest published version.
When the billing cycle starts, which sets the day of later charges. Defaults to the time of creation.
What the subscription bills, item by item. Each item has a kind: recurring_fee (a fixed fee, with timing advance to bill at the start of the period or arrears to bill at the end; defaults to advance), credit_grant (credits granted each cycle) or metered_usage (metered usage, billed at the end of the period). Only recurring_fee takes timing. When omitted, items follow the product's pricing model: a prepaid product bills the fee up front and grants credits; any other bills the fee and usage at the end of the period.
Show child attributes
Show child attributes