cURL
curl --request POST 'https://api.integrateledger.com/v1/track' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"customerId":"user_123","featureId":"api_call","request_id":"operation_123"}'import os
from ledger_sdk import Ledger
ledger = Ledger(api_key=os.environ["LEDGER_API_KEY"])
ledger.track_usage(customer_id="user_123", feature_id="api_call", request_id="operation_123")import { Ledger } from "@ledger/sdk";
const ledger = new Ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await ledger.trackUsage({ customerId: "user_123", featureId: "api_call", requestId: "operation_123" });const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({customerId: '<string>', featureId: '<string>', request_id: '<string>'})
};
fetch('https://api.integrateledger.com/v1/track', 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.integrateledger.com/v1/track",
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' => '<string>',
'featureId' => '<string>',
'request_id' => '<string>'
]),
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.integrateledger.com/v1/track"
payload := strings.NewReader("{\n \"customerId\": \"<string>\",\n \"featureId\": \"<string>\",\n \"request_id\": \"<string>\"\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.integrateledger.com/v1/track")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"<string>\",\n \"featureId\": \"<string>\",\n \"request_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.integrateledger.com/v1/track")
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\": \"<string>\",\n \"featureId\": \"<string>\",\n \"request_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"allowed": true,
"availableCredits": 1,
"chargedCredits": 123,
"request_id": "<string>",
"idempotent": true
}{
"error": "<string>",
"availableCredits": 1,
"creditCost": 123
}{
"error": "<string>",
"availableCredits": 1,
"creditCost": 123
}{
"error": "<string>",
"availableCredits": 1,
"creditCost": 123
}{
"error": "<string>",
"availableCredits": 1,
"creditCost": 123
}Customers and usage
Record feature usage
Record a successful feature action with an idempotent request ID.
POST
/
v1
/
track
cURL
curl --request POST 'https://api.integrateledger.com/v1/track' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"customerId":"user_123","featureId":"api_call","request_id":"operation_123"}'import os
from ledger_sdk import Ledger
ledger = Ledger(api_key=os.environ["LEDGER_API_KEY"])
ledger.track_usage(customer_id="user_123", feature_id="api_call", request_id="operation_123")import { Ledger } from "@ledger/sdk";
const ledger = new Ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await ledger.trackUsage({ customerId: "user_123", featureId: "api_call", requestId: "operation_123" });const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({customerId: '<string>', featureId: '<string>', request_id: '<string>'})
};
fetch('https://api.integrateledger.com/v1/track', 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.integrateledger.com/v1/track",
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' => '<string>',
'featureId' => '<string>',
'request_id' => '<string>'
]),
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.integrateledger.com/v1/track"
payload := strings.NewReader("{\n \"customerId\": \"<string>\",\n \"featureId\": \"<string>\",\n \"request_id\": \"<string>\"\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.integrateledger.com/v1/track")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"<string>\",\n \"featureId\": \"<string>\",\n \"request_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.integrateledger.com/v1/track")
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\": \"<string>\",\n \"featureId\": \"<string>\",\n \"request_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"allowed": true,
"availableCredits": 1,
"chargedCredits": 123,
"request_id": "<string>",
"idempotent": true
}{
"error": "<string>",
"availableCredits": 1,
"creditCost": 123
}{
"error": "<string>",
"availableCredits": 1,
"creditCost": 123
}{
"error": "<string>",
"availableCredits": 1,
"creditCost": 123
}{
"error": "<string>",
"availableCredits": 1,
"creditCost": 123
}Records one successful use of an active feature and charges its current
creditCost. Send customerId, featureId, and a unique request_id for the logical action. Track checks the balance in a transaction; a successful response includes the remaining availableCredits, chargedCredits, and idempotent: false.
If the network response is lost, retry the same customer, feature, and request_id. Ledger returns idempotent: true and does not charge again. Reusing the same customer and request ID for a different feature returns 409 request_id_conflict.
An insufficient balance returns 409 insufficient_credits with availableCredits and creditCost. This can happen even if an earlier Check credits was allowed, because check does not reserve balance. An unknown customer or archived/unknown feature returns 404. See Credits and usage for the recommended check and track sequence.Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json