Skip to main content

Assets

/api/v1/assets End Point - reads/writes assets data from your cbsplit account and return as json data.

Make an api request to visits endpoint#

http://YOUR_CBSPLIT_HOST/api/v1/assets

Every request should provide API Key via X-API-Key header.

API will return 100 results per page. Use page param for pagination.

Response#

API will return a JSON object like bellow:

{ entries: [], totalEntries: Number, page: Number, totalPages: Number }

Every entry will have the following structure:

  • id: Integer
  • created_at: UTC Timestamp
  • updated_at: UTC Timestamp
  • name: String
  • folder: String
  • image: Boolean
  • video: Boolean
  • script: Boolean
  • style: Boolean
  • text: Boolean
  • width: Integer Image width in pixels, if entry is an image
  • height: Integer Image height in pixels, if entry is an image
  • url: String Used on remote assets
  • async: Boolean Used on scripts
  • defer: Boolean Used on scripts

API Call Rate Limits#

Maximum 60 Requests Per Minute per IP Address. If limit reached 429 status code returned with an empty body.

Filters#

  • id
  • created_at
  • updated_at
  • name
  • folder
  • image
  • video
  • script
  • style
  • text
  • width
  • height
  • url
  • async
  • defer

By default any column will filter by exact value. e.g. { "created_at": "2020-02-03T17:16:00.485Z" } will return entries created at that exact timestamp.

To get entries created after specific time use gt/gte modifier: { "created_at.gt": "2020-02-03" } or { "created_at.gte": "2020-02-03" }

To get entries created before specific time use lt/lte modifier: { "created_at.lt": "2020-02-03" } or { "created_at.lte": "2020-02-03" }

To get entries created within specific timespan use between modifier, providing two comma separated values: { "created_at.between": "2020-02-03,2020-03-03" }

It's also possible to filter by multiple exact values by using in modifier and providing comma separated values: { "country.in": "US,CA" }

This same logic applies to all columns, except Boolean ones. To filter by Boolean columns use t for true and f for false. { "mobile": "t" } or { "mobile": "f" }

Filter Requests Examples#

/api/v1/assets?created_at.gt=2020-02-03/api/v1/assets?created_at.between=2020-02-03,2020-03-01/api/v1/assets?country.in=US,CA&mobile=t

Request Types#

Create#

This is post request - to upload assets to your cbsplit account#

curl -X POST \-H "X-API-Key: KEY" \-F "name=..." \-F "content=..." \ (or "url=..." or "file=@/path/to/file")http://YOUR_CBSPLIT_HOST/api/v1/assets
  • url, content and file columns are mutually exclusive so provide either one of them.
  • If providing url a hotlinking asset will be created.
  • That's it, no local copy will be created, resulting in a hotlinked remote resource.
  • Providing content will create a local asset with given content.
  • Uploading a file under file column will create a local asset from given file.
  • On success 200 response code returned with a JSON body containing the id: { "id": "N" }
  • On error 400 response code returned with body containing the error message string.

Update#

curl -X PUT \-H "X-API-Key: KEY" \-F "name=..." \http://YOUR_CBSPLIT_HOST/api/v1/assets
  • Any of above columns can be updated, except id, created_at and updated_at.
  • To update content use either content column or upload a file under file column.
  • To rename an asset provide name column.
  • Please note that no other updates accepted when renaming the asset so provide only the name column.
  • To move asset to another folder provide folder column (it should be an existing folder path).
  • Please note that no other updates accepted when moving the asset so provide only the folder column.
  • On success 200 response code returned with body containing true string.
  • On error 400 response code returned with body containing the error message string.

Delete#

curl -H "X-API-Key: KEY" -X DELETE http://YOUR_CBSPLIT_HOST/api/v1/assets/ID
  • On success 200 response code returned with body containing true string.
  • On error 400 response code returned with body containing the error message string.

Get#


Code Samples#

cURL - Command Line#

GET ASSETS#

curl -H "X-API-Key: XXXXXXXXXXXXXXXX" https://YOUR_CBSPLIT_HOST/api/v1/assets
  ⤑ GET ASSETS : PAGINATION#
curl -H "X-API-Key: XXXXXXXXXXXXXXXX" https://YOUR_CBSPLIT_HOST/api/v1/assets?page=2

