ClickDimensions Image Manager API

Image Manager API

ClickDimensions supports API operations to allow interacting with the Image Manager component of Email Template and Web Content editors. This API is helpful for migrating images from legacy marketing applications or to enable integrations with marketing resource libraries. The Image Manager API includes methods to retrieve folder content, add/delete image folders and subfolders, and add/delete images.

Note: Using the Image Manager API requires you to develop and maintain custom code. The ClickDimensions technical support team does not offer technical support for custom code.

Working with the API

Each call to the Image Manager API requires an Account Key and Authorization Header. All calls to the Image Manager API should be in the form of a POST request. Most of the API’s methods resolve its parameters using a query string (the UploadImage method requires a JSON request body).

• Account Key: The Account Key can be found within CRM by navigating to Settings > ClickDimensions Settings. The Account Key is displayed at the top of the ClickDimensions Settings page.
• Authorization Header: For each API method, you must generate a new Authorization Header. To generate an Authorization Header, you will need the unique Token for the account. To find the Token, navigate in CRM to Settings > Customizations > Customize the System. Locate the cdi_settings.xml web resource. The Token is listed in this XML web resource.

An example of generating the Authorization Header:


public static string ComputeHash(string token, string uri)
{
byte[] secretBytes = ASCIIEncoding.ASCII.GetBytes(token);
HMACMD5 hmac = new HMACMD5(secretBytes);
byte[] dataBytes = ASCIIEncoding.ASCII.GetBytes(HttpUtility.UrlDecode(uri));
byte[] computedHash = hmac.ComputeHash(dataBytes);
string computedHashString = Convert.ToBase64String(computedHash);
return computedHashString;
}

Usage example:


var webRequest = (HttpWebRequest)WebRequest.Create("https://appdev.clickdimensions.com/Service.svc/av4CmktPKMk6drBsFYcaaw/folder");
webRequest.Method = "GET";
webRequest.Headers.Add("Authorization", ComputeHash("acSweI", "/Service.svc/av4CmktPKMk6drBsFYcaaw/folder"));

 

API Methods

In the following examples, the yellow highlighted portion of the request should be replaced with the correct Account Key, and the Authorization Header should be generated as noted above.

