/apispaces/{apiSpaceId}/content/{fileId}

The Content service can be used to host assets for use in your messages using Multi part messages as it makes them URL accessible.

Uploading files to the Content service

The Content service can receive data in a variety of ways to make the process of uploading files simple. The various methods for uploading files are described below:

Endpoint

post https://api.comapi.com/apispaces/apiSpaceId/content

Path Params

apiSpaceId
string
required

The id of the api space to update

Security

Include your JWT security access token in the authorization HTTP header, and ensure that it has the content-w permission included. e.g.

Authorization: Bearer fyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI5MWM1OWI2YS01ZmY5LTRhOTctODRhNy0xYjFjYTRhMGZlODIiLCJpc3MiOiJodHRwczovL2FwaS5jb21hcGkuY29tL2FjY2Vzc3Rva2VucyIsImF1ZCI6Imh0dHBzOi8vYXBpLmNv5CJtc2c6YW55OnMiLCJtc2c6c21zOnMiLCJtc2c6ZmJtc2c6cyIsIm1zZzphcHBtc2c6cfd7zpjdXN0b206cyIsIm1zZzphbnk6aSIsIm1zZzpzbXM6aSIsIm1zZzpmYm1zZzppIiwibXNnOmFwcG1zZzppIiwibXNnOmN1c3RvbTppIiwibXNnOnIiLCJwbnY6ciIsInBudjp3IiwicHJvZjpyYSIsInByb2Y6d2EiLCJwcm9mOmRhI4JzZXNzOnJhIiwic2Vzczp3YSIsInNlc3M6ZGEiLCJ3ZWJob29rOnIiLCJ3ZWJob29rOmQiLCJ3ZWJob29rOnciLCJjb250ZW50OnciXSwic3ViIjoiOTFjNTliNmEtNWZmOS00YTk3LTg0YTctMWIxY2E0YTBmZTgyIiwicHJvZmlsZUlkIjoiQWNtZSIsIm5hbWUiOiJEZW1vIFRva2VuIiwiaWF0IjoxNDk2MTU1MzI5fQ.mhsg9ClOYW0YCttNkIyKzFOtsdlqydgDnsvBuVLOVM4

Using Form data

Use multi-part form data to upload the file data:

curl -X POST \
  https://api.comapi.com/apispaces/{Your API Space Id}/content \
  -H 'authorization: Bearer {Your security token}' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F 'file=@C:\Temp\myImage.png'
var fs = require("fs");
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.comapi.com/apispaces/{Your API Space Id}/content',
  headers: 
   { 'cache-control': 'no-cache',
     authorization: 'Bearer {Your security token}',
     'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' },
  formData: 
   { file: 
      { value: 'fs.createReadStream("C:\\Temp\\yourImage.png")',
        options: 
         { filename: 'C:\\Temp\\yourImage.png',
           contentType: null } } } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://api.comapi.com/apispaces/{Your API Space Id}/content")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
request["authorization"] = 'Bearer {Your security token}'
request["cache-control"] = 'no-cache'
request.body = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"C:\\Temp\\yourImage.png\"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"

response = http.request(request)
puts response.read_body
var data = new FormData();
data.append("file", "C:\\Temp\\yourImage.png");

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.comapi.com/apispaces/{Your API Sapce Id}/content");
xhr.setRequestHeader("authorization", "Bearer {Your security token}");
xhr.setRequestHeader("cache-control", "no-cache");

xhr.send(data);
import requests

url = "https://api.comapi.com/apispaces/{Your API Space Id}/content"

payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"C:\\Temp\\yourImage.png\"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
headers = {
    'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    'authorization': "Bearer {Your security token}",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

Using Base64 data

You can upload data using a Base64 string instead of streaming, but we generally recommend streaming, especially for files greater than a few hundred kilobytes.

To upload post a application/json body using the following contract:

PropertyTypeDescription
namestringThe name of the content asset
typestringThe MIME Type for the content asset
datastringThe Base64 string version of your files data
curl -X POST \
  https://api.comapi.com/apispaces/{Your API Space Id}/content \
  -H 'authorization: Bearer {Your security token}' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
	"name": "Item picture.png",
	"type": "image/png",
	"data": "{Your Base64 string}"
}'
var request = require("request");

var options = { method: 'POST',
  url: 'https://api.comapi.com/apispaces/{Your API Space Id}/content',
  headers: 
   { 'cache-control': 'no-cache',
     'content-type': 'application/json',
     authorization: 'Bearer {Your security token}' },
  body: 
   { name: 'Item picture.png',
     type: 'image/png',
     data: '{Your Base64 data string}' },
  json: true };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://api.comapi.com/apispaces/{Your API Space Id}/content")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["authorization"] = 'Bearer {Your security token}'
request["content-type"] = 'application/json'
request["cache-control"] = 'no-cache'
request.body = "{\n\t\"name\": \"Item picture.png\",\n\t\"type\": \"image/png\",\n\t\"data\": \"{Your Base64 data string}\"\n}"

response = http.request(request)
puts response.read_body
var data = JSON.stringify({
  "name": "Item picture.png",
  "type": "image/png",
  "data": "{Your Base64 data string}"
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.comapi.com/apispaces/{Your API Space Id}/content");
xhr.setRequestHeader("authorization", "Bearer {Your security token}");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");

xhr.send(data);
import requests

url = "https://api.comapi.com/apispaces/{Your API Space Id}/content"

payload = "{\n\t\"name\": \"Item picture.png\",\n\t\"type\": \"image/png\",\n\t\"data\": \"{Your Base64 data string}\"\n}"
headers = {
    'authorization': "Bearer {Your security token}",
    'content-type': "application/json",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

Upload Response

Upon successfully uploading a file using one of the techniques described above you will receive a HTTP 200 OK response and the following contract:

PropertyTypeDescription
idstringThe unique identifier for this content asset
namestringThe name of your content asset
sizeintegerSize in bytes of the content asset
typestringThe MIME Type for the content asset
folderstringThe virtual folder the content asset belongs to
urlstringThe URL to use to retrieve the content asset using a HTTP GET
_createdOnstringThe UTC date time of when this content asset was created in ISO 8601 format
_updatedOnstringThe UTC date time of when this content asset was last updated in ISO 8601 format
_createdBystringThe profile id that created the content asset
_updatedBystringThe profile id that last updated the content asset
{
    "id": "c71782490345d8b06d6b8a54c29a709b4555da39",
    "_createdOn": "2017-09-18T09:02:32.495Z",
    "_updatedOn": "2017-09-18T09:02:32.495Z",
    "_createdBy": "access:91c59b6a-5ff9-4a97-84a7-1b1ca4a0fe82",
    "_updatedBy": "access:91c59b6a-5ff9-4a97-84a7-1b1ca4a0fe82",
    "name": "yourImage.png",
    "size": 236071,
    "type": "image/png",
    "folder": "content",
    "url": "https://api.comapi.com/apispaces/ff42e8af-5fc3-40d4-a38c-034535c0a385/content/c71782490345d8b06d6b8a54c29a709b4555da39"
}

Retrieving an uploaded file

Simply make a HTTP(S) GET request to the URL returned from the upload to retrieve your file as described above.