CREATE ASSETS#

CREATE ASSETS : WITH - CONTENT#

curl -X POST -H "X-API-Key: 4BD088E0EE1E912E" -F "name=test.css" -F "content=html{background:#FFF}" https://demo.cbsplit.com/api/v1/assets

CREATE ASSETS : WITH - FILE UPLOAD#

curl -X POST -H "X-API-Key: XXXXXXXXXXXXXXXX" -F "name=2.png" -F "file=@./2.png" -F "width=1000" -F "height=1000" https://YOUR_CBSPLIT_HOST/api/v1/assets

CREATE ASSETS : WITH - HOTLINK CSS/JS#

curl -X POST -H "X-API-Key: XXXXXXXXXXXXXXXX" -F "name=site.css" -F "url=https://EXTERNAL_URL/site.css" https://YOUR_CBSPLIT_HOST/api/v1/assets

UPDATE ASSETS#

curl -X PUT -H "X-API-Key: XXXXXXXXXXXXXXXX" -F "content=html{background:#000}" https://demo.cbsplit.com/api/v1/assets/ID

DELETE ASSETS#

curl -H "X-API-Key: XXXXXXXXXXXXXXXX" -X DELETE http://demo.cbsplit.com/api/v1/assets/ID

NodeJs Code#

GET ASSETS#

fetch("https://YOUR_CBSPLIT_HOST/api/v1/assets", {  method: "get",  headers: {     'X-API-Key': 'XXXXXXXXXXXXXX',    'User-Agent': 'Mozilla/5.0 (compatible; cURL/7.68.0)'  }})  .then(res => res.json())  .then(data => console.log(data))  .catch(err => console.log(err))

CREATE ASSETS#

fetch("https://YOUR_CBSPLIT_HOST/api/v1/assets", {  method: "post",  headers: {     'X-API-Key': 'XXXXXXXXXXXXXX',    'User-Agent': 'Mozilla/5.0 (compatible; cURL/7.68.0)'  }})  .then(res => res.json())  .then(data => console.log(data))  .catch(err => console.log(err))

UPDATE ASSETS#

fetch("https://YOUR_CBSPLIT_HOST/api/v1/assets", {  method: "post",  headers: {     'X-API-Key': 'XXXXXXXXXXXXXX',    'User-Agent': 'Mozilla/5.0 (compatible; cURL/7.68.0)'  }})  .then(res => res.json())  .then(data => console.log(data))  .catch(err => console.log(err))

DELETE ASSETS#

fetch("https://YOUR_CBSPLIT_HOST/api/v1/assets", {  method: "post",  headers: {     'X-API-Key': 'XXXXXXXXXXXXXX',    'User-Agent': 'Mozilla/5.0 (compatible; cURL/7.68.0)'  }})  .then(res => res.json())  .then(data => console.log(data))  .catch(err => console.log(err))

PHP Code#

<?php
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "https://YOUR_CBSPLIT_HOST/api/v1/assets");$headers = [    'X-API-Key: XXXXXXXXXXXXXX',];curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; cURL/7.68.0)');curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
if(curl_errno($ch)) {    echo "curl error: " . curl_error($ch);} else {    $data = json_decode($response, true);    print_r($data);}curl_close($ch);
?>

Python code#

import requests
url = "https://YOUR_CBSPLIT_HOST/api/v1/assets"headers = {    "X-API-Key": "XXXXXXXXXXXX",    "User-Agent": "Mozilla/5.0 (compatible; cURL/7.68.0)"}
response = requests.get(url, headers=headers)if response.status_code == 200:    data = response.json()    for obj in data['entries']:        print (obj)else:    print(f"Error: {response.status_code}")

Ruby code#

require 'net/http'require 'uri'
url = URI.parse("https://YOUR_CBSPLIT_HOST/api/v1/assets")
http = Net::HTTP.new(url.host, url.port)http.use_ssl = (url.scheme == "https")
request = Net::HTTP::Get.new(url.path)request["X-API-Key"] = "xxxxxxxxxxx" # Replace with your actual API keyrequest["User-Agent"] = "Mozilla/5.0 (compatible; cURL/7.68.0)"
response = http.request(request)
puts response.body