Note: The request samples below use the base URL for the ClickDimensions application in the US data center (https://app.clickdimensions.com/Service.svc/…). You should use the web services address for the data center where your ClickDimensions account is hosted.

API address by Data Center hosting account

US https://app.clickdimensions.com/Service.svc/
EU https://app-eu.clickdimensions.com/Service.svc/
AU https://app-au.clickdimensions.com/Service.svc/

GetImageFolderContent

Returns all the image definitions that contains image folder for particular account Id.

UriTemplate: Service.svc/{accountKey}/folder

Request sample:

POST: /Service.svc/foldercontent/ab3CjkrPJRk6erBsSYcxaw

Headers:

Authorization: 4+y6Cf2zs98CLHC1YOAGxA==

Parameters:

ab3CjkrPJRk6erBsSYcxaw – Account Key

Note: Authorization header is different for every API method.

AddImageFolder

Creates a new folder with the specified name under a parent folder. To create a new folder in the root directory, use “0” as the ID for the parent folder.

Request sample:

UriTemplate : Service.svc/{accountKey}/folder/{folderId}

https://app.clickdimensions.com/Service.svc/ab3CjkrPJRk6erBsSYcxaw/folder

Request body:

{
"folderName" : "New folder name",
"parentId" : "0",
}

ab3CjkrPJRk6erBsSYcxaw – Account Key

NewImageFolderName – Name for new folder

0 – ID of parent folder, in case you need to add a subfolder to the root, use 0 as ID.

Note: Authorization header is different for every API method.

To add a new subfolder to an existing parent folder, you first need to get the folder list using the GetImageFolderContent method in order to parse the response and learn the parent folder’s ID. The JSON response will look like this example:


{"CreatedOn":null,"Id":"0","Name":"Root","ParentId":null,"id":"0","name":"Root", "parentid":null,"subfolders":[{"CreatedOn":"\/Date(1455193141888)\/","Id":"56bc7c3673050d530ce969c9", "Name":"zzzz","ParentId":"0","id":"56bc7c3673050d530ce969c9","name":"zzzz", "parentid":"0","subfolders":[{"CreatedOn":"\/Date(1455193167203)\/","Id":"56bc7c4f73050d530ce969cb", "Name":"xxxx","ParentId":"56bc7c3673050d530ce969c9", "id":"56bc7c4f73050d530ce969cb","name":"xxxx", "parentid":"56bc7c3673050d530ce969c9","subfolders":[]}]}]}

In the above example JSON response, we have a structure like this:

  • Root
    • zzzz
      • xxxx

The ID of the ‘zzzz’ folder is 56bc7c3673050d530ce969c9
To add a new ‘Newsletter’ subfolder to the ‘zzzz’ folder you would post the following call:

POST https://app.clickdimensions.com/Service.svc/folder/ab3CjkrPJRk6erBsSYcxaw/Newsletter/ 56bc7c3673050d530ce969c9

Headers: 

Authorization: NRDTXizeYNuliZliysdR3g==

DeleteImageFolder

Deletes a folder by its ID

Request sample:

Uri template: Service.svc/{accountKey}/folder/{folderId}

HTTP method: DELETE

https://app.clickdimensions.com/Service.svc/ab3CjkrPJRk6erBsSYcxaw/FolderIdToDelete

Headers:

Authorization: cKS0xgfrLvrH1OWxQBSmRg==

Parameters:

ab3CjkrPJRk6erBsSYcxaw – Account Key

FolderIdToDelete – Folder ID that will be deleted

Note: Authorization header is different for every API method.

DeleteImage

Delete an image by its ID

UriTemplate :  https://app.clickdimensions.com/Service.svc/{accountKey}/image/{fileId}

HTTP method: DELETE

Request sample:

https://app.clickdimensions.com/Service.svc/ab3CjkrPJRk6erBsSYcxaw/image/ImageIdToDelete

Headers:

Authorization: dxBaHWWch+cYu7IeNGaNhQ==

Parameters:

ab3CjkrPJRk6erBsSYcxaw – Account Key

ImageIdToDelete – The image ID that will be deleted.

Note: Authorization header is different for every API method.

UploadImage

Upload a new or replace an existing image in the Image Manager

Method: POST

UriTemplate: https://app.clickdimensions.com/Service.svc/{accountKey}/image

Request sample:

POST: https://app.clickdimensions.com/Service.svc/ab3CjkrPJRk6erBsSYcxaw/image

Headers:

Authorization: +zd49i7ajkLkxCoF5JStWw==

Body:

{
"fileName": "testFileName.jpg",
"parentId":"0",
"replaceExisting":"true",
"content": “Base64Encoded bytes string”,
}

Parameters:

accountKey – The Account Key

fileName  – The file name that will be given to the image in the Image Manager

parentId – The ID of the folder where the image will be stored. If uploading to the root folder, use “0” as the ID.

replaceExisting – boolean parameter that indicates whether the file should overwrite an existing one with the same name. Values can be “true” or “false”.

contentBase64 encoded file content. The images are stored in Azure Blob Storage as Base64 encoded files. Below is an example in C# of converting an image to Base64 encoding. The resulting string should be placed in the “content” parameter.

Example of encoding an images as a Base64 string:

var webRequest = 
(HttpWebRequest)WebRequest.Create("https://app.clickdimensions.com/Service.svc/ab3CjkrPJRk6erBsSYcxaw/image");
webRequest.Method = "POST";
webRequest.Headers.Add("Authorization", ComputeHash("aPmtBJ", "/Service.svc/a7OfXqYcukiAsOhywWhvGw/image"));
webRequest.ContentType = "application/json; charset=utf-8";
var butes = File.ReadAllBytes("D:\\2.jpg");
var obj = new
{
fileName = "BiggerThanExpected.jpg",
parentId = "0",
replaceExisting = "true",
content = Convert.ToBase64String(butes)
};
var data = JsonConvert.SerializeObject(obj);
using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
{
streamWriter.Write(data);
}
var httpResponse = (HttpWebResponse)webRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}