Skip to main content
POST
/
v1
/
subscriptions
Create
curl --request POST \
  --url https://{defaultHost}/v1/subscriptions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "subscription": {
    "customer": "3ae30b77-3fad-4271-9929-9949349228e3",
    "price": "443a121c-8272-4e84-b1af-2d2b87f18880",
    "payment_method": "af64489f-99e0-4f50-ac57-756f5619a382"
  }
}
'
import requests

url = "https://{defaultHost}/v1/subscriptions"

payload = { "subscription": {
"customer": "3ae30b77-3fad-4271-9929-9949349228e3",
"price": "443a121c-8272-4e84-b1af-2d2b87f18880",
"payment_method": "af64489f-99e0-4f50-ac57-756f5619a382"
} }
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: '3ae30b77-3fad-4271-9929-9949349228e3',
price: '443a121c-8272-4e84-b1af-2d2b87f18880',
payment_method: 'af64489f-99e0-4f50-ac57-756f5619a382'
}
})
};

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' => '3ae30b77-3fad-4271-9929-9949349228e3',
'price' => '443a121c-8272-4e84-b1af-2d2b87f18880',
'payment_method' => 'af64489f-99e0-4f50-ac57-756f5619a382'
]
]),
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\": \"3ae30b77-3fad-4271-9929-9949349228e3\",\n \"price\": \"443a121c-8272-4e84-b1af-2d2b87f18880\",\n \"payment_method\": \"af64489f-99e0-4f50-ac57-756f5619a382\"\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\": \"3ae30b77-3fad-4271-9929-9949349228e3\",\n \"price\": \"443a121c-8272-4e84-b1af-2d2b87f18880\",\n \"payment_method\": \"af64489f-99e0-4f50-ac57-756f5619a382\"\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\": \"3ae30b77-3fad-4271-9929-9949349228e3\",\n \"price\": \"443a121c-8272-4e84-b1af-2d2b87f18880\",\n \"payment_method\": \"af64489f-99e0-4f50-ac57-756f5619a382\"\n }\n}"

response = http.request(request)
puts response.read_body
{
  "id": "a14cb818-ae6b-4806-b5b7-2c7608c45a94",
  "object": "subscription",
  "ad_hoc_amount": null,
  "affiliation_expires_at": null,
  "cancel_at_period_end": false,
  "currency": "usd",
  "current_period_end_at": 1785077907,
  "current_period_start_at": 1782485907,
  "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/a14cb818-ae6b-4806-b5b7-2c7608c45a94",
  "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": "df28c6a7-615d-4570-a3cc-7aa39358cd0f",
  "customer": "3ae30b77-3fad-4271-9929-9949349228e3",
  "discount": null,
  "manual_payment_method": null,
  "payment_method": "af64489f-99e0-4f50-ac57-756f5619a382",
  "price": "443a121c-8272-4e84-b1af-2d2b87f18880",
  "purchase": "53d35f8c-963f-423a-bb67-2f50e7124894",
  "shipping_method": null,
  "variant": null,
  "created_at": 1782485907,
  "updated_at": 1782485907
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
subscription
object

Response

200 - application/json

Success

id
string | null

The UUID of the specific object.

object
string

A string describing the object type returned.

ad_hoc_amount
integer | null

The amount to use for this subscription when the associated price is ad_hoc=true.

affiliation_expires_at
integer | null

Time at which the affiliation will expire.

cancel_at_period_end
boolean

If the subscription is set to cancel at the end of the current period. You can use this attribute to determine whether a subscription that has a status of active is scheduled to be canceled at the end of the current period.

live_mode
boolean

Set to true if this subscription is in live mode, and set to false if it is in test mode.

manual_payment
boolean

Whether or not this subscription should finalize checkouts during renewal with the manual_payment=true option.

quantity
integer

The quantity of products being purchased.

restore_at
integer | null

The time at which this subscription will automatically be restored. This can only be set if the subscription is canceled or set to cancel at period end.

restart_on_completed
boolean

Whether installment subscriptions should be automatically restarted when they reach the completed state. When the subscription is created, this value will be inherited from the price restart_subscription_on_completed value.

tax_enabled
boolean

Whether or not tax is enabled for this subscription. This will default to the account's tax_protocol.tax_enabled value when the subscription is created.

trial_end_at
integer | null

If the subscription has a trial, the end of that trial.

metadata
object

Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.

current_period_end_at
integer | null

End of the current period that the subscription is in. At the end of this period, a new period will be created. This will be null when the subscription has a one-time price.

current_period_start_at
integer | null

Start of the current period that the subscription is in.

ended_at
integer | null

If the subscription has ended, the date the subscription ended.

finite
boolean

Whether or not this subscription belongs to a price with a set recurring_period_count, meaning it has a defined end.

last_renewal_reminder_sent_at
integer | null

Time at which the last renewal reminder notification sent. Measured in seconds since the Unix epoch.

pending_update
object
portal_url
string | null

A URL that will redirect to this subscription's correct portal page (hosted or external).

price_readonly
boolean

Whether or not the price of this subscription can be modified. If true, the price is locked and cannot be changed

remaining_period_count
integer | null

The number of periods remaining before this subscription ends. This count is reduced when a period is paid.

subtotal_amount
integer

Total of the subscription before discounts or taxes are applied.

status
string

The current status of this subscription, which can be one of incomplete, trialing, active, past_due, canceled, or completed.

affiliation
object | null

The affiliation associated with this subscription.

current_cancellation_act

Expandable – The associated cancellation act ID.

current_period

Expandable – The associated period ID.

customer

Expandable – The associated customer ID.

discount

Expandable – The associated discount ID.

manual_payment_method

Expandable – The associated manual payment method ID.

payment_method

Expandable – The associated payment method ID.

periods

Expandable – Property not returned unless expanded.

price

Expandable – The associated price ID.

purchase

Expandable – The associated purchase ID.

shipping_method

Expandable – The associated shipping method ID.

variant

Expandable – The associated variant ID.

variant_options
array | null

An array of the associated variant's options.

created_at
integer | null

Time at which the object was created. Measured in seconds since the Unix epoch.

updated_at
integer | null

Time at which the object was last updated. Measured in seconds since the Unix epoch.