Pair a phone
const url = 'http://127.0.0.1:7700/api/pair';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"code":"7f3a9c21","name":"My phone"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url http://127.0.0.1:7700/api/pair \ --header 'Content-Type: application/json' \ --data '{ "code": "7f3a9c21", "name": "My phone" }'A phone trades a pairing code for its own device token. The code stops working once used. Keep the
token; the box does not show it again. Open without a token, so the body is capped at 1 MB. A code read
off a screen may be typed as 8120-D849; case and dashes do not matter. Wrong codes are limited to 5 a
minute from one address and 60 a minute from everyone together, then 429.
Request Bodyrequired
Section titled “Request Bodyrequired”object
The code from POST /pair/start.
A name for the phone, shown in the log when it answers. Default phone.
What the device says it is. Default web. It is never used for a security decision. setup goes with a code from POST /setup/code, and only with one.
Optional. The phone’s SpacetimeDB identity, so the box vouches for it at once.
Example
{ "code": "7f3a9c21", "name": "My phone"}Responses
Section titled “Responses”The phone’s token.
object
The phone’s device token. Send it as Authorization: Bearer <token>.
The box’s edition
object
Business: the person the code was made for.
object
Example
{ "edition": "server"}The code is wrong, used or expired, or kind is not allowed.
object
What went wrong
Example
{ "error": "bad or expired pairing code"}The body is over 1 MB.
object
What went wrong
Example generated
{ "error": "example"}Too many wrong codes from this address, or from everyone together.
object
What went wrong
Example generated
{ "error": "example"}