Content Import API

When you need to save web content into Agility for an import, you can use the Content Import API to do so.  It is a JSON API specifically created to allow you to save items into the Digital Content section of Agility.  This can be useful for doing complex content imports at the start of a project, or for keeping Agility content in sync with an outside system.  It is not meant to be used on a regular basis to replace the functions of the content manager.

Each of these calls works by sending and receiving JSON strings to the server.  We wanted to do this to allow you use dynamic objects without us having to update our Agility.Web assembly to .Net 4. 

Before you start, make sure you are using the latest version of the Agility.Web dll, available from the Developer Downloads section of the Agility Content Manager Settings screen.

Each method returns a JSON string in the following format:

{
  IsError: [true/false],
  Message: [if an error occurred, not null],
  ResponseData: [the object returned by the server]
}

It's up to your code to check for IsError, in addition to any other exceptions that may occur withing the method.

string enc = JsonConvert.SerializeObject(obj);

var retStr = ServerAPI.SaveContentItem(-1, "MyContent", "en-us", enc, null);

var retObj = JsonConvert.DeserializeObject<APIResult<int>>(retStr);
if (retObj.IsError)
{
   throw new ApplicationException(string.Format("Error: {0}", retObj.Message));
}

We recommend the JSON.Net library for serialization. 

Below is a list of all the calls you can make to the content server.  The type that you use for the APIResult object is indicated as the return type:

Methods
dynamic GetContentItems(Agility.Web.Objects.ServerAPI.GetContentItemArgs arg)
Gets a listing of content items based on the GetContentItemArgs parameter.
var retStr = ServerAPI.GetContentItems(
		new Agility.Web.Objects.ServerAPI.GetContentItemArgs()
		{
			referenceName = "ServerAPITest",
			columns = "Title;Date;NumberTest",
			languageCode = "en-us",
			pageSize = 20,
			rowOffset = 0,
			searchFilter = "",
			sortField = "Date",
			sortDirection = "DESC"
		}
	);

			
var retObj = JsonConvert.DeserializeObject<APIResult<List<dynamic>>>(retStr);

return Content(retStr);

if (retObj.IsError)
{
	//todo: handle error

}
else
{

	foreach (var item in retObj.ResponseData)
	{
		//access the columns from the items using their field names
		string title = item.Title;
		DateTime date = item.Date;
		int numberTest = item.NumberTest;					
	}
				
}

				
dynamic GetContentItem(int contentID, string languageCode)
Get a content item given a contentID and languageCode.  The item is return as a dictionary, but it can also be deserialized as a dynamic object.
			var retStr = ServerAPI.GetContentItem(contentID, "en-us");

			var retObj = JsonConvert.DeserializeObject<APIResult<dynamic>>(retStr);
			if (retObj.IsError)
			{
				//handle error
			}
			else
			{
				var item = retObj.ResponseData;
				string aFieldValue = item.AFieldName;
			}

				
void DeleteContent(int contentID, string languageCode)
Deletes a content item given a contentID and languageCode.
int RequestApproval(int contentID, string languageCode)
Requests approval for a content item given a contentID and languageCode.
int SaveContentItem(int contentID, string languageCode, string referenceName, string contentItemEncoded, string attachmentsEncoded)
Saves a content item based on contentID, languageCode, referenceName. 
var contentItem =  new {
	Title = "Test item 1",		  
	Date = new DateTime(2012, 10, 26),
	Number = 1
};

//if you are saving a new version of an EXISTING item in another language
//leave the ContentID property at -1, and set the "ItemContainerID" field 
//on the content item to the value of the previous item's content id.

var attachments = new[] {
	new {
		originalName = "[uploaded url]",
		mimeType = "[contentType]",
		fileSize = fileSize, //file size 
		managerID = "[FieldName]",
		AssetMediaID = mediaID //media id of uploaded file 
	}
};

string contentItemStr = JsonConvert.SerializeObject(contentItem);
string attachmentsStr = JsonConvert.SerializeObject(attachments);

var retStr = ServerAPI.SaveContentItem(
				-1, //if updating an item, pass content item here.
				"ServerAPITest", 
				"en-us", 
				contentItemStr, attachmentsStr);

var retObj = JsonConvert.DeserializeObject<APIResult<int>>(retStr);
if (retObj.IsError)
{
	//handle error
}
else
{
	int contentID = retObj.ResponseData;
}



			
int PublishContent(int contentID, string languageCode)
Publish a content item given a specific contentID and languageCode.  The same contentID should be returned on success.
dynamic UploadMedia(string mediaFolder, string fileName, string contentType, Stream fileData)
Upload a file to the Media & Documents section of Agility to the specified folder.
Stream s = Request.Files[0].InputStream;
string filename = Path.GetFileName(Request.Files[0].FileName);
string contentType = Request.Files[0].ContentType;

var retStr = ServerAPI.UploadMedia("Upload", filename, contentType, s);

var retObj = JsonConvert.DeserializeObject<APIResult<dynamic>>(retStr);
if (retObj.IsError)
{
	//handle error
}
else
{
	int mediaID = retObj.ResponseData.MediaID;
	string mediaUrl = retObj.ResponseData.Url;
	string thumbnailUrl = retObj.ResponseData.ThumbnailUrl;
	int size = retObj.ResponseData.Size;
}
				

LOGIN

Log in with your Agility username and password or
register for the site




Log In

REGISTER












Register

FORGOT PASSWORD