Create access token
For the complete documentation index, see llms.txt. For the full documentation snapshot, see llms-full.txt.
Create a new access token.
curl --request POST \
--url https://app.launchdarkly.com/api/v2/tokens \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"role": "reader"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/tokens"
payload = { "role": "reader" }
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({role: 'reader'})
};
fetch('https://app.launchdarkly.com/api/v2/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://app.launchdarkly.com/api/v2/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([
'role' => 'reader'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"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://app.launchdarkly.com/api/v2/tokens"
payload := strings.NewReader("{\n \"role\": \"reader\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
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://app.launchdarkly.com/api/v2/tokens")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"role\": \"reader\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"role\": \"reader\"\n}"
response = http.request(request)
puts response.read_body{
"_id": "61095542756dba551110ae21",
"ownerId": "569f514156e003339cfd3917",
"memberId": "569f514183f2164430000002",
"creationDate": "1628001602644",
"lastModified": "1628001602644",
"_links": {
"parent": {
"href": "/api/v2/tokens",
"type": "application/json"
},
"self": {
"href": "/api/v2/tokens/61095542756dba551110ae21",
"type": "application/json"
}
},
"_member": {
"_links": {
"self": {
"href": "/api/v2/members/569f183514f4432160000007",
"type": "application/json"
}
},
"_id": "569f183514f4432160000007",
"role": "admin",
"email": "ariel@acme.com",
"firstName": "Ariel",
"lastName": "Flores"
},
"name": "Example reader token",
"description": "A reader token used in testing and examples",
"customRoleIds": [],
"inlineRole": [],
"role": "reader",
"token": "1234",
"serviceToken": false,
"defaultApiVersion": 20240415,
"lastUsed": "0"
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "forbidden",
"message": "Forbidden. Access to the requested resource was denied."
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}Authorizations
Body
A human-friendly name for the access token
A description for the access token
Base role for the token
reader, writer, admin A list of custom role IDs to use as access limits for the access token
A JSON array of statements represented as JSON objects with three attributes: effect, resources, actions. May be used in place of a role.
Show child attributes
Show child attributes
Whether the token is a service token
The default API version for this token
Response
Access token response
The ID of the access token
"61095542756dba551110ae21"
The ID of the owner of the account for the access token
"569f514156e003339cfd3917"
The ID of the member who created the access token
"569f514183f2164430000002"
Timestamp of when the access token was created
"1628001602644"
Timestamp of the last modification of the access token
"1628001602644"
The location and content type of related resources
Show child attributes
Show child attributes
{
"parent": {
"href": "/api/v2/tokens",
"type": "application/json"
},
"self": {
"href": "/api/v2/tokens/61095542756dba551110ae21",
"type": "application/json"
}
}
Details on the member who created the access token
Show child attributes
Show child attributes
A human-friendly name for the access token
"Example reader token"
A description for the access token
"A reader token used in testing and examples"
A list of custom role IDs to use as access limits for the access token
[]
An array of policy statements, with three attributes: effect, resources, actions. May be used in place of a role.
Show child attributes
Show child attributes
[]
Base role for the token
"reader"
The token value. When creating or resetting, contains the entire token value. Otherwise, contains the last four characters.
"1234"
Whether this is a service token or a personal token
false
The default API version for this token
20240415
Timestamp of when the access token was last used
"0"
curl --request POST \
--url https://app.launchdarkly.com/api/v2/tokens \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"role": "reader"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/tokens"
payload = { "role": "reader" }
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({role: 'reader'})
};
fetch('https://app.launchdarkly.com/api/v2/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://app.launchdarkly.com/api/v2/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([
'role' => 'reader'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"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://app.launchdarkly.com/api/v2/tokens"
payload := strings.NewReader("{\n \"role\": \"reader\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
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://app.launchdarkly.com/api/v2/tokens")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"role\": \"reader\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"role\": \"reader\"\n}"
response = http.request(request)
puts response.read_body{
"_id": "61095542756dba551110ae21",
"ownerId": "569f514156e003339cfd3917",
"memberId": "569f514183f2164430000002",
"creationDate": "1628001602644",
"lastModified": "1628001602644",
"_links": {
"parent": {
"href": "/api/v2/tokens",
"type": "application/json"
},
"self": {
"href": "/api/v2/tokens/61095542756dba551110ae21",
"type": "application/json"
}
},
"_member": {
"_links": {
"self": {
"href": "/api/v2/members/569f183514f4432160000007",
"type": "application/json"
}
},
"_id": "569f183514f4432160000007",
"role": "admin",
"email": "ariel@acme.com",
"firstName": "Ariel",
"lastName": "Flores"
},
"name": "Example reader token",
"description": "A reader token used in testing and examples",
"customRoleIds": [],
"inlineRole": [],
"role": "reader",
"token": "1234",
"serviceToken": false,
"defaultApiVersion": 20240415,
"lastUsed": "0"
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "forbidden",
"message": "Forbidden. Access to the requested resource was denied."
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}