Cloud API
The API the Spendyard Cloud dashboard and the CLI use, calling any of it from the CLI, its contract on Buf, and how a call looks.
Everything the dashboard and the CLI do with Spendyard Cloud goes through one API, as the signed-in person: it sees what they may see and does what their role allows. The contract is public, as the Buf module buf.build/spendyard/spendyard (spendyard.api.v1), and the CLI is built on it.
Your own code can’t sign in yet. It will later. Until then, the CLI is the way in from a script or a coding agent:
spendyard apicalls any method of the API, as you, once the CLI is signed in.
From the CLI
spendyard api has the whole contract compiled in, with its comments: it lists the methods, describes one field by field, and calls any of them with a request written as JSON. It’s for what no other command covers yet, for scripts, and for coding agents.
Sign the CLI in first (Spendyard Cloud CLI); list and describe work without.
spendyard cloud login
Find a method
spendyard api list # every method, with the permission it takes
spendyard api list --service sync # one service's
spendyard api list subscription --reads # those holding "subscription" that only read
spendyard api list --streams # those that answer with a stream
SyncService/SyncChanges sync:read
SyncService/SyncBootstrap sync:read
SyncService/WatchChanges sync:read (stream)
Methods only the dashboard may call (removing a member, deleting the organisation) are marked dashboard only; the CLI’s token is refused for them.
Describe one
spendyard api describe SyncChanges
SyncService/SyncChanges sync:read
SyncChanges gives the changes after `since`, a page at a time. When the caller can't catch up from there (too old, another epoch, or nothing held yet), it says to start over with SyncBootstrap.
SyncChangesRequest
orgId string
since int64 (a string) The newest sync id the caller applied. …
epoch int64 (a string) The epoch it was of, from the answer that gave it; …
kinds [EntityKind] Only changes of these kinds, …
It gives the request and the answer field by field, and the messages they hold, in the contract’s own words. Names are as JSON writes them (pageSize, orgId). A method can be named DocumentService/ListDocuments, or just ListDocuments when only one service has it.
Call one
spendyard api call DocumentService/ListDocuments '{"pageSize": 5}'
echo '{"query": "slack"}' | spendyard api call ListDocuments - # the request from standard input
spendyard api call SubscriptionService/ListSubscriptions # no request is {}
- The answer is printed as JSON, as the API gives it.
- The request is checked first, against the contract: a field it doesn’t have, or a value of the wrong type, is refused before anything is sent, with what was wrong.
- Your organisation: a request that names one (
orgId) and isn’t given it gets the one the CLI acts in (spendyard cloud statussays which;spendyard cloud switchchanges it). - Streams: a method that answers with a stream (
WatchChanges) prints each message on a line of its own until it ends, or you press Ctrl-C. - Errors say what went wrong, and exit with 2:
not signed in to Spendyard Cloud; run spendyard cloud login, or what the API refused (only in the dashboard: a token can't do that, or the role your account lacks).
With jq, for instance, the names of the vendors you pay for each month:
spendyard api call ListSubscriptions | jq -r '.subscriptions[] | select(.interval == "INTERVAL_MONTH") | .vendor.name'
The reference
Every service, method and message, with what each field means, is documented with the contract on Buf: buf.build/spendyard/spendyard.
Calls
The API speaks Connect: each method is a POST to https://app.spendyard.com/spendyard.api.v1.<Service>/<Method>, with JSON or binary Protobuf. A call is made as a signed-in person, in one of their organisations.
curl https://app.spendyard.com/spendyard.api.v1.SubscriptionService/ListSubscriptions \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{}'
Field names are the contract’s, in lowerCamelCase in JSON (includeAll, pageSize). Errors are Connect’s: unauthenticated without a valid token, permission_denied when your role doesn’t allow the method.
Clients
Generate a typed client from the module, for TypeScript, Go, Python, Swift, Kotlin and more:
buf generate buf.build/spendyard/spendyard
with a buf.gen.yaml naming the plugins for your language; see Buf’s and Connect’s docs.
Services
Each links to its methods and messages on Buf.
| Service | |
|---|---|
DocumentService |
Receipts, invoices and statements: list, get, upload (CreateDocumentUpload, then AddDocument), correct, download the original, read again, delete |
SubscriptionService |
Subscriptions: what each costs a month, seats, card, next renewal, status |
PaymentService |
Every payment once, with its receipts and statement lines |
TransactionService |
Card statements’ lines, and the receipt each matched |
VendorService |
The organisation’s vendors and what each costs; vendors of its own |
PushService |
What spendyard cloud push sends: documents read elsewhere, with their readings and corrections |
SyncService |
The organisation’s changes, in order, to follow them |
SourceService |
Forwarding addresses: list, make a new one, retire one |
OrgService |
Organisations and their members and roles |
InviteService |
Invites and the invite link |
AccountService |
Your profile and your sessions |
ActivityService |
Who changed what |
Each method declares in the contract the permission it needs, and each role (owner, admin, member, accountant) holds some of them, as in the dashboard.