curl -X POST https://api.v2.dealmachine.com/v1/auth/device/token \
-H "Content-Type: application/json" \
-d '{
"device_code": "a1b2c3d4e5f6...",
"client_id": "dealmachine-next-cli"
}'
async function pollForToken(deviceCode: string, interval: number) {
while (true) {
const response = await fetch('https://api.v2.dealmachine.com/v1/auth/device/token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
device_code: deviceCode,
client_id: 'dealmachine-next-cli',
}),
});
if (response.ok) {
const data = await response.json();
console.log('API Key:', data.api_key);
return data;
}
const error = await response.json();
if (error.error.code === 'authorization_pending') {
await new Promise(r => setTimeout(r, interval * 1000));
continue;
}
throw new Error(error.error.message);
}
}
import requests
import time
def poll_for_token(device_code, interval):
while True:
response = requests.post(
'https://api.v2.dealmachine.com/v1/auth/device/token',
json={
'device_code': device_code,
'client_id': 'dealmachine-next-cli'
}
)
if response.ok:
data = response.json()
print(f"API Key: {data['api_key']}")
return data
error = response.json()['error']
if error['code'] == 'authorization_pending':
time.sleep(interval)
continue
raise Exception(error['message'])
{
"api_key": "dm_sk_live_VMgXKyJQ7qTt9SHpoDYgHOXo...",
"key_id": "key_abc123def456",
"organization": {
"id": 1,
"name": "My Company",
"slug": "my-company"
}
}
{
"error": {
"code": "authorization_pending",
"message": "Authorization pending. Continue polling.",
"request_id": "req_abc123"
}
}
{
"error": {
"code": "access_denied",
"message": "The user denied the authorization request.",
"request_id": "req_abc123"
}
}
{
"error": {
"code": "expired_token",
"message": "The device code has expired.",
"request_id": "req_abc123"
}
}
Poll for Device Token
POST
/
v1
/
auth
/
device
/
token
curl -X POST https://api.v2.dealmachine.com/v1/auth/device/token \
-H "Content-Type: application/json" \
-d '{
"device_code": "a1b2c3d4e5f6...",
"client_id": "dealmachine-next-cli"
}'
async function pollForToken(deviceCode: string, interval: number) {
while (true) {
const response = await fetch('https://api.v2.dealmachine.com/v1/auth/device/token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
device_code: deviceCode,
client_id: 'dealmachine-next-cli',
}),
});
if (response.ok) {
const data = await response.json();
console.log('API Key:', data.api_key);
return data;
}
const error = await response.json();
if (error.error.code === 'authorization_pending') {
await new Promise(r => setTimeout(r, interval * 1000));
continue;
}
throw new Error(error.error.message);
}
}
import requests
import time
def poll_for_token(device_code, interval):
while True:
response = requests.post(
'https://api.v2.dealmachine.com/v1/auth/device/token',
json={
'device_code': device_code,
'client_id': 'dealmachine-next-cli'
}
)
if response.ok:
data = response.json()
print(f"API Key: {data['api_key']}")
return data
error = response.json()['error']
if error['code'] == 'authorization_pending':
time.sleep(interval)
continue
raise Exception(error['message'])
{
"api_key": "dm_sk_live_VMgXKyJQ7qTt9SHpoDYgHOXo...",
"key_id": "key_abc123def456",
"organization": {
"id": 1,
"name": "My Company",
"slug": "my-company"
}
}
{
"error": {
"code": "authorization_pending",
"message": "Authorization pending. Continue polling.",
"request_id": "req_abc123"
}
}
{
"error": {
"code": "access_denied",
"message": "The user denied the authorization request.",
"request_id": "req_abc123"
}
}
{
"error": {
"code": "expired_token",
"message": "The device code has expired.",
"request_id": "req_abc123"
}
}
Poll for the result of a device authorization. Call this endpoint repeatedly (respecting the
interval) until the user approves, denies, or the code expires.
No authentication required. This is a public endpoint.
curl -X POST https://api.v2.dealmachine.com/v1/auth/device/token \
-H "Content-Type: application/json" \
-d '{
"device_code": "a1b2c3d4e5f6...",
"client_id": "dealmachine-next-cli"
}'
async function pollForToken(deviceCode: string, interval: number) {
while (true) {
const response = await fetch('https://api.v2.dealmachine.com/v1/auth/device/token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
device_code: deviceCode,
client_id: 'dealmachine-next-cli',
}),
});
if (response.ok) {
const data = await response.json();
console.log('API Key:', data.api_key);
return data;
}
const error = await response.json();
if (error.error.code === 'authorization_pending') {
await new Promise(r => setTimeout(r, interval * 1000));
continue;
}
throw new Error(error.error.message);
}
}
import requests
import time
def poll_for_token(device_code, interval):
while True:
response = requests.post(
'https://api.v2.dealmachine.com/v1/auth/device/token',
json={
'device_code': device_code,
'client_id': 'dealmachine-next-cli'
}
)
if response.ok:
data = response.json()
print(f"API Key: {data['api_key']}")
return data
error = response.json()['error']
if error['code'] == 'authorization_pending':
time.sleep(interval)
continue
raise Exception(error['message'])
{
"api_key": "dm_sk_live_VMgXKyJQ7qTt9SHpoDYgHOXo...",
"key_id": "key_abc123def456",
"organization": {
"id": 1,
"name": "My Company",
"slug": "my-company"
}
}
{
"error": {
"code": "authorization_pending",
"message": "Authorization pending. Continue polling.",
"request_id": "req_abc123"
}
}
{
"error": {
"code": "access_denied",
"message": "The user denied the authorization request.",
"request_id": "req_abc123"
}
}
{
"error": {
"code": "expired_token",
"message": "The device code has expired.",
"request_id": "req_abc123"
}
}
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
device_code | string | Yes | Device code from /auth/device/code response |
client_id | string | Yes | Must match the original request’s client_id |
Polling Behavior
| Response Code | Meaning | Action |
|---|---|---|
authorization_pending | User hasn’t acted yet | Wait interval seconds and retry |
slow_down | Polling too fast | Increase interval by 5 seconds |
access_denied | User denied | Stop polling, show error |
expired_token | Code expired | Stop polling, start new flow |
The API key is returned only once. After the first successful poll, the raw key is cleared from the server. If you lose it, the user must re-authorize.
Success Response Fields
| Field | Type | Description |
|---|---|---|
api_key | string | The API key (dm_sk_live_xxx) |
key_id | string | Key identifier for management |
organization.id | number | Organization ID |
organization.name | string | Organization name |
organization.slug | string | Organization URL slug |
⌘I