Pair a phone
POST
/pair
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.
Request Bodyrequired
Section titled “Request Bodyrequired”Media typeapplication/json
object
code
required
The code from POST /pair/start.
string
name
A name for the phone, shown in the log when it answers. Default phone.
string
Example
{ "code": "7f3a9c21", "name": "My phone"}Responses
Section titled “Responses”The phone’s token.
Media typeapplication/json
object
token
required
The phone’s device token. Send it as Authorization: Bearer <token>.
string
device
required
object
id
string
name
string
box
required
object
id
string
name
string
Example generated
{ "token": "example", "device": { "id": "example", "name": "example" }, "box": { "id": "example", "name": "example" }}The code is wrong, used or expired.
Media typeapplication/json
object
error
required
What went wrong
string
Example
{ "error": "bad or expired pairing code"}GurtOS is open source under the Apache License 2.0.Source code on GitHub.