In the post Eloqua API How To: Create and Retrieve a Data Card, we looked at the basics of creating Data Cards.


Now that the new data card is created, you may wish to link it to a particular Contact record.  Let's take a look at how this can be accomplished.


When you created the Data Card, you created a Field/Value collection for the DynamicEntity, and then added email and title as fields in that collection:


// Create a Dynamic Entity's Field Value Collection
dynamicEntities[0].FieldValueCollection = new DynamicEntityFields();

dynamicEntities[0].FieldValueCollection.Add("Email1", "");

dynamicEntities[0].FieldValueCollection.Add("Title1", "Cloud");


To map this data card to a Contact, you will simply need to add a couple extra fields to the collection as follows:

dynamicEntities[0].FieldValueCollection.Add("MappedEntityType", "");

dynamicEntities[0].FieldValueCollection.Add("MappedEntityID", "");


For the MappedEntityType field, use either "1" for Contact (or "2" for Company).  For our example, let's map this card to a Contact record:

dynamicEntities[0].FieldValueCollection.Add("MappedEntityType", "1");


Now, for the MappedEntityID, you will need to have the ID for the Contact record that you wish to map to.  If you are creating a new contact record, and trying to map it to the Data Card right away, then just use the ContactID that you had returned to you when you created the contact (see Eloqua API How To: Create and Retrieve a Contact for more details):

var result = service.ServiceProxy.Create(dynamicEntities);

foreach (CreateResult t in result)
     // Successfull requests return a positive integer value for ID
     if (t.ID != -1)
          contactId = t.ID;
          success = true;


In this case, just use the ID that you stored in your variable contactID:

dynamicEntities[0].FieldValueCollection.Add("MappedEntityID", contactId.ToString());


If you want to use the ID of an already existing contact, then you'll have to retrieve the contact record first, then use the ID that you get back with the record.

SeeEloqua API How To: Query a Contact by Email Address or Eloqua API How To: Query a Contact by Multiple Fields for more details.