JavaScript
import Surge from '@surgeapi/node';
const client = new Surge({
apiKey: process.env['SURGE_API_KEY'], // This is the default and can be omitted
});
const userTokenResponse = await client.users.createToken('usr_01jymgdfrpec2asc5m0z3a6fr9');
console.log(userTokenResponse.token);import os
from surge import Surge
client = Surge(
api_key=os.environ.get("SURGE_API_KEY"), # This is the default and can be omitted
)
user_token_response = client.users.create_token(
user_id="usr_01jymgdfrpec2asc5m0z3a6fr9",
)
print(user_token_response.token)require "surge_api"
surge = SurgeAPI::Client.new(api_key: "My API Key")
user_token_response = surge.users.create_token("usr_01jymgdfrpec2asc5m0z3a6fr9")
puts(user_token_response)curl --request POST \
--url https://api.surge.app/users/{user_id}/tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"duration_seconds": 900
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.surge.app/users/{user_id}/tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'duration_seconds' => 900
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.surge.app/users/{user_id}/tokens"
payload := strings.NewReader("{\n \"duration_seconds\": 900\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.surge.app/users/{user_id}/tokens")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"duration_seconds\": 900\n}")
.asString();{
"token": "header.payload.signature"
}{
"error": {
"message": "The requested resource could not be found.",
"type": "not_found"
}
}Users
Create user token
Create a short-lived JWT for a user to authenticate with Surge’s embeddable UI components.
POST
/
users
/
{user_id}
/
tokens
JavaScript
import Surge from '@surgeapi/node';
const client = new Surge({
apiKey: process.env['SURGE_API_KEY'], // This is the default and can be omitted
});
const userTokenResponse = await client.users.createToken('usr_01jymgdfrpec2asc5m0z3a6fr9');
console.log(userTokenResponse.token);import os
from surge import Surge
client = Surge(
api_key=os.environ.get("SURGE_API_KEY"), # This is the default and can be omitted
)
user_token_response = client.users.create_token(
user_id="usr_01jymgdfrpec2asc5m0z3a6fr9",
)
print(user_token_response.token)require "surge_api"
surge = SurgeAPI::Client.new(api_key: "My API Key")
user_token_response = surge.users.create_token("usr_01jymgdfrpec2asc5m0z3a6fr9")
puts(user_token_response)curl --request POST \
--url https://api.surge.app/users/{user_id}/tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"duration_seconds": 900
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.surge.app/users/{user_id}/tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'duration_seconds' => 900
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.surge.app/users/{user_id}/tokens"
payload := strings.NewReader("{\n \"duration_seconds\": 900\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.surge.app/users/{user_id}/tokens")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"duration_seconds\": 900\n}")
.asString();{
"token": "header.payload.signature"
}{
"error": {
"message": "The requested resource could not be found.",
"type": "not_found"
}
}Authorizations
Path Parameters
Body
application/json
A request to create a token
Restrict the token to viewing embedded conversations and unread counts. Sending messages, changing read state, editing contacts, and calling are disabled. Defaults to false. Preserve this value when refreshing the token; changing access mode requires reloading the embed.