Skip navigation

In previous posts, we looked at Eloqua API How To: Create and Retrieve a Data Card and Eloqua API How To: Mapping a Data Card to a Contact.  This time we will look at how to Update an existing Custom Data Object (or Data Card).

 

The code below will show you how to first retrieve the Data Card we want to update, modify a field value, then write that back to Eloqua.  Finally, we will pull back the DataCard and check the new value to confirm it was updated successfully.

 

Once again, I will be assuming that the code found Connecting to the Eloqua API - Generic Setup is being used to establish a connection to the Eloqua API.  It is also assumed that you know the ID of both the Data Card Set and Data Card that you wish to update, as well as the internal name of any field(s) to be updated.

 

As before, we will be using the EloquaService API. For more information on which API to use for specific functions, see Eloqua SOAP API - Which one do I use?.

 

Now, the code...

 

   class UpdateDataCard
    {
        static void Main()
        {
               var dataCardIDs = new int[1];
               string oldVal = "";
            
               try
               {
                    var service = new EloquaInstance("instance", "userid", "password");

                    // Build a DataCardSet Entity Type object - (the ID is the ID of an existing DataCardSet in Eloqua)
                    EntityType entityType = new EntityType { ID = 55, Name = "DataCardSet", Type = "DataCardSet" };

                    // Set the ID of the DataCard Entity
                    dataCardIDs[0] = 301677;

                    // Create a new list containing the fields you want populated
                   List<string> fieldList = new List<string>();

                    // Add the DataCard’s Title to the field list (this is the field we will update)
                   fieldList.Add("Title1");

                    // Build a Dynamic Entity array to store the results
                    DynamicEntity[] retrievedEntities;

                    // If the field list is empty - the request will return all Entity Fields
                   // Otherwise, only fields defined in the field list are returned
                   retrievedEntities = service.ServiceProxy.Retrieve(entityType, dataCardIDs, fieldList.Count == 0 ? null : fieldList.ToArray());

                    // Make sure a result was found
                    if (retrievedEntities.Length > 0)
                    {
                         foreach (DynamicEntity dynamicEntity in retrievedEntities)
                         {
                             //Save the old value so that we can confirm the change
                             oldVal = dynamicEntity.FieldValueCollection["Title1"];
                             //Update the value
                             dynamicEntity.FieldValueCollection["Title1"] = "A new value!";
                         }

                         //Perform the Update
                    service.ServiceProxy.Update(retrievedEntities);

                       Console.WriteLine("DataCard Updated Successfully!");
                    }

               //Now, pull the card again to make sure it updated
                retrievedEntities = service.ServiceProxy.Retrieve(entityType, dataCardIDs, fieldList.Count == 0 ? null : fieldList.ToArray());

               // Make sure a result was found
                if (retrievedEntities.Length > 0)
                {
                    foreach (DynamicEntity dynamicEntity in retrievedEntities)
                    {
                        Console.WriteLine(String.Format("Title was changed from \"{0}\" to \"{1}\"", oldVal, dynamicEntity.FieldValueCollection["Title1"]));
                    }
                         // Customize your own error handling
                  }
            catch (System.ServiceModel.FaultException ex)
            {
                // Catch Service Model Fault Exceptions
                Console.WriteLine(String.Format("Reson: {0}", ex.Reason.ToString()));
                Console.WriteLine(String.Format("Fault Type: {0}", ex.GetType().ToString()));
                Console.WriteLine(String.Format("Fault Code: {0}", ex.Code.Name.ToString()));
            }
          catch (Exception ex)
            {
                // Catch System Exceptions
                Console.WriteLine(String.Format("Exception Message: {0}", ex.Message.ToString()));
            }

            // Wait for user input before stepping out.
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();

        }
    }


When the program is run, a console window will pop up showing the results as seen below.


fileCUserstfields.png

fsakr

Eloqua API Chart

Posted by fsakr Jan 3, 2013

The following chart identifies some API operations available with different versions of the Eloqua product. Please note that the document is not exhaustive.

 

 

E10E9RESTSOAP
Core ObjectsCreateRetrieveUpdateDeleteCreateRetrieveUpdateDelete
Accounts

X

X

X

X

X

X

X

X

XX
Activities

X

X

XX
Campaigns

X

X

X

X

X

X
Contacts

X

X

X

X

X

X

X

X

XX
Contact Fields

X

X

X

X

X

XX
Contact Lists

X

X

X

X

X

X
Content Sections

X

X

X

X

X
Custom Objects Metadata

X

X

XX
Custom Objects Data

X

X

X

X

X

X

XXXX
EmailsX

X

XXX

X

XXX
Email Deployment

X

X

 

 

X

 

XX
Forms

X

X
Form DataX

X

XX

X

X

X

X

XX
Landing Pages

X

X

X

X

X
Microsites

X

X

X

X

X
Prospects

X

X

X

X

X
Users

X

X
VisitorsXXXX

X

X

X

X

X

 

We hope that you find this helpful.

Filter Blog

By date: By tag: