Create
curl --request POST \
--url https://{defaultHost}/v1/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"subscription": {
"customer": "78c1b383-6d1f-4788-826a-96c33c17a693",
"price": "57c55a4d-80f6-434c-a93d-6591700f920c",
"payment_method": "288c7ad7-89e7-4947-9389-be8c43549a0b"
}
}
'import requests
url = "https://{defaultHost}/v1/subscriptions"
payload = { "subscription": {
"customer": "78c1b383-6d1f-4788-826a-96c33c17a693",
"price": "57c55a4d-80f6-434c-a93d-6591700f920c",
"payment_method": "288c7ad7-89e7-4947-9389-be8c43549a0b"
} }
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({
subscription: {
customer: '78c1b383-6d1f-4788-826a-96c33c17a693',
price: '57c55a4d-80f6-434c-a93d-6591700f920c',
payment_method: '288c7ad7-89e7-4947-9389-be8c43549a0b'
}
})
};
fetch('https://{defaultHost}/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://{defaultHost}/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([
'subscription' => [
'customer' => '78c1b383-6d1f-4788-826a-96c33c17a693',
'price' => '57c55a4d-80f6-434c-a93d-6591700f920c',
'payment_method' => '288c7ad7-89e7-4947-9389-be8c43549a0b'
]
]),
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://{defaultHost}/v1/subscriptions"
payload := strings.NewReader("{\n \"subscription\": {\n \"customer\": \"78c1b383-6d1f-4788-826a-96c33c17a693\",\n \"price\": \"57c55a4d-80f6-434c-a93d-6591700f920c\",\n \"payment_method\": \"288c7ad7-89e7-4947-9389-be8c43549a0b\"\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://{defaultHost}/v1/subscriptions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"subscription\": {\n \"customer\": \"78c1b383-6d1f-4788-826a-96c33c17a693\",\n \"price\": \"57c55a4d-80f6-434c-a93d-6591700f920c\",\n \"payment_method\": \"288c7ad7-89e7-4947-9389-be8c43549a0b\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{defaultHost}/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 \"subscription\": {\n \"customer\": \"78c1b383-6d1f-4788-826a-96c33c17a693\",\n \"price\": \"57c55a4d-80f6-434c-a93d-6591700f920c\",\n \"payment_method\": \"288c7ad7-89e7-4947-9389-be8c43549a0b\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "78bf2e89-8d3a-43e0-836c-d45cac03c121",
"object": "subscription",
"ad_hoc_amount": null,
"affiliation_expires_at": null,
"cancel_at_period_end": false,
"currency": "usd",
"current_period_end_at": 1796389006,
"current_period_start_at": 1793797006,
"ended_at": null,
"finite": false,
"last_renewal_reminder_sent_at": null,
"live_mode": true,
"manual_payment": false,
"metadata": {},
"pending_update": {},
"price_readonly": false,
"portal_url": "http://app.example.com/portal_redirect/subscriptions/78bf2e89-8d3a-43e0-836c-d45cac03c121",
"quantity": 1,
"remaining_period_count": null,
"restart_on_completed": false,
"restore_at": null,
"subtotal_amount": 2900,
"status": "incomplete",
"tax_enabled": false,
"trial_end_at": null,
"trial_start_at": null,
"variant_options": null,
"affiliation": null,
"current_cancellation_act": null,
"current_period": "1d39e7d5-9843-41f5-8fdd-197d2f4744f5",
"customer": "78c1b383-6d1f-4788-826a-96c33c17a693",
"discount": null,
"manual_payment_method": null,
"payment_method": "288c7ad7-89e7-4947-9389-be8c43549a0b",
"price": "57c55a4d-80f6-434c-a93d-6591700f920c",
"purchase": "e63fda4a-edb5-420f-8b96-81a0062a8740",
"shipping_method": null,
"variant": null,
"created_at": 1793797006,
"updated_at": 1793797006
}Subscriptions
Create
Creates a new subscription.
POST
/
v1
/
subscriptions
Create
curl --request POST \
--url https://{defaultHost}/v1/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"subscription": {
"customer": "78c1b383-6d1f-4788-826a-96c33c17a693",
"price": "57c55a4d-80f6-434c-a93d-6591700f920c",
"payment_method": "288c7ad7-89e7-4947-9389-be8c43549a0b"
}
}
'import requests
url = "https://{defaultHost}/v1/subscriptions"
payload = { "subscription": {
"customer": "78c1b383-6d1f-4788-826a-96c33c17a693",
"price": "57c55a4d-80f6-434c-a93d-6591700f920c",
"payment_method": "288c7ad7-89e7-4947-9389-be8c43549a0b"
} }
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({
subscription: {
customer: '78c1b383-6d1f-4788-826a-96c33c17a693',
price: '57c55a4d-80f6-434c-a93d-6591700f920c',
payment_method: '288c7ad7-89e7-4947-9389-be8c43549a0b'
}
})
};
fetch('https://{defaultHost}/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://{defaultHost}/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([
'subscription' => [
'customer' => '78c1b383-6d1f-4788-826a-96c33c17a693',
'price' => '57c55a4d-80f6-434c-a93d-6591700f920c',
'payment_method' => '288c7ad7-89e7-4947-9389-be8c43549a0b'
]
]),
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://{defaultHost}/v1/subscriptions"
payload := strings.NewReader("{\n \"subscription\": {\n \"customer\": \"78c1b383-6d1f-4788-826a-96c33c17a693\",\n \"price\": \"57c55a4d-80f6-434c-a93d-6591700f920c\",\n \"payment_method\": \"288c7ad7-89e7-4947-9389-be8c43549a0b\"\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://{defaultHost}/v1/subscriptions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"subscription\": {\n \"customer\": \"78c1b383-6d1f-4788-826a-96c33c17a693\",\n \"price\": \"57c55a4d-80f6-434c-a93d-6591700f920c\",\n \"payment_method\": \"288c7ad7-89e7-4947-9389-be8c43549a0b\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{defaultHost}/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 \"subscription\": {\n \"customer\": \"78c1b383-6d1f-4788-826a-96c33c17a693\",\n \"price\": \"57c55a4d-80f6-434c-a93d-6591700f920c\",\n \"payment_method\": \"288c7ad7-89e7-4947-9389-be8c43549a0b\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "78bf2e89-8d3a-43e0-836c-d45cac03c121",
"object": "subscription",
"ad_hoc_amount": null,
"affiliation_expires_at": null,
"cancel_at_period_end": false,
"currency": "usd",
"current_period_end_at": 1796389006,
"current_period_start_at": 1793797006,
"ended_at": null,
"finite": false,
"last_renewal_reminder_sent_at": null,
"live_mode": true,
"manual_payment": false,
"metadata": {},
"pending_update": {},
"price_readonly": false,
"portal_url": "http://app.example.com/portal_redirect/subscriptions/78bf2e89-8d3a-43e0-836c-d45cac03c121",
"quantity": 1,
"remaining_period_count": null,
"restart_on_completed": false,
"restore_at": null,
"subtotal_amount": 2900,
"status": "incomplete",
"tax_enabled": false,
"trial_end_at": null,
"trial_start_at": null,
"variant_options": null,
"affiliation": null,
"current_cancellation_act": null,
"current_period": "1d39e7d5-9843-41f5-8fdd-197d2f4744f5",
"customer": "78c1b383-6d1f-4788-826a-96c33c17a693",
"discount": null,
"manual_payment_method": null,
"payment_method": "288c7ad7-89e7-4947-9389-be8c43549a0b",
"price": "57c55a4d-80f6-434c-a93d-6591700f920c",
"purchase": "e63fda4a-edb5-420f-8b96-81a0062a8740",
"shipping_method": null,
"variant": null,
"created_at": 1793797006,
"updated_at": 1793797006
}Authorizations
Response
200 - application/json
Success
Expandable – The associated cancellation act ID.
Expandable – The associated period ID.
Expandable – The associated customer ID.
Expandable – The associated discount ID.
Expandable – The associated manual payment method ID.
Expandable – The associated payment method ID.
Expandable – Property not returned unless expanded.
Expandable – The associated price ID.
Expandable – The associated purchase ID.
Expandable – The associated shipping method ID.
Expandable – The associated variant ID.
Was this page helpful?