Retrieving emails from ExactTarget based on a folder

There are some interesting documentation issues with regards to ExactTarget. For instance, if you are programming against ExactTarget to retrieve all emails which belong to a specific folder, then you would expect that you can filter on the 'folder' attribute of an email. Apparently that doesn't work, but you will have to use the CategoryID attribute. But then again, filtering against the CategoryID doesn't filter the result on the folder.

According to ExactTarget:
There is a known issue with the MSCRM integrated accounts when using a Simple Filter Part on CategoryId via the API. You can use sfp.Property=”fkCategoryid’ and that should work. So you can above method or as a workaround, you can do the filtering in the client application (so your application once you retrieve all the data).

So far the theoretical information. Now the useful summary:

public ArrayList GetEmails(int folderId)
// Intialize variables
String requestID;
APIObject[] results;

// Create Filter
SimpleFilterPart sfp = new SimpleFilterPart();
sfp.Property = "fkCategoryID";
sfp.SimpleOperator = SimpleOperators.equals;
sfp.Value = new string[] { folderId.ToString() };

// Create RetrieveRequest
RetrieveRequest rr = new RetrieveRequest();
rr.QueryAllAccounts = true;
rr.QueryAllAccountsSpecified = true;
rr.ObjectType = "Email";
rr.Properties = new string[] { "Name", "ID", "CategoryID" };
rr.Filter = sfp;

// Execute RetrieveRequest
String status = _exactTarget.Retrieve(rr, out requestID, out results);

ArrayList alEmail = new ArrayList();
for (int i = 0; i < results.Length; i++)
Email email = (Email)results[i];
return alEmail;

No comments: