Exchange an OAuth token for a key
curl --request POST \
--url https://api.datalyr.com/v1/keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"workspace_id": "wsPublic01",
"name": "Nightly export",
"scopes": [
"datalyr:read"
]
}
'import requests
url = "https://api.datalyr.com/v1/keys"
payload = {
"workspace_id": "wsPublic01",
"name": "Nightly export",
"scopes": ["datalyr:read"]
}
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({workspace_id: 'wsPublic01', name: 'Nightly export', scopes: ['datalyr:read']})
};
fetch('https://api.datalyr.com/v1/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.datalyr.com/v1/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([
'workspace_id' => 'wsPublic01',
'name' => 'Nightly export',
'scopes' => [
'datalyr:read'
]
]),
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.datalyr.com/v1/keys"
payload := strings.NewReader("{\n \"workspace_id\": \"wsPublic01\",\n \"name\": \"Nightly export\",\n \"scopes\": [\n \"datalyr:read\"\n ]\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.datalyr.com/v1/keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"workspace_id\": \"wsPublic01\",\n \"name\": \"Nightly export\",\n \"scopes\": [\n \"datalyr:read\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.datalyr.com/v1/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 \"workspace_id\": \"wsPublic01\",\n \"name\": \"Nightly export\",\n \"scopes\": [\n \"datalyr:read\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"key": "<string>",
"key_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"key_prefix": "<string>",
"scopes": [
"<string>"
],
"expires_at": "2023-11-07T05:31:56Z"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>",
"code": "scope_not_allowed_at_signup"
}{
"error": "<string>"
}{
"error": "<string>"
}Keys and approvals
Exchange an OAuth token for a key
Trade an OAuth access token for a named dk_agent_ key that a script can hold after the 15-minute token expires.
Rules. The token’s user must be an owner or admin of workspace_id. Every scope must be one the token holds. A write scope also needs the owner role. A dk_agent_ key gets 403 oauth_required.
Expiry. expires_in defaults to 90 days and cannot exceed 365 days. There is no non-expiring exchange key.
Limit. 10 per hour per user. It fails closed with 503.
POST
/
keys
Exchange an OAuth token for a key
curl --request POST \
--url https://api.datalyr.com/v1/keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"workspace_id": "wsPublic01",
"name": "Nightly export",
"scopes": [
"datalyr:read"
]
}
'import requests
url = "https://api.datalyr.com/v1/keys"
payload = {
"workspace_id": "wsPublic01",
"name": "Nightly export",
"scopes": ["datalyr:read"]
}
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({workspace_id: 'wsPublic01', name: 'Nightly export', scopes: ['datalyr:read']})
};
fetch('https://api.datalyr.com/v1/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.datalyr.com/v1/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([
'workspace_id' => 'wsPublic01',
'name' => 'Nightly export',
'scopes' => [
'datalyr:read'
]
]),
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.datalyr.com/v1/keys"
payload := strings.NewReader("{\n \"workspace_id\": \"wsPublic01\",\n \"name\": \"Nightly export\",\n \"scopes\": [\n \"datalyr:read\"\n ]\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.datalyr.com/v1/keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"workspace_id\": \"wsPublic01\",\n \"name\": \"Nightly export\",\n \"scopes\": [\n \"datalyr:read\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.datalyr.com/v1/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 \"workspace_id\": \"wsPublic01\",\n \"name\": \"Nightly export\",\n \"scopes\": [\n \"datalyr:read\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"key": "<string>",
"key_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"key_prefix": "<string>",
"scopes": [
"<string>"
],
"expires_at": "2023-11-07T05:31:56Z"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>",
"code": "scope_not_allowed_at_signup"
}{
"error": "<string>"
}{
"error": "<string>"
}Authorizations
The access token an MCP client holds. Accepted only by POST /keys and the key-request routes.
Body
application/json
A workspace id from list_workspaces.
Required string length:
1 - 80Every scope must be one the OAuth token holds.
Minimum array length:
1Available options:
datalyr:read, datalyr:write:rules, datalyr:write:links, datalyr:propose:scripts Seconds. Defaults to 90 days.
Required range:
86400 <= x <= 31536000Was this page helpful?