cancel
Showing results for 
Search instead for 
Did you mean: 

Search Contact by LastUpdatedDate

Participant

Search Contact by LastUpdatedDate

Hello,


       We have a requirement to retrieve the collection of contacts whose condition is based on lastupdatedate. We basically have to sync our database for the subscribed and unsubscribed users. For that i found information from your site link given below


 http://developer.constantcontact.com/doc/manageContacts#update_contact_info


Based on this I searched on the Utitliy class and I didn't see any equivalent method. So I added a new method based on the information provided in the above link. Below i have attached the piece of code.


 


 public static List<Contact> SearchContactByUpdatedDate(AuthenticationData authenticationData, string currentChunkId, out string nextChunkId)

        {

            //IList<Contact> list = Utility.SearchContactByEmail(AuthenticationData, emailAddress, out nextChunkId);


            //IList<ContactList> list = Utility.GetUserContactListCollection(AuthenticationData, out nextChunkId);

          

            //int count = list.Count;


            ValidateAuthenticationData(authenticationData);


            StringBuilder uriAddress = new StringBuilder();

            uriAddress.Append(authenticationData.AccountContactsUri);

            uriAddress.Append("?");

            uriAddress.AppendFormat("updatedsince={0}&listtype={1}", HttpUtility.UrlEncode("2010-02-09T01:00:00.000Z"),HttpUtility.UrlEncode("active"));


            string currentAddress = String.Format(CultureInfo.InvariantCulture, "{0}{1}",

                                                 uriAddress, currentChunkId);

            Stream stream = Stream.Null;

            try

            {

                // get the response stream

                stream = GetResponseStream(new Uri(currentAddress), authenticationData);


                // parse the stream and get a collection of Contacts

                return ContactComponent.GetContactCollection(stream, out nextChunkId);

            }

            catch (Exception e)

            {

                throw new ConstantException(e.Message, e);

            }

            finally

            {

                // close the response stream

                stream.Close();

            }

        }

        #endregion


For me everything is fine but I am not able to navigate after 50 records. Basically my call from my service will hit every 50 and keep adding to my local collection and once it collects the entire data then it will be send as a whole object in my local application. Also providing that sample below. The issue here I am not able to navigate to next set of 50 records and so...


string currentChunkId = String.Empty;

            string nextChunkId;


            string CurrentChunk;

            string NextChunk;

            long ChunkIndex;


            CurrentChunk = null;

            NextChunk = null;

            ChunkIndex = 1;




            IList<Contact> list;

            do

            {

                //list = Utility.SearchContactByUpdatedDate(AuthenticationData, "", out nextChunkId);

               


                string nextChunk;

                list = string.IsNullOrEmpty(CurrentChunk)

                           ? Utility.SearchContactByUpdatedDate(AuthenticationData, null, out nextChunk)

                           : Utility.SearchContactByUpdatedDate(AuthenticationData, CurrentChunk, out nextChunk);

               int count = list.Count;


               /// logic that will add the list to the main list.


                NextChunk = nextChunk;

                CurrentChunk = NextChunk;

                NextChunk = null;

                ChunkIndex += 50;


            } while (list.Count > 0);


 


Could you pleaes let me know how to achive this functionality? Or do you have any methods where i can access this. Also need from where i can grab the latest new dll's. Please provide me the location for the same.


 


Regards,


Elango

5 REPLIES
Moderator

Hi Elango,   The code you

Hi Elango,


 


The code you have should cycle through the updated contacts 50 at a time without issue, provided you have more than 50 updated contacts since 2/9/2010 to cycle through.  Keep in mind, the List variable is being overwritten every time you cycle through this loop so in the end you will only have the last batch of updated contacts.


 


We are in the process of putting out an updated ASP sample with some of our newer functionality included.  We do not have an estimated time for when this will be out, however once it is it will be available for download from our sample page.  Outside of that, we will simply replace the sample form when we have updates to the code, however the dlls have not changed for quite some time now.

Dave Berard
Senior Product Manager, Constant Contact
Participant

Thanks for your reply. The

Thanks for your reply. The issue here is I have more than 50 records but I am not able to navigate to next 50 records. It always returns me the same 50 records even though I use the code that pages. Please check the below code.


 


string currentChunkId = String.Empty;

            string nextChunkId;


            string CurrentChunk;

            string NextChunk;

            long ChunkIndex;


            CurrentChunk = null;

            NextChunk = null;

            ChunkIndex = 1;




            IList<Contact> list;

            do

            {

                //list = Utility.SearchContactByUpdatedDate(AuthenticationData, "", out nextChunkId);

               


                string nextChunk;

                list = string.IsNullOrEmpty(CurrentChunk)

                           ? Utility.SearchContactByUpdatedDate(AuthenticationData, null, out nextChunk)

                           : Utility.SearchContactByUpdatedDate(AuthenticationData, CurrentChunk, out nextChunk);

                int count = list.Count;


                NextChunk = nextChunk;

                CurrentChunk = NextChunk;

                NextChunk = null;

                ChunkIndex += 50;


            } while (list.Count > 0);


 


Regards,


Elango

Moderator

Hi Elango,   I did some

Hi Elango,


 


I did some digging and found the problem with the code and your modification.  Since our code was written before we allowed multiple parameters in the "next" attribute, the regular expression in the ContactComponent.cs file is failing to find the next node.  This so for the following method:


 


private static string GetLink(XPathNavigator navigator, string attributeValue, IXmlNamespaceResolver resolver)


 


Current Regex:


 


Regex r = new Regex(@"\?next\=(||\d|-)+$");


 


You will need to update this to include the &, ; and other characters as well:


 


Regex r = new Regex(@"\?next\=(||\d|-|;|&|%|.)+$");


 


Please note that once you correct this Regex, you will still have a problem with your SearchContactByUpdatedDate() method.  Since you only have one method that takes 3 arguments instead of two (one for the first with two arguments and one for all others with three arguments) you will have to modify your code to account for the CurrentChunk not being null.  Otherwise the URI you create will be a bad URI that has the initial search query and the next query together which returns a 400 Bad Request. 


 


I will bring these points up with our Developer group to make sure these are addressed in our next version.

Dave Berard
Senior Product Manager, Constant Contact
Participant

Thanks Dave. Its working

Thanks Dave. Its working now.


 


Regards,


Elango

Highlighted
Moderator

Re: test postback latency test 1

post comment

Still need help?
You can post a new message in the Community or find us on Twitter Mon-Fri 8am - 8pm ET. We've got real people waiting to help you out. Click below to start a conversation!