Criar chave API
curl --request POST \
--url https://suasofia.online/api/user/api-keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>"
}
'import requests
url = "https://suasofia.online/api/user/api-keys"
payload = { "name": "<string>" }
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: '<string>'})
};
fetch('https://suasofia.online/api/user/api-keys', 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://suasofia.online/api/user/api-keys",
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' => '<string>'
]),
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://suasofia.online/api/user/api-keys"
payload := strings.NewReader("{\n \"name\": \"<string>\"\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://suasofia.online/api/user/api-keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://suasofia.online/api/user/api-keys")
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\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"message": "Chave API criada com sucesso.",
"api_key": {
"name": "Chave API de Produção",
"token": "1|abc123xyz789abcdef...",
"created_at": "2025-01-08T10:30:00.000000Z"
}
}
{
"message": "O campo nome é obrigatório.",
"errors": {
"name": ["O campo nome é obrigatório."]
}
}
Chaves da API
Criar chave API
Gerar uma nova chave API para o usuário autenticado
POST
/
user
/
api-keys
Criar chave API
curl --request POST \
--url https://suasofia.online/api/user/api-keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>"
}
'import requests
url = "https://suasofia.online/api/user/api-keys"
payload = { "name": "<string>" }
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: '<string>'})
};
fetch('https://suasofia.online/api/user/api-keys', 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://suasofia.online/api/user/api-keys",
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' => '<string>'
]),
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://suasofia.online/api/user/api-keys"
payload := strings.NewReader("{\n \"name\": \"<string>\"\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://suasofia.online/api/user/api-keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://suasofia.online/api/user/api-keys")
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\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"message": "Chave API criada com sucesso.",
"api_key": {
"name": "Chave API de Produção",
"token": "1|abc123xyz789abcdef...",
"created_at": "2025-01-08T10:30:00.000000Z"
}
}
{
"message": "O campo nome é obrigatório.",
"errors": {
"name": ["O campo nome é obrigatório."]
}
}
Este endpoint gera uma nova chave API para o usuário autenticado. Diferentemente do endpoint de login que cria um token de sessão, este cria uma chave API persistente que pode ser usada para acesso de longo prazo à API.
Este endpoint requer autenticação. Use sua chave API existente ou token de sessão para criar chaves API adicionais.
Corpo da Requisição
string
required
Um nome/rótulo para a chave API (ex: “Produção”, “Desenvolvimento”, “Meu App”)
Resposta
string
Mensagem de sucesso
object
{
"message": "Chave API criada com sucesso.",
"api_key": {
"name": "Chave API de Produção",
"token": "1|abc123xyz789abcdef...",
"created_at": "2025-01-08T10:30:00.000000Z"
}
}
{
"message": "O campo nome é obrigatório.",
"errors": {
"name": ["O campo nome é obrigatório."]
}
}
Exemplo de Requisição
curl -X POST https://suasofia.online/api/user/api-keys \
-H "Authorization: Bearer SUA_CHAVE_API_EXISTENTE" \
-H "Content-Type: application/json" \
-d '{
"name": "Chave API de Produção"
}'
O token da chave API é retornado apenas uma vez. Certifique-se de armazená-lo com segurança. Se você perdê-lo, precisará criar uma nova chave.
Gerenciando Chaves API
- GET /user/api-keys - Listar todas as chaves API para o usuário autenticado
- DELETE /user/api-keys/ - Deletar uma chave API específica
⌘I

