Create API key for user
Creates a new API key for the current user. The key gives access to all resources of the user. The raw key is returned only once in the response.
curl -X POST "//v1/api-keys" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN (API Key)" \
-d '{
"name": "John Doe",
"expiration_date": "2024-12-25T10:00:00Z"
}'
import requests
import json
url = "//v1/api-keys"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_TOKEN (API Key)"
}
data = {
"name": "John Doe",
"expiration_date": "2024-12-25T10:00:00Z"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
const response = await fetch("//v1/api-keys", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_TOKEN (API Key)"
},
body: JSON.stringify({
"name": "John Doe",
"expiration_date": "2024-12-25T10:00:00Z"
})
});
const data = await response.json();
console.log(data);
package main
import (
"fmt"
"net/http"
"bytes"
"encoding/json"
)
func main() {
data := []byte(`{
"name": "John Doe",
"expiration_date": "2024-12-25T10:00:00Z"
}`)
req, err := http.NewRequest("POST", "//v1/api-keys", bytes.NewBuffer(data))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_API_TOKEN (API Key)")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("Response Status:", resp.Status)
}
require 'net/http'
require 'json'
uri = URI('//v1/api-keys')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request['Authorization'] = 'Bearer YOUR_API_TOKEN (API Key)'
request.body = '{
"name": "John Doe",
"expiration_date": "2024-12-25T10:00:00Z"
}'
response = http.request(request)
puts response.body
{
"id": "example_string",
"key_prefix": "example_string",
"name": "John Doe",
"expiration_date": "2024-12-25T10:00:00Z",
"created_at": "2024-12-25T10:00:00Z",
"revoked_at": "2024-12-25T10:00:00Z",
"api_key": "example_string"
}
{
"error": "Bad Request",
"message": "The request contains invalid parameters or malformed data",
"code": 400,
"details": [
{
"field": "email",
"message": "Invalid email format"
}
]
}
{
"error": "Unauthorized",
"message": "Authentication required. Please provide a valid API token",
"code": 401
}
{
"error": "Internal Server Error",
"message": "An unexpected error occurred on the server",
"code": 500,
"requestId": "req_1234567890"
}
POST
/v1/api-keys
POST
Base URLstring
Target server for requests. Edit to use your own host.
Bearer Token (API Key)
Bearer Tokenstring
RequiredUser API Key. Create in the Ctxfy dashboard or via POST /v1/api-keys. Use Bearer <api_key> in Authorization header.
User API Key. Create in the Ctxfy dashboard or via POST /v1/api-keys. Use Bearer <api_key> in Authorization header.
Content-Typestring
RequiredThe media type of the request body
Options: application/json
expiration_datestring
Format: date-time
Request Preview
Response
Response will appear here after sending the request
Authentication
header
Authorizationstring
RequiredBearer token (API Key). User API Key. Create in the Ctxfy dashboard or via POST /v1/api-keys. Use Bearer <api_key> in Authorization header.
Responses
Was this page helpful?