cURL
curl --request POST 'https://api.integrateledger.com/v1/entities' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"customerId":"user_123","entityId":"alice","allowanceCredits":500,"capCredits":2000}'import ledger from "integrateledger";
const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await client.upsertEntity({ customerId: "user_123", entityId: "alice", allowanceCredits: 500, capCredits: 2000 });import os
from integrateledger import ledger
client = ledger(api_key=os.environ["LEDGER_API_KEY"])
client.upsert_entity(customer_id="user_123", entity_id="alice", allowance_credits=500, cap_credits=2000){
"entityId": "<string>",
"customerId": "<string>",
"name": "<string>",
"allowanceCredits": 123,
"capCredits": 1,
"createdAt": "2023-11-07T05:31:56Z",
"availableCredits": 1,
"allowanceRemaining": 1,
"periodUsage": 1,
"capRemaining": 1,
"heldCredits": 1,
"periodStart": "2023-11-07T05:31:56Z",
"periodEnd": "2023-11-07T05:31:56Z",
"plans": [
{
"planId": "<string>",
"group": "<string>",
"status": "pending",
"startsAt": "2023-11-07T05:31:56Z",
"endsAt": "2023-11-07T05:31:56Z"
}
],
"created": true,
"seats": [
{
"planId": "<string>",
"slot": 123
}
]
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "insufficient_permissions",
"requiredScope": "customers:read",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "payload_too_large",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "rate_limited",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}Entities
Create or update an entity
Add a user, seat or workspace to a customer, with its own allowance or a cap on the shared credits.
POST
/
v1
/
entities
cURL
curl --request POST 'https://api.integrateledger.com/v1/entities' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"customerId":"user_123","entityId":"alice","allowanceCredits":500,"capCredits":2000}'import ledger from "integrateledger";
const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await client.upsertEntity({ customerId: "user_123", entityId: "alice", allowanceCredits: 500, capCredits: 2000 });import os
from integrateledger import ledger
client = ledger(api_key=os.environ["LEDGER_API_KEY"])
client.upsert_entity(customer_id="user_123", entity_id="alice", allowance_credits=500, cap_credits=2000){
"entityId": "<string>",
"customerId": "<string>",
"name": "<string>",
"allowanceCredits": 123,
"capCredits": 1,
"createdAt": "2023-11-07T05:31:56Z",
"availableCredits": 1,
"allowanceRemaining": 1,
"periodUsage": 1,
"capRemaining": 1,
"heldCredits": 1,
"periodStart": "2023-11-07T05:31:56Z",
"periodEnd": "2023-11-07T05:31:56Z",
"plans": [
{
"planId": "<string>",
"group": "<string>",
"status": "pending",
"startsAt": "2023-11-07T05:31:56Z",
"endsAt": "2023-11-07T05:31:56Z"
}
],
"created": true,
"seats": [
{
"planId": "<string>",
"slot": 123
}
]
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "insufficient_permissions",
"requiredScope": "customers:read",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "payload_too_large",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "rate_limited",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}An entity is a user, seat, agent or workspace inside one customer. Send
customerId and your own entityId, with either or both of:
allowanceCredits: credits per billing period that only this entity can spend. It spends them before the customer’s shared credits. They’re granted while the customer has a plan (paid or free), for the plan’s billing period, so a customer without a plan gives its entities no allowance.capCredits: the most this entity may draw from the customer’s shared credits and overage per billing period. Its own allowance doesn’t count against it.0lets it spend only its allowance.
entityId to check, track and reservations to spend as that entity. A track that would pass the cap returns 409 entity_cap_reached with capRemaining.
The same call updates an entity: omitted fields keep their values and null clears one. A changed allowance applies to the current period at once; credits already spent stay spent. Calling it for a deleted entity’s ID restores it (created: true).
The response is the entity with its balance, as Get an entity returns it. An unknown customer returns 404 customer_not_found. Needs the Customers permission at Write.Authorizations
Body
application/json
Response
The entity, created, updated or restored