Content API
You can find the project's base endpoint in your Project Settings / API Access section. In order to connect to the API you will need an access token.
Endpoints
GET Get Project
https://your-domain.com/api/your_project_id
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Example Requests
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request GET 'https://your-domain.com/api/your_project_id' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token'
GET /api/your_project_id HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
response = https.request(request)
puts response.read_body
GET Get Entries
https://your-domain.com/api/your_project_id/collection
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Example Requests
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id/your_collection',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request GET 'https://your-domain.com/api/your_project_id/your_collection' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token'
GET /api/your_project_id/your_collection HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id/your_collection", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id/your_collection")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
response = https.request(request)
puts response.read_body
GET Get One Entry
https://your-domain.com/api/your_project_id/collection/{content_id}
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Example Requests
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id/your_collection/{content_id}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request GET 'https://your-domain.com/api/your_project_id/your_collection/{content_id}' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token'
GET /api/your_project_id/your_collection/{content_id} HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id/your_collection/{content_id}", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id/your_collection/{content_id}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
response = https.request(request)
puts response.read_body
POST Create An Entry
https://your-domain.com/api/your_project_id/your_collection
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Body formdata
locale | en |
---|---|
title | Post Title |
... |
Save as Draft
If you want to create an entry as a draft add one more parameter to your request body.
Body formdata
draft | 1 |
---|
Example Requests
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id/your_collection',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('locale' => 'en', 'title' => 'Post Title'),
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request POST 'https://your-domain.com/api/your_project_id/your_collection' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token' \
--form 'locale="en"' \
--form 'title="Post Title"' \
POST /api/your_project_id/your_collection HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
Content-Length: 221
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="locale"
en
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="title"
Post Title
----WebKitFormBoundary7MA4YWxkTrZu0gW
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var formdata = new FormData();
formdata.append("locale", "en");
formdata.append("title", "Post Title");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id/your_collection", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id/your_collection")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
form_data = [['locale', 'en'],['title', 'Post Title']]
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body
Repeatable Fields
If your collection contains repeatable fields, when creating new entry you need to send that field as an array.
Here is an example using GuzzleHttp:
composer require guzzlehttp/guzzle:^7.0
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://your-domain.com',
]);
$token = 'your_access_token';
$response = $client->post(
'/api/your_project_id/your_collection', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '. $token,
],
'json' => [
'repeatable-field-name' => [
'apple',
'orange',
'banana',
],
],
],
);
echo $response->getBody()->getContents();
POST Update An Entry
https://your-domain.com/api/your_project_id/your_collection/update/{content_id}
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Body formdata
locale | en |
---|---|
title | Post Title |
... |
Example Requests
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id/your_collection/update/{content_id}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('locale' => 'en','title' => 'Post Title'),
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request POST 'https://your-domain.com/api/your_project_id/your_collection/update/{content_id}' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token' \
--form 'locale="en"' \
--form 'title="Post Title"' \
POST /api/your_project_id/your_collection/update/{content_id} HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
Content-Length: 221
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="locale"
en
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="title"
Post Title
----WebKitFormBoundary7MA4YWxkTrZu0gW
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var formdata = new FormData();
formdata.append("locale", "en");
formdata.append("title", "Post Title");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id/your_collection/update/{content_id}", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id/your_collection/update/{content_id}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
form_data = [['locale', 'en'],['title', 'Post Title']]
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body
Repeatable Fields
If your collection contains repeatable fields, when updating an entry you need to send that field as an array.
Editing existing content for repeatable fields is not available. Every parameter you send will be saved as a new entry.
Here is an example using GuzzleHttp:
composer require guzzlehttp/guzzle:^7.0
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://your-domain.com',
]);
$token = 'your_access_token';
$response = $client->post(
'/api/your_project_id/your_collection/update/:item_id', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '. $token,
],
'json' => [
'repeatable-field-name' => [
'apple',
'orange',
'banana',
],
],
],
);
echo $response->getBody()->getContents();
DEL Delete an Entry
https://your-domain.com/api/your_project_id/your_collection/{content_id}
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Example Requests
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id/your_collection/{content_id}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request DELETE 'https://your-domain.com/api/your_project_id/your_collection/{content_id}' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token'
DELETE /api/your_project_id/your_collection/{content_id} HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var requestOptions = {
method: 'DELETE',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id/your_collection/{content_id}", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id/your_collection/{content_id}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Delete.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
response = https.request(request)
puts response.read_body
GET Get Project Files
https://your-domain.com/api/your_project_id/project-media
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Example Requests
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id/project-media',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request GET 'https://your-domain.com/api/your_project_id/project-media' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token'
GET /api/your_project_id/project-media HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id/project-media", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id/project-media")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
response = https.request(request)
puts response.read_body
GET Get File By ID
https://your-domain.com/api/your_project_id/project-media/{file_id}
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Example Requests
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id/project-media/{file_id}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request GET 'https://your-domain.com/api/your_project_id/project-media/{file_id}' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token'
GET /api/your_project_id/project-media/{file_id} HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id/project-media/{file_id}", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id/project-media/{file_id}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
response = https.request(request)
puts response.read_body
GET Get File By Name
https://your-domain.com/api/your_project_id/project-media/name/{file_name}
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Example Requests
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id/project-media/name/{file_name}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request GET 'https://your-domain.com/api/your_project_id/project-media/name/{file_name}' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token'
GET /api/your_project_id/project-media/name/{file_name} HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id/project-media/name/{file_name}", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id/project-media/name/{file_name}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
response = https.request(request)
puts response.read_body
POST Upload a File
https://your-domain.com/api/your_project_id/project-media/upload
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Body formdata
file | your_file |
---|
Example Requests
composer require guzzlehttp/guzzle:^7.0
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'https://your-domain.com',
]);
$token = 'your_access_token';
if(isset($_FILES['file'])){
try {
$response = $client->post(
'/api/your_project_id/project-media/upload', [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '. $token,
],
'multipart' => [
[
'name' => 'file',
'contents' => fopen($_FILES['file']['tmp_name'], 'r'),
'filename' => $_FILES['file']['name']
],
],
],
);
echo $response->getBody()->getContents();
} catch (\GuzzleHttp\Exception\ClientException $e) {
echo $e->getMessage();
exit;
}
}
?>
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
Select file to upload:
<input type="file" name="file" id="file">
<input type="submit" value="Upload File" name="submit">
</form>
</body>
</html>
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id/project-media/upload',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('file'=> new CURLFILE('/path_to_file')),
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request POST 'https://your-domain.com/api/your_project_id/project-media/upload' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token' \
--form 'file=@"/path_to_file"'
POST /api/your_project_id/project-media/upload HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
Content-Length: 204
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="path_to_file"
Content-Type: image/jpg
(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var formdata = new FormData();
formdata.append("file", fileInput.files[0], "path_to_file");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id/project-media/upload", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id/project-media/upload")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
form_data = [['file', File.open('/path_to_file')]]
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body
DEL Delete a File
https://your-domain.com/api/your_project_id/project-media/{file_id}
Request Headers
Accept | application/json |
---|---|
Authorization | Bearer your_access_token |
Example Requests
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://your-domain.com/api/your_project_id/project-media/{file_id}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your_access_token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location --request DELETE 'https://your-domain.com/api/your_project_id/project-media/{file_id}' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your_access_token'
DELETE /api/your_project_id/project-media/{file_id} HTTP/1.1
Host: your-domain.com
Accept: application/json
Authorization: Bearer your_access_token
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer your_access_token");
var requestOptions = {
method: 'DELETE',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://your-domain.com/api/your_project_id/project-media/{file_id}", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
require "uri"
require "net/http"
url = URI("https://your-domain.com/api/your_project_id/project-media/{file_id}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Delete.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your_access_token"
response = https.request(request)
puts response.read_body
Parameters
Where Clauses
You can use where clauses to filter the results.
Example Request
https://your-domain.com/api/your_project_id/posts?where[id]=1
Single Where Clause
?where[id]=1
?where[locale]=en
?where[created_at]=2021-11-25
?where[updated_at]=2021-11-25
?where[published_at]=2021-11-25
?where[title]=About
Get the first result
https://your-domain.com/api/your_project_id/posts?first
like operator
?where[title][like]=about
not operator
?where[title][not]=about
in and not_in operators
?where[id][in]=1,2,3
?where[id][not_in]=4,5,6
lt and lte operators
less than
?where[price][lt]=200
less than or equal to
?where[price][lte]=200
gt and gte operators
greater than
?where[price][gt]=200
greater than or equal to
?where[price][gte]=200
null and not_null operators
?where[price]=null
?where[price]=not_null
between and not_between operators
?where[price][between]=20,21
?where[price][not_between]=20,21
Combining where clauses
?where[][price]=200&where[][name]=Watch
OR
?where[][price]=200&where[or][price]=300
Where Through Relation
You can filter your API requests through relation fields. There are two ways of doing this.
For example; let's say we have two collections. Posts and Authors.
Posts | ||
---|---|---|
Display Name | Field Name | Field Type |
Title | title | text |
Url | url | slug |
Author | author | relation(One to One to authors collection) |
Authors | ||
---|---|---|
Display Name | Field Name | Field Type |
Name | name | text |
Surname | surname | text |
You want to get the Post entries that has an author named John.
# Option 1
You can use two API requests.
1- Get the author id filtering by name:
https://your-domain.com/api/your_project_id/authors?where[name]=John
2- Get the Post entries that has the author id:
https://your-domain.com/api/your_project_id/posts?where[author]=1
# Option 2
You can use whereRelation parameter.
Get the Post entries that has author named John:
https://your-domain.com/api/your_project_id/posts?whereRelation[author][name]=John
Or you can get the Post entries by author's surname:
https://your-domain.com/api/your_project_id/posts?whereRelation[author][surname]=Doe
You can combine whereRelation option with other where clauses:
https://your-domain.com/api/your_project_id/posts?whereRelation[author][name]=John&where[title]=about
Counting Entries
To get the total number of entries you can use count operator.
Example Request
https://your-domain.com/api/your_project_id/posts?count
You can combine count operator with other filter options.
https://your-domain.com/api/your_project_id/posts?where[price][lt]=200&count
Sorting
Example Request
https://your-domain.com/api/your_project_id/posts?sort=created_at:DESC
https://your-domain.com/api/your_project_id/posts?sort=created_at:ASC,id:DESC
Limit and Offset
Limit the size of the returned results and skip a specific number of entries (useful for pagination).
Example Request (limit)
https://your-domain.com/api/your_project_id/posts?limit=20
Example Request (limit & offset)
https://your-domain.com/api/your_project_id/posts?limit=20&offset=5
With or Only Draft
By default the content from the API is published. But you can include drafts as well.
https://your-domain.com/api/your_project_id/posts?state=with_draft
If you want to get only drafts;
https://your-domain.com/api/your_project_id/posts?state=only_draft
Include Timestamp Fields
By default 3 timestamp fields (created_at, updated_at, published_at) are invisible in API calls.
You can include them using timestamps option.
https://your-domain.com/api/your_project_id/posts?timestamps