Create an API key
curl --request POST \
--url https://api.segmnt.cloud/v1/projects/{projectId}/api-keys \
--header 'Content-Type: application/json' \
--cookie segmnt_session= \
--data '
{
"name": "Course site backend",
"scope": "full"
}
'import requests
url = "https://api.segmnt.cloud/v1/projects/{projectId}/api-keys"
payload = {
"name": "Course site backend",
"scope": "full"
}
headers = {
"cookie": "segmnt_session=",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {cookie: 'segmnt_session=', 'Content-Type': 'application/json'},
body: JSON.stringify({name: 'Course site backend', scope: 'full'})
};
fetch('https://api.segmnt.cloud/v1/projects/{projectId}/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://api.segmnt.cloud/v1/projects/{projectId}/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' => 'Course site backend',
'scope' => 'full'
]),
CURLOPT_COOKIE => "segmnt_session=",
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.segmnt.cloud/v1/projects/{projectId}/api-keys"
payload := strings.NewReader("{\n \"name\": \"Course site backend\",\n \"scope\": \"full\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("cookie", "segmnt_session=")
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.segmnt.cloud/v1/projects/{projectId}/api-keys")
.header("cookie", "segmnt_session=")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Course site backend\",\n \"scope\": \"full\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.segmnt.cloud/v1/projects/{projectId}/api-keys")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["cookie"] = 'segmnt_session='
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Course site backend\",\n \"scope\": \"full\"\n}"
response = http.request(request)
puts response.read_body{
"id": "key_3hT9aZ",
"name": "<string>",
"prefix": "Abcd1234",
"scope": "full",
"createdAt": "2023-11-07T05:31:56Z",
"lastUsedAt": "2023-11-07T05:31:56Z",
"secret": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>",
"limit": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>",
"limit": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>",
"limit": "<string>"
}API keys
Create an API key
POST
/
v1
/
projects
/
{projectId}
/
api-keys
Create an API key
curl --request POST \
--url https://api.segmnt.cloud/v1/projects/{projectId}/api-keys \
--header 'Content-Type: application/json' \
--cookie segmnt_session= \
--data '
{
"name": "Course site backend",
"scope": "full"
}
'import requests
url = "https://api.segmnt.cloud/v1/projects/{projectId}/api-keys"
payload = {
"name": "Course site backend",
"scope": "full"
}
headers = {
"cookie": "segmnt_session=",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {cookie: 'segmnt_session=', 'Content-Type': 'application/json'},
body: JSON.stringify({name: 'Course site backend', scope: 'full'})
};
fetch('https://api.segmnt.cloud/v1/projects/{projectId}/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://api.segmnt.cloud/v1/projects/{projectId}/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' => 'Course site backend',
'scope' => 'full'
]),
CURLOPT_COOKIE => "segmnt_session=",
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.segmnt.cloud/v1/projects/{projectId}/api-keys"
payload := strings.NewReader("{\n \"name\": \"Course site backend\",\n \"scope\": \"full\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("cookie", "segmnt_session=")
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.segmnt.cloud/v1/projects/{projectId}/api-keys")
.header("cookie", "segmnt_session=")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Course site backend\",\n \"scope\": \"full\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.segmnt.cloud/v1/projects/{projectId}/api-keys")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["cookie"] = 'segmnt_session='
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Course site backend\",\n \"scope\": \"full\"\n}"
response = http.request(request)
puts response.read_body{
"id": "key_3hT9aZ",
"name": "<string>",
"prefix": "Abcd1234",
"scope": "full",
"createdAt": "2023-11-07T05:31:56Z",
"lastUsedAt": "2023-11-07T05:31:56Z",
"secret": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>",
"limit": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>",
"limit": "<string>"
}{
"type": "<string>",
"title": "<string>",
"status": 123,
"code": "plan_limit_reached",
"detail": "<string>",
"limit": "<string>"
}Body
application/json
Response
Key created. secret is shown only in this response. We store only a hash.
full (default): the key can call every /v1 route of its project.
playback: the key can call ONLY the playback-token mint route, so a
key that sits on a customer's server (for example a WordPress site)
cannot upload, encode, delete, read account data, or spend money.
Available options:
full, playback Example:
"full"