Submit a usage entry
curl --request POST \
--url https://api.salesbricks.com/v2/usage \
--header 'Key: <api-key>'import requests
url = "https://api.salesbricks.com/v2/usage"
headers = {"Key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Key: '<api-key>'}};
fetch('https://api.salesbricks.com/v2/usage', 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/v2/usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"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"
"net/http"
"io"
)
func main() {
url := "https://api.salesbricks.com/v2/usage"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Key", "<api-key>")
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/v2/usage")
.header("Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.salesbricks.com/v2/usage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Key"] = '<api-key>'
response = http.request(request)
puts response.read_bodySubmit a usage entry
Use this API to set either a prorated gauge or increment a final value counter for a customer.
POST
/
v2
/
usage
Submit a usage entry
curl --request POST \
--url https://api.salesbricks.com/v2/usage \
--header 'Key: <api-key>'import requests
url = "https://api.salesbricks.com/v2/usage"
headers = {"Key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {Key: '<api-key>'}};
fetch('https://api.salesbricks.com/v2/usage', 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/v2/usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"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"
"net/http"
"io"
)
func main() {
url := "https://api.salesbricks.com/v2/usage"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Key", "<api-key>")
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/v2/usage")
.header("Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.salesbricks.com/v2/usage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Key"] = '<api-key>'
response = http.request(request)
puts response.read_bodyThe
v2/usage REST API is designed to handle both setting a prorated gauge and incrementing a final value counter for a specific customer in Salesbricks.
To utilize this endpoint, ensure that you are using the
v2/usage API endpoint:https://api.salesbricks.com/api/v2/usageRequest: POST /v2/usage
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
transaction_id | String | Yes | The unique identifier for this usage entry transaction. |
subscription_id | UUID | Yes | The ID of the Salesbricks subscription associated with the customer. |
brick_id | UUID | Yes | The ID of the associated Usage Brick. |
value | Integer | Yes | Required. This is the value to set for the Counter or Gauge (e.g., 1). |
time | DateTime | Yes | The timestamp indicating when the operation occurs in ISO 8601 format. |
properties | Dict | No | Additional properties as a JSON dictionary object (optional). |
Response
201 Created- if the usage entry is successfully submitted.400 Bad Request- if validation fails or required fields are missing.
{
"message": "Usage entry submitted successfully."
}
Example: Setting a Prorated Gauge
POST /v2/usage
Content-Type: application/json
Authorization: Bearer <token>
{
"transaction_id": "12345",
"subscription_id": "00000000-0000-0000-0000-000000000000",
"brick_id": "00000000-0000-0000-0000-000000000000",
"value": 121,
"time": "2024-09-16T10:15:30Z"
}
Example: Incrementing a Final Value Counter
POST /v2/usage
Content-Type: application/json
Authorization: Bearer <token>
{
"transaction_id": "54321",
"subscription_id": "00000000-0000-0000-0000-000000000000",
"brick_id": "00000000-0000-0000-0000-000000000000",
"value": 1,
"time": "2024-09-16T10:15:30Z",
"properties": {
"source_worker": "8168cf7f-65e0-4f9a-aeb4-3e013ff71f89",
"region": "us-east-1"
}
}
DELETE /v2/usage - Deleting a Usage Entry
To delete a usage entry, provide thetransaction_id in the request body.
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
transaction_id | String | Yes | The unique identifier for the usage entry. |
Response
200 OK- if the usage entry is successfully deleted.404 Not Found- if the usage entry does not exist.
{
"message": "Usage entry deleted successfully."
}
PATCH /v2/usage - Updating a Usage Entry
To update a usage entry, provide thetransaction_id and the fields to be updated.
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
transaction_id | String | Yes | The unique identifier for the usage entry. |
value | Integer | Yes | Update the usage value. |
properties | Dict | Optional | Update the properties dictionary (if applicable). |
Response
200 OK- if the usage entry is successfully updated.400 Bad Request- if validation fails or required fields are missing.404 Not Found- if the usage entry does not exist.
{
"message": "Usage entry updated successfully."
}