Peter Kjaer (SDL)

October 13, 2011

Identifying a Contact

Filed under: Audience Manager — Tags: , , , , , , — Peter Kjaer @ 9:14 AM

People are doing more and more with Audience Manager.

It’s exciting to see your product used in ways that you hadn’t anticipated – even if it does lead to questions that are hard to answer 🙂

Question

This question has been asked a couple of times recently:
How can I get the same Contact on both the Content Delivery and Content Manager side?

Because the internal ID of Contacts are different for both systems (it’s an auto-increment field in the database), you cannot use that as an identifier.
And there is no way to use the API to look up the ID for the other side.

So what’s a guy to do?

Answer (2011)

You need to use the identification fields. Keep in mind that these are different for every customer.

It  is very easy to get a Contact using those fields in the Audience Manager Content Delivery API.
Unfortunately, it is not currently straight-forward to do so on the Content Manager side.

In 2011 GA, you have to get a list of Contacts with those identification fields within a Publication:

TcmUri publicationId = new TcmUri(0, 22, 1); // Change 22 to your Publication Id

ContactFilter filter = new ContactFilter(UserContext.Current);
filter.ExtendedDetails.Add(new FilterFieldDefinition("IDENTIFICATION_KEY", "testContact", OperatorType.Equals));
filter.ExtendedDetails.Add(new FilterFieldDefinition("IDENTIFICATION_SOURCE", "Website", OperatorType.Equals));

IEnumerable<Contact> contacts = Contact.GetContacts(filter, new Publication(publicationId));
foreach (Contact contact in contacts)
{
	Console.WriteLine("E-mail address: {0}.", contact.EmailAddress);
	break;
}

This works because there will only ever be one Contact with those identification fields.
But there are 2 main problems with this:

  1. That’s a lot of code just to get one Contact.  You have to read it closely to understand what is going on.
  2. You need to know the Publication that a Contact is in.

Answer (2011 SP1)

In 2011 SP1, we have added a new constructor to the Contact class, which allows you to directly get a Contact by its identification fields:

var identificationFields = new Dictionary<string, string>
			  {
				  {"IDENTIFICATION_KEY", "testContact"},
				  {"IDENTIFICATION_SOURCE", "Website"}
			  };

Contact contact = new Contact(identificationFields);
Console.WriteLine("E-mail address: {0}.", contact.EmailAddress);

That is much clearer and has the added bonus of being a system-wide query, so you do not need to know where the Contact is stored.

Happy coding!

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: