Mint a short-lived ws_token for browser/mobile websocket auth
curl --request POST \
--url https://api-beta.pepay.io/api/v1/ws/token \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"ttl_seconds": 60
}
'import requests
url = "https://api-beta.pepay.io/api/v1/ws/token"
payload = { "ttl_seconds": 60 }
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({ttl_seconds: 60})
};
fetch('https://api-beta.pepay.io/api/v1/ws/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-beta.pepay.io/api/v1/ws/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([
'ttl_seconds' => 60
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$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-beta.pepay.io/api/v1/ws/token"
payload := strings.NewReader("{\n \"ttl_seconds\": 60\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
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-beta.pepay.io/api/v1/ws/token")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"ttl_seconds\": 60\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-beta.pepay.io/api/v1/ws/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"ttl_seconds\": 60\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"scope": "merchant",
"merchant_id": 123,
"network_environment": null,
"expires_at": 1766320496,
"ws_url": "wss://api-beta.pepay.io/ws/merchant/events"
}
}
Mint a WebSocket Token
Mint a short-lived token used to authenticate WebSocket connections.
POST
/
api
/
v1
/
ws
/
token
Mint a short-lived ws_token for browser/mobile websocket auth
curl --request POST \
--url https://api-beta.pepay.io/api/v1/ws/token \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"ttl_seconds": 60
}
'import requests
url = "https://api-beta.pepay.io/api/v1/ws/token"
payload = { "ttl_seconds": 60 }
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({ttl_seconds: 60})
};
fetch('https://api-beta.pepay.io/api/v1/ws/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-beta.pepay.io/api/v1/ws/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([
'ttl_seconds' => 60
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$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-beta.pepay.io/api/v1/ws/token"
payload := strings.NewReader("{\n \"ttl_seconds\": 60\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
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-beta.pepay.io/api/v1/ws/token")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"ttl_seconds\": 60\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-beta.pepay.io/api/v1/ws/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"ttl_seconds\": 60\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"scope": "merchant",
"merchant_id": 123,
"network_environment": null,
"expires_at": 1766320496,
"ws_url": "wss://api-beta.pepay.io/ws/merchant/events"
}
}
Overview
Use this endpoint to mint a short-lived token for WebSocket authentication. Tokens are scoped (merchant or commerce) and can be issued with a TTL.
Authentication
- Server auth:
x-api-key(merchant) orx-commerce-api-key(commerce)
Request
SDK
const wsToken = await pepay.ws.token.mint({ scope: 'merchant', ttlSeconds: 60 });
cURL
curl -X POST "https://api-beta.pepay.io/api/v1/ws/token" \
-H "x-api-key: pk_..." \
-H "Content-Type: application/json" \
-d '{"scope":"merchant","ttl_seconds":60}'
Response
{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"scope": "merchant",
"merchant_id": 123,
"network_environment": null,
"expires_at": 1766320496,
"ws_url": "wss://api-beta.pepay.io/ws/merchant/events"
}
}
Errors
400invalid scope/ttl (or scope mismatch for the provided API key type)401invalid API key
Examples
Connect to merchant events with the minted token:const { data } = (await pepay.ws.token.mint({ scope: 'merchant' })) as any;
const wsUrl = `${process.env.PEPAY_WS_URL ?? 'wss://api-beta.pepay.io'}/ws/merchant/events?token=${data.token}`;
console.log(wsUrl);
Authorizations
merchantApiKeycommerceApiKey
API key for server-to-server operations (scope=merchant or commerce)
Body
application/json
Was this page helpful?

