Code samples

Make the same authenticated API request with cURL, JavaScript, PHP, and Python.

All REST requests use https://api.thrivedesk.com/v1 and a server-side bearer token. These examples fetch the current user so you can verify a token without changing data.

cURL

curl "https://api.thrivedesk.com/v1/me" \
  -H "Authorization: Bearer $THRIVEDESK_TOKEN" \
  -H "Accept: application/json"

JavaScript

const response = await fetch('https://api.thrivedesk.com/v1/me', {
  headers: {
    Authorization: `Bearer ${process.env.THRIVEDESK_TOKEN}`,
    Accept: 'application/json'
  }
});

if (!response.ok) throw new Error(`ThriveDesk returned ${response.status}`);
console.log(await response.json());

PHP

<?php
$request = curl_init('https://api.thrivedesk.com/v1/me');
curl_setopt_array($request, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('THRIVEDESK_TOKEN'),
        'Accept: application/json',
    ],
]);

$body = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_RESPONSE_CODE);
if ($status < 200 || $status >= 300) throw new RuntimeException("ThriveDesk returned $status");
print_r(json_decode($body, true, flags: JSON_THROW_ON_ERROR));

Python

import os
import requests

response = requests.get(
    "https://api.thrivedesk.com/v1/me",
    headers={
        "Authorization": f"Bearer {os.environ['THRIVEDESK_TOKEN']}",
        "Accept": "application/json",
    },
    timeout=30,
)
response.raise_for_status()
print(response.json())