curl --request POST \
--url https://api.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants \
--header 'Content-Type: application/json' \
--header 'X-SALESBRICKS-KEY: <api-key>' \
--data '
{
"lines": [
{
"brick_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"quantity": "<string>",
"unit_price": "<string>"
}
],
"expires_at": "2023-12-25",
"effective_at": "2023-12-25",
"charge_immediately": false
}
'import requests
url = "https://api.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants"
payload = {
"lines": [
{
"brick_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"quantity": "<string>",
"unit_price": "<string>"
}
],
"expires_at": "2023-12-25",
"effective_at": "2023-12-25",
"charge_immediately": False
}
headers = {
"X-SALESBRICKS-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-SALESBRICKS-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
lines: [
{
brick_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
quantity: '<string>',
unit_price: '<string>'
}
],
expires_at: '2023-12-25',
effective_at: '2023-12-25',
charge_immediately: false
})
};
fetch('https://api.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants', 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.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants",
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([
'lines' => [
[
'brick_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'quantity' => '<string>',
'unit_price' => '<string>'
]
],
'expires_at' => '2023-12-25',
'effective_at' => '2023-12-25',
'charge_immediately' => false
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-SALESBRICKS-KEY: <api-key>"
],
]);
$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.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants"
payload := strings.NewReader("{\n \"lines\": [\n {\n \"brick_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"quantity\": \"<string>\",\n \"unit_price\": \"<string>\"\n }\n ],\n \"expires_at\": \"2023-12-25\",\n \"effective_at\": \"2023-12-25\",\n \"charge_immediately\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-SALESBRICKS-KEY", "<api-key>")
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.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants")
.header("X-SALESBRICKS-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"lines\": [\n {\n \"brick_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"quantity\": \"<string>\",\n \"unit_price\": \"<string>\"\n }\n ],\n \"expires_at\": \"2023-12-25\",\n \"effective_at\": \"2023-12-25\",\n \"charge_immediately\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-SALESBRICKS-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"lines\": [\n {\n \"brick_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"quantity\": \"<string>\",\n \"unit_price\": \"<string>\"\n }\n ],\n \"expires_at\": \"2023-12-25\",\n \"effective_at\": \"2023-12-25\",\n \"charge_immediately\": false\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"grant_type": "TOP_UP",
"subscription_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "PENDING",
"activates": "ON_PAYMENT",
"effective_at": "2023-12-25",
"activated_at": "2023-11-07T05:31:56Z",
"voided_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"invoice": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"number": "<string>",
"status": "<string>",
"grand_total": 123,
"currency": "<string>",
"payment_url": "<string>"
},
"lines": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"brick_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"brick_name": "<string>",
"quantity": 0,
"unit_price": "<string>",
"expires_at": "2023-12-25",
"used": 0,
"remaining": 0
}
]
}Create a subscription grant
Grants extra pre-committed units of one or more usage bricks on a live subscription, at a price you set: a usage top-up. Grants never create an order, never renew and never change the contracted price or the renewal quantity.
Billing
- One invoice is raised on the subscription today, with one one-time line per
brick, and is listed by
GET /subscriptions/{subscription_id}/invoices. - A 0-cent grant gets a 0-cent invoice that is paid at once.
- With
charge_immediately, the billed company’s default card is charged now. If the invoice cannot be calculated at once, the grant is created PENDING and the invoice is charged when it is calculated. A buyer who turned auto-pay off is emailed the invoice instead, like any other invoice.
Cover
Once active, the units cover usage that would otherwise be billed as overage,
committed units first, then grants, soonest expiry first. They carry into
renewals of the subscription until expires_at, and unused units lapse then.
Duplicate requests
This endpoint has no idempotency key: each successful call creates and bills a new grant. Clients must guard against sending the same grant twice, for example after a timeout, by listing the subscription’s grants before retrying.
Errors
- 400 when the request can’t be met. Nothing is created.
- 402 when
charge_immediatelywas set and the charge was declined or needs the buyer to authenticate. The grant and its unpaid invoice are kept;detailscarries their ids.
curl --request POST \
--url https://api.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants \
--header 'Content-Type: application/json' \
--header 'X-SALESBRICKS-KEY: <api-key>' \
--data '
{
"lines": [
{
"brick_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"quantity": "<string>",
"unit_price": "<string>"
}
],
"expires_at": "2023-12-25",
"effective_at": "2023-12-25",
"charge_immediately": false
}
'import requests
url = "https://api.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants"
payload = {
"lines": [
{
"brick_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"quantity": "<string>",
"unit_price": "<string>"
}
],
"expires_at": "2023-12-25",
"effective_at": "2023-12-25",
"charge_immediately": False
}
headers = {
"X-SALESBRICKS-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-SALESBRICKS-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
lines: [
{
brick_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
quantity: '<string>',
unit_price: '<string>'
}
],
expires_at: '2023-12-25',
effective_at: '2023-12-25',
charge_immediately: false
})
};
fetch('https://api.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants', 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.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants",
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([
'lines' => [
[
'brick_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'quantity' => '<string>',
'unit_price' => '<string>'
]
],
'expires_at' => '2023-12-25',
'effective_at' => '2023-12-25',
'charge_immediately' => false
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-SALESBRICKS-KEY: <api-key>"
],
]);
$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.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants"
payload := strings.NewReader("{\n \"lines\": [\n {\n \"brick_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"quantity\": \"<string>\",\n \"unit_price\": \"<string>\"\n }\n ],\n \"expires_at\": \"2023-12-25\",\n \"effective_at\": \"2023-12-25\",\n \"charge_immediately\": false\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-SALESBRICKS-KEY", "<api-key>")
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.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants")
.header("X-SALESBRICKS-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"lines\": [\n {\n \"brick_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"quantity\": \"<string>\",\n \"unit_price\": \"<string>\"\n }\n ],\n \"expires_at\": \"2023-12-25\",\n \"effective_at\": \"2023-12-25\",\n \"charge_immediately\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.salesbricks.com/api/v2/subscriptions/{subscription_id}/grants")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-SALESBRICKS-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"lines\": [\n {\n \"brick_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"quantity\": \"<string>\",\n \"unit_price\": \"<string>\"\n }\n ],\n \"expires_at\": \"2023-12-25\",\n \"effective_at\": \"2023-12-25\",\n \"charge_immediately\": false\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"grant_type": "TOP_UP",
"subscription_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "PENDING",
"activates": "ON_PAYMENT",
"effective_at": "2023-12-25",
"activated_at": "2023-11-07T05:31:56Z",
"voided_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"invoice": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"number": "<string>",
"status": "<string>",
"grand_total": 123,
"currency": "<string>",
"payment_url": "<string>"
},
"lines": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"brick_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"brick_name": "<string>",
"quantity": 0,
"unit_price": "<string>",
"expires_at": "2023-12-25",
"used": 0,
"remaining": 0
}
]
}Body
Input serializer for creating a grant.
The first day the units cover usage. They cover every usage period that ends on or after it, so a grant added mid-period covers the whole period. A date (YYYY-MM-DD) in the subscription's time zone. Defaults to today; can't be before today, or after the last day of the subscription's last usage period.
Charge the billed company's default card now. Requires an enabled Stripe integration and a default card, checked before anything is created. A declined charge, or one that needs the buyer to authenticate, answers 402 and keeps the grant and its unpaid invoice: pay it with POST /invoices/{invoice_id}/pay or void the grant.
Response
What granted the units. TOP_UP: units sold on their own invoice. ROLLOVER: unused committed units rolled over when a commitment period ended, not charged for. More types will be added, so treat an unknown value as a grant you can read but not act on.
TOP_UP- Top-upROLLOVER- Rollover
TOP_UP, ROLLOVER