Create a project API key
curl --request POST \
--url https://api.moderationapi.com/v1/projects/{id}/api-keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "API key"
}
'import requests
url = "https://api.moderationapi.com/v1/projects/{id}/api-keys"
payload = { "name": "API key" }
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({name: 'API key'})
};
fetch('https://api.moderationapi.com/v1/projects/{id}/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.moderationapi.com/v1/projects/{id}/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' => 'API key'
]),
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.moderationapi.com/v1/projects/{id}/api-keys"
payload := strings.NewReader("{\n \"name\": \"API key\"\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.moderationapi.com/v1/projects/{id}/api-keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"API key\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moderationapi.com/v1/projects/{id}/api-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 \"name\": \"API key\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"name": "<string>",
"projectId": "<string>",
"createdAt": "<string>",
"secretKey": "<string>"
}{
"type": "invalid_request_error",
"code": "invalid_request",
"message": "Invalid input data",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "authentication_error",
"code": "unauthorized",
"message": "Authorization not provided",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "permission_error",
"code": "permission_denied",
"message": "Insufficient access",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "not_found_error",
"code": "resource_not_found",
"message": "Not found",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "rate_limit_error",
"code": "rate_limit_exceeded",
"message": "Rate limit exceeded",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}Create a project API key
Create a new secret API key for a project and return it. Give each app or computer its own key, so you can revoke one without breaking the others. The project’s existing keys keep working. Needs the projects:write permission.
Create a project API key
curl --request POST \
--url https://api.moderationapi.com/v1/projects/{id}/api-keys \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "API key"
}
'import requests
url = "https://api.moderationapi.com/v1/projects/{id}/api-keys"
payload = { "name": "API key" }
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({name: 'API key'})
};
fetch('https://api.moderationapi.com/v1/projects/{id}/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.moderationapi.com/v1/projects/{id}/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' => 'API key'
]),
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.moderationapi.com/v1/projects/{id}/api-keys"
payload := strings.NewReader("{\n \"name\": \"API key\"\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.moderationapi.com/v1/projects/{id}/api-keys")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"API key\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moderationapi.com/v1/projects/{id}/api-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 \"name\": \"API key\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"name": "<string>",
"projectId": "<string>",
"createdAt": "<string>",
"secretKey": "<string>"
}{
"type": "invalid_request_error",
"code": "invalid_request",
"message": "Invalid input data",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "authentication_error",
"code": "unauthorized",
"message": "Authorization not provided",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "permission_error",
"code": "permission_denied",
"message": "Insufficient access",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "not_found_error",
"code": "resource_not_found",
"message": "Not found",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "rate_limit_error",
"code": "rate_limit_exceeded",
"message": "Rate limit exceeded",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
The ID of the project.
Body
application/json
A name for the key, shown on the API keys page of the dashboard. Name it after where the key is used, for example the app or the computer.
Required string length:
1 - 50Response
API key created successfully
The ID of the API key.
The key's name.
The ID of the project the key belongs to.
When the key was created.
The new secret API key. Use it to moderate content in this project. It is also shown in the project's settings.
Was this page helpful?