Connecting a provider
A provider needs a sync token before it can call the service, and pairing is the only way to get one. The provider displays a code, the owner approves it in the app, and the token is delivered once.
- Start. Ask the service for a pairing. You get a code, a link, and a poll secret.
- Show. Open the link in a browser. If the provider has no screen, print the link and the code.
- Approve. The owner signs in or creates an account, names the library, and approves. The page shows the code and the device name.
- Collect. Poll with the poll secret. The first poll after approval returns the sync token. No later poll returns it.
Start a pairing
POST https://api.lets.dj/providers/pair/start
Content-Type: application/json
{ "deviceName": "Ryan’s MacBook" }
Takes no credential. The body is optional.
| Field | Notes |
|---|---|
deviceName |
Shown to the owner beside the code, so send a name they will recognize. Cut to 60 characters; control characters become spaces. |
Response:
{
"code": "K7QM-X4NP",
"pollSecret": "…",
"pairUrl": "https://app.lets.dj/pair?code=K7QM-X4NP",
"expiresAt": 1790000000000,
"pollIntervalSeconds": 2
}
| Field | Notes |
|---|---|
code |
Eight characters as two groups of four, from an alphabet with no 0 or O and no 1, I or L. It is how the owner’s page finds the pairing. It is not a credential. |
pollSecret |
The credential. Keep it to yourself and use it only for polling. |
pairUrl |
The link to open. Use it as given rather than building it. |
expiresAt |
Milliseconds since the epoch. |
pollIntervalSeconds |
How long to wait between polls. |
A 429 with "code": "too_many_pairings" means the ceiling on simultaneously open pairings is reached. Wait as long as Retry-After says, then ask again.
Expiry
| Window | Duration |
|---|---|
| Pairing open from creation | 30 minutes |
| Each time the owner reaches the approval page signed in | the 30 minutes restart |
| Ceiling from creation, regardless of restarts | 2 hours |
| Collecting the token after approval | 30 minutes |
expiresAt moves. Go by the value the poll returns, not by these figures. When a pairing expires, start a new one and show the new code.
Poll for the token
POST https://api.lets.dj/providers/pair/poll
Authorization: Bearer <poll secret>
This is the only route where the bearer is not a sync token.
Before approval:
{ "status": "pending", "expiresAt": 1790000000000 }
After approval, once:
{
"status": "approved",
"syncToken": "…",
"bridgeId": "0123456789abcdef",
"hostname": "0123456789abcdef.letsdj.io",
"label": "Karaoke at Ryan’s"
}
| Field | Notes |
|---|---|
syncToken |
Store it before you do anything else that could fail. The service keeps only a hash and cannot say it again. If it is lost, pair again — which makes a new library, leaving the old one empty for the owner to delete. |
bridgeId, hostname |
The library’s name on the service’s domain. Use hostname as given. See A name and a certificate. |
label |
What the owner called the library. |
Responses are marked Cache-Control: no-store.
| Status | code |
Do |
|---|---|---|
410 |
expired |
Start a new pairing. |
410 |
already_collected |
The token was already delivered, perhaps to a poll whose answer you never received. Start a new pairing. |
403 |
unknown_pairing |
The poll secret matches no pairing. Start a new pairing. |
401 |
missing_token |
No bearer was sent. |
After approval
The library exists and is empty, and the owner’s page says it is connected. It becomes ready when you send your first catalog — see Sending a catalog.
A sync token does not expire. It stops working when the owner deletes the library, and every route answers 403 from then on. See Conventions.
Do not share a sync token between two programs. Each sync replaces the address and media token the library has on file, so the second would quietly take the library from the first.