Generate key
curl --request POST \
--url https://api.datkey.dev/keys \
--header 'Content-Type: application/json' \
--data '
{
"api_id": "{api_id}",
"name": "{api_name}",
"prefix": "prefix",
"length": 16,
"meta": {
"user_id": "123456"
},
"expires_at": 123,
"verification_limit": 123
}
'import requests
url = "https://api.datkey.dev/keys"
payload = {
"api_id": "{api_id}",
"name": "{api_name}",
"prefix": "prefix",
"length": 16,
"meta": { "user_id": "123456" },
"expires_at": 123,
"verification_limit": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
api_id: '{api_id}',
name: '{api_name}',
prefix: 'prefix',
length: 16,
meta: {user_id: '123456'},
expires_at: 123,
verification_limit: 123
})
};
fetch('https://api.datkey.dev/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://api.datkey.dev/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([
'api_id' => '{api_id}',
'name' => '{api_name}',
'prefix' => 'prefix',
'length' => 16,
'meta' => [
'user_id' => '123456'
],
'expires_at' => 123,
'verification_limit' => 123
]),
CURLOPT_HTTPHEADER => [
"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.datkey.dev/keys"
payload := strings.NewReader("{\n \"api_id\": \"{api_id}\",\n \"name\": \"{api_name}\",\n \"prefix\": \"prefix\",\n \"length\": 16,\n \"meta\": {\n \"user_id\": \"123456\"\n },\n \"expires_at\": 123,\n \"verification_limit\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
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.datkey.dev/keys")
.header("Content-Type", "application/json")
.body("{\n \"api_id\": \"{api_id}\",\n \"name\": \"{api_name}\",\n \"prefix\": \"prefix\",\n \"length\": 16,\n \"meta\": {\n \"user_id\": \"123456\"\n },\n \"expires_at\": 123,\n \"verification_limit\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.datkey.dev/keys")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"api_id\": \"{api_id}\",\n \"name\": \"{api_name}\",\n \"prefix\": \"prefix\",\n \"length\": 16,\n \"meta\": {\n \"user_id\": \"123456\"\n },\n \"expires_at\": 123,\n \"verification_limit\": 123\n}"
response = http.request(request)
puts response.read_body{
"key": {
"id": "<key_id>",
"name": "<key_name>",
"key": "flox_sk_05ad2bfxxxxxxxx",
"prefix": "flox_sk",
"length": 16,
"verifications": 0,
"verification_limit": null,
"expires_at": 1733237153,
"meta": null,
"created_at": "2023-12-05T11:31:23.000000Z",
"updated_at": "2023-12-05T11:31:23.000000Z"
}
}{
"message": "key expiry cannot be back dated"
}Endpoints
Generate Key
POST
/
keys
Generate key
curl --request POST \
--url https://api.datkey.dev/keys \
--header 'Content-Type: application/json' \
--data '
{
"api_id": "{api_id}",
"name": "{api_name}",
"prefix": "prefix",
"length": 16,
"meta": {
"user_id": "123456"
},
"expires_at": 123,
"verification_limit": 123
}
'import requests
url = "https://api.datkey.dev/keys"
payload = {
"api_id": "{api_id}",
"name": "{api_name}",
"prefix": "prefix",
"length": 16,
"meta": { "user_id": "123456" },
"expires_at": 123,
"verification_limit": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
api_id: '{api_id}',
name: '{api_name}',
prefix: 'prefix',
length: 16,
meta: {user_id: '123456'},
expires_at: 123,
verification_limit: 123
})
};
fetch('https://api.datkey.dev/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://api.datkey.dev/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([
'api_id' => '{api_id}',
'name' => '{api_name}',
'prefix' => 'prefix',
'length' => 16,
'meta' => [
'user_id' => '123456'
],
'expires_at' => 123,
'verification_limit' => 123
]),
CURLOPT_HTTPHEADER => [
"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.datkey.dev/keys"
payload := strings.NewReader("{\n \"api_id\": \"{api_id}\",\n \"name\": \"{api_name}\",\n \"prefix\": \"prefix\",\n \"length\": 16,\n \"meta\": {\n \"user_id\": \"123456\"\n },\n \"expires_at\": 123,\n \"verification_limit\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
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.datkey.dev/keys")
.header("Content-Type", "application/json")
.body("{\n \"api_id\": \"{api_id}\",\n \"name\": \"{api_name}\",\n \"prefix\": \"prefix\",\n \"length\": 16,\n \"meta\": {\n \"user_id\": \"123456\"\n },\n \"expires_at\": 123,\n \"verification_limit\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.datkey.dev/keys")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"api_id\": \"{api_id}\",\n \"name\": \"{api_name}\",\n \"prefix\": \"prefix\",\n \"length\": 16,\n \"meta\": {\n \"user_id\": \"123456\"\n },\n \"expires_at\": 123,\n \"verification_limit\": 123\n}"
response = http.request(request)
puts response.read_body{
"key": {
"id": "<key_id>",
"name": "<key_name>",
"key": "flox_sk_05ad2bfxxxxxxxx",
"prefix": "flox_sk",
"length": 16,
"verifications": 0,
"verification_limit": null,
"expires_at": 1733237153,
"meta": null,
"created_at": "2023-12-05T11:31:23.000000Z",
"updated_at": "2023-12-05T11:31:23.000000Z"
}
}{
"message": "key expiry cannot be back dated"
}
The key returned would be show unencrypted the first time you generate it, ensure you show it to your user because it won’t be show to you again.
Body
application/json
Response
OK