In past How-To articles, we've touched on the basics of querying through the SOAP API.
In Eloqua API How To: Query a Contact by Email Address, we looked at how to find a contact based on email address, and in Eloqua API How To: Query a Contact by Multiple Fields we looked at using multiple fields. We even touched on using dates in Eloqua API How To: Retrieve Activity Data through the API to bring back activity data.
This post will look at a few more ways to query for contacts, using different fields and criteria.
For this example, we will assume that we are searching for Contacts, and that the code HERE is being used.
Let's start by creating a string to hold the search query.
string searchQuery = "";
We could query using any contact field, but let's first look at using the Modified Date field.
First, we can query for contacts that have been modified since January 1st, 2012:
searchQuery = "C_DateModified>2012-01-01";
We could also find contacts that have been modified between January 1st, 2011 and January 1st, 2012:
searchQuery = "C_DateModified>2011-01-01 and C_DateModified<2012-01-01";
We've already seen how to search for a single email address:
searchQuery = "C_EmailAddressfirstname.lastname@example.org'";
But how about looking for multiple email addresses in one call? An example of this is demonstrated below:
In this case, if you are querying on the same field, and using a "=" operator, the API will actually treat an "and" as an "or" and return all matching values.
Once you've constructed your searchQuery, define a container for the results.
Next, execute the Query function and pass in the searchQuery string.
queryResult = service.ServiceProxy.Query(contactEntityType, searchQuery, fieldList.ToArray(), currentPage, pageSize);
When the Query is executed, the contacts meeting the criteria will be returned for use in your code.
These search patterns can be used with any contact field, so play around with them to come up with the best method to suit your needs.