The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Timeout Errors on Opting Out Contacts

Highlighted
Occasional Contributor

Timeout Errors on Opting Out Contacts

Hello,

 

I am receiving time out errors trying to opt out contacts. I am using a basic HTTP DELETE method for opting out contacts in certain bounce categories from the last email sent. This used to work fine. I’ve tried this two days in a row, and I get the same result: my application gets a list of the contacts I want to opt-out, and seems to opt-out the first two fine (NoContent status code is returned); however, trying to opt-out the third contact returns time outs. The contact I was trying to delete this time was https://api.constantcontact.com/ws/customers/abdataclassaction/contacts/8826. When I view this contact in a web browser, it seems to be a valid contact. Since I’ve received timeout errors on the 3rd contact two days in a row, I doubt this is due to a certain contact.

 

Any idea what could be causing this?

 

My code used is:

 

deleteData(mApiUsername, mPassword, null, requestCall);

 

        private static void deleteData(string apiUsername, string password, XmlDocument xmlDoc, string requestCall)

        {

            try

            {

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestCall);

                request.Method = "DELETE";

                request.ContentType = "application/atom+xml";

                request.Credentials = new NetworkCredential(apiUsername, password);

                HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //The third requestCall times out here…

 

                if (response.StatusCode == HttpStatusCode.OK)

                {

                    Console.WriteLine(((HttpWebResponse)response).StatusDescription);

                    //Console.Read();

                    Stream dataStream = response.GetResponseStream();

                    StreamReader reader = new StreamReader(dataStream);

                    string responseFromServer = reader.ReadToEnd();

                    // Display the content.

                    Console.WriteLine(responseFromServer);

                    //Console.ReadLine();

                    // Clean up the streams.

                    reader.Close();

                    dataStream.Close();

                    response.Close();

                    //Console.ReadLine();

                    StringBuilder sb = new StringBuilder();

                    sb.Append(responseFromServer);

                    //xmlDoc.LoadXml(sb.ToString());

                }

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex);

                Console.ReadLine();

            }

        }

 

Thanks!

 

2 REPLIES 2
Highlighted
Employee

Re: Timeout Errors on Opting Out Contacts

Hi,

 

I'm sure this is due to a stream not getting closed.  We had to modify one of our wrappers because it was leaving streams open and causing a timeout error upon updating the 3rd contact as well.  I see you're closing your response stream, perhaps all you need is:

 

request.Close();

 

Best Regards,

Shannon W.

API Support Specialist

Highlighted
Occasional Contributor

Re: Timeout Errors on Opting Out Contacts

That fixed it. My HTTP deleteData was only running response.Close() if the status code returned was OK, which didn't make sense. Using response.Close() fixed it. Thanks!

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured