JavaScript
import Hyperspell from '@hyperspell/hyperspell';
const client = new Hyperspell({
apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted
});
const token = await client.auth.userToken({ user_id: 'user_id' });
console.log(token.token);import os
from hyperspell import Hyperspell
client = Hyperspell(
api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted
)
token = client.auth.user_token(
user_id="user_id",
)
print(token.token)package main
import (
"context"
"fmt"
"github.com/hyperspell/hyperspell-go"
"github.com/hyperspell/hyperspell-go/option"
)
func main() {
client := hyperspell.NewClient(
option.WithAPIKey("My API Key"),
)
token, err := client.Auth.UserToken(context.TODO(), hyperspell.AuthUserTokenParams{
UserID: "user_id",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", token.Token)
}
hyperspell auth user-token \
--api-key 'My API Key' \
--user-id user_idcurl --request POST \
--url https://api.hyperspell.com/auth/user_token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"user_id": "<string>",
"origin": "<string>",
"expires_in": "30m"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.hyperspell.com/auth/user_token",
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([
'user_id' => '<string>',
'origin' => '<string>',
'expires_in' => '30m'
]),
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;
}HttpResponse<String> response = Unirest.post("https://api.hyperspell.com/auth/user_token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"user_id\": \"<string>\",\n \"origin\": \"<string>\",\n \"expires_in\": \"30m\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.hyperspell.com/auth/user_token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"user_id\": \"<string>\",\n \"origin\": \"<string>\",\n \"expires_in\": \"30m\"\n}"
response = http.request(request)
puts response.read_body{
"token": "<string>",
"expires_at": "2023-11-07T05:31:56Z"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Authentication
Get a user token
Use this endpoint to create a user token for a specific user. This token can be safely passed to your user-facing front-end.
POST
/
auth
/
user_token
JavaScript
import Hyperspell from '@hyperspell/hyperspell';
const client = new Hyperspell({
apiKey: process.env['HYPERSPELL_API_KEY'], // This is the default and can be omitted
});
const token = await client.auth.userToken({ user_id: 'user_id' });
console.log(token.token);import os
from hyperspell import Hyperspell
client = Hyperspell(
api_key=os.environ.get("HYPERSPELL_API_KEY"), # This is the default and can be omitted
)
token = client.auth.user_token(
user_id="user_id",
)
print(token.token)package main
import (
"context"
"fmt"
"github.com/hyperspell/hyperspell-go"
"github.com/hyperspell/hyperspell-go/option"
)
func main() {
client := hyperspell.NewClient(
option.WithAPIKey("My API Key"),
)
token, err := client.Auth.UserToken(context.TODO(), hyperspell.AuthUserTokenParams{
UserID: "user_id",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", token.Token)
}
hyperspell auth user-token \
--api-key 'My API Key' \
--user-id user_idcurl --request POST \
--url https://api.hyperspell.com/auth/user_token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"user_id": "<string>",
"origin": "<string>",
"expires_in": "30m"
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.hyperspell.com/auth/user_token",
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([
'user_id' => '<string>',
'origin' => '<string>',
'expires_in' => '30m'
]),
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;
}HttpResponse<String> response = Unirest.post("https://api.hyperspell.com/auth/user_token")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"user_id\": \"<string>\",\n \"origin\": \"<string>\",\n \"expires_in\": \"30m\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.hyperspell.com/auth/user_token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"user_id\": \"<string>\",\n \"origin\": \"<string>\",\n \"expires_in\": \"30m\"\n}"
response = http.request(request)
puts response.read_body{
"token": "<string>",
"expires_at": "2023-11-07T05:31:56Z"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Authorizations
APIKeyAsUser
API Key or JWT User Token. If using an API Key, set the X-As-User header to act as a specific user. A JWT User Token is always scoped to a specific user.
Body
application/json
Origin of the request, used for CSRF protection. If set, the token will only be valid for requests originating from this origin.
Token lifetime, e.g., '30m', '2h', '1d'. Defaults to 24 hours if not provided. Maximum 30 days.
Example:
"30m"
Was this page helpful?
⌘I