Crear un API token propio
curl --request POST \
--url https://api.ugps.io/api/auth/my-api-tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Integración ERP",
"type": "persistent",
"expiresIn": 3600000
}
'import requests
url = "https://api.ugps.io/api/auth/my-api-tokens"
payload = {
"name": "Integración ERP",
"type": "persistent",
"expiresIn": 3600000
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({name: 'Integración ERP', type: 'persistent', expiresIn: 3600000})
};
fetch('https://api.ugps.io/api/auth/my-api-tokens', 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.ugps.io/api/auth/my-api-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([
'name' => 'Integración ERP',
'type' => 'persistent',
'expiresIn' => 3600000
]),
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.ugps.io/api/auth/my-api-tokens"
payload := strings.NewReader("{\n \"name\": \"Integración ERP\",\n \"type\": \"persistent\",\n \"expiresIn\": 3600000\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.ugps.io/api/auth/my-api-tokens")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Integración ERP\",\n \"type\": \"persistent\",\n \"expiresIn\": 3600000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ugps.io/api/auth/my-api-tokens")
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 \"name\": \"Integración ERP\",\n \"type\": \"persistent\",\n \"expiresIn\": 3600000\n}"
response = http.request(request)
puts response.read_body{
"status": "success",
"data": {
"token": "atk_Xy2b...base64url",
"tokenId": "507f1f77bcf86cd799439011"
}
}{
"error": "El email es requerido"
}{
"error": "Token inválido o expirado"
}{
"error": "No tiene permisos para realizar esta acción"
}{
"message": "Error interno del servidor"
}Auth - Autenticación
Crear un API token propio
Crea un nuevo API token (prefijo atk_) para el usuario autenticado.
Permisos requeridos: access_api_keys
Datos requeridos:
name(string, 1-100 caracteres): Nombre descriptivo del tokentype(persistent|temporary): Tipo de token
Datos opcionales:
expiresIn(number, milisegundos): Obligatorio cuandotypeestemporary; define la vida útil del token
Comportamiento:
- El token raw se retorna una sola vez y nunca se almacena en texto plano (solo su hash HMAC-SHA256)
- El
clientIdy eluserIdse asignan automáticamente desde la sesión - Aplica rate limiting de creación de tokens
Requiere sesión de usuario: un bearer atk_ es rechazado con 403 y código SESSION_REQUIRED; un API token no puede crear otros tokens.
POST
/
api
/
auth
/
my-api-tokens
Crear un API token propio
curl --request POST \
--url https://api.ugps.io/api/auth/my-api-tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Integración ERP",
"type": "persistent",
"expiresIn": 3600000
}
'import requests
url = "https://api.ugps.io/api/auth/my-api-tokens"
payload = {
"name": "Integración ERP",
"type": "persistent",
"expiresIn": 3600000
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({name: 'Integración ERP', type: 'persistent', expiresIn: 3600000})
};
fetch('https://api.ugps.io/api/auth/my-api-tokens', 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.ugps.io/api/auth/my-api-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([
'name' => 'Integración ERP',
'type' => 'persistent',
'expiresIn' => 3600000
]),
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.ugps.io/api/auth/my-api-tokens"
payload := strings.NewReader("{\n \"name\": \"Integración ERP\",\n \"type\": \"persistent\",\n \"expiresIn\": 3600000\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.ugps.io/api/auth/my-api-tokens")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Integración ERP\",\n \"type\": \"persistent\",\n \"expiresIn\": 3600000\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ugps.io/api/auth/my-api-tokens")
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 \"name\": \"Integración ERP\",\n \"type\": \"persistent\",\n \"expiresIn\": 3600000\n}"
response = http.request(request)
puts response.read_body{
"status": "success",
"data": {
"token": "atk_Xy2b...base64url",
"tokenId": "507f1f77bcf86cd799439011"
}
}{
"error": "El email es requerido"
}{
"error": "Token inválido o expirado"
}{
"error": "No tiene permisos para realizar esta acción"
}{
"message": "Error interno del servidor"
}Authorizations
bearerAuthcookieAuth
Token de sesión Better Auth o API token (atk_...) en el header Authorization: Bearer <token>. Los JWT legacy ya no son válidos.
Body
application/json