(500) Internal Server Error

SOLVED
Go to solution
ToddB12
Campaign Expert
0 Votes

I have been using Constant Contact API for some time and it has been working fine. All of a sudden I am getting: "The remote server returned an error: (500) Internal Server Error." Nothing in my code has changed. I am using the libraries for .NET, and the error occurs at the 'finally' block in Utility.cs:

 

            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();
            }

 

It seems that this is a problem within Constant Contact as I haven't changed anything with my Authentication Data and am just passing an email address. It occurs when I am trying to use the function Utility.SearchContactByEmail. Any help is appreciated, thanks!

1 ACCEPTED SOLUTION
Nick_G
Employee

Hey Todd,

 

We experienced an issue with our API earlier today, and we restarted the service. It seems to have resolved these issues in all my testing, so let me know if you're still experiencing those same errors. Thanks!

Nick Galbraith
Support Engineer

View solution in original post

26 REPLIES 26
Nick_G
Employee

Hey Todd,

 

We experienced an issue with our API earlier today, and we restarted the service. It seems to have resolved these issues in all my testing, so let me know if you're still experiencing those same errors. Thanks!

Nick Galbraith
Support Engineer
ToddB12
Campaign Expert
0 Votes

Thanks for the quick reply, Nick. I did temporarly remove the code that was calling the API, so I will readd it this afternoon and let you know if I have any issues. Thanks!

ToddB12
Campaign Expert
0 Votes

Good to go!

ErikF18
Rookie
0 Votes

How exactly do you restart the service.  I am experiencing the same 500 error message. 

DaveBerard
Employee
0 Votes

We restart our servers periodically when doing software updates or when we take servers in and out of our active pools and for standard maintenance.  This specific thread had to do with an issue where some of our production servers had become unresponsive back in 2012, this is not currently the case as all of our servers are up, live and healthy.  There is no way customers like yourself would be able to restart our services.

 

500 errors can come up for many reasons, especially with our v1 XML API.  Typically, it's caused by XML that is incorrectly formed or has invalid characters that can cause our XML parser to throw an unhandled exception, thus the 500 Server Error instead of a valid error message.  It's usually best for you to provide a code sample and/or your XML payload which is causing the error for us to give you more support. 

Dave Berard
Senior Product Manager, Constant Contact
ErikF18
Rookie
0 Votes

I understand.  I actually not sure why the error is occuring.  It was working perfectly fine til just a couple days ago.  

DaveBerard
Employee
0 Votes

I did take a look at our service logs.  We had an issue with some of our servers from late July 23rd to early July 24th which caused a slight rise in 500 errors.  The 500 errors were intermittent and should be resolved.  Let me know if you see any more happening today.

Dave Berard
Senior Product Manager, Constant Contact

This is the most "recent" post I could find on this issue so I am starting here. As of 05/06/14 - I began seeing this error in the Convio Common Ground Platform hosted on the Salesforce instance. We use the plug in and do not have direct access to the code so I am not immediately able to determine if there are code errors being thrown. I contacted Common Ground and they advised the error is in Constact Contact. Any thoughts as to what is occuring?

 

Screenshots attached.  


CC server error.JPG

We would need to work with Convio development team to troubleshoot this.  Without knowing what the call was, will be hard to track this down and get more information.  Any chance you can open a ticket with them and connect us with their team?  Our direct email address for API support is apisupport@constantcontact.com.

Dave Berard
Senior Product Manager, Constant Contact
VC1977
Campaign Collaborator
0 Votes

I think I am getting a similar issue for the last couple months.  It appears that when using your API and executing this function Utility.SearchContactByEmail(...) I am getting a timeout after processing about 10 records in my batch cycling through 1 by 1.  Then I wait at least 30+ minutes later and another 10 will go through.  This code was developed back in 2013 without any change since and uses the API utility run time Version v2.0.50727.   I saw on some of the threads that Constant Contact needs to restart some server(s) and or service(s) to get this going again... If so can someone at Constant Contact do that or tell me what needs to be done to eliminate this issue.

Jimmy_D
Employee
0 Votes

Hi @VC1977,

 

This thread is several years old and refers to our v1 API which is deprecated. Are you using the v1 API and encountering this issue, or are you using our v2 or v3 API? If you are using our v1 API I would highly recommend to look in to updating to one of our other versions.


Regards,
Jimmy D.
Tier II API Support Engineer
MatthewB03
Rookie
0 Votes

Hello,

I am assuming the technical support a company that has been using Salesforce (professional) and Constant Contact together for a while. Recently, for no discernable reason, the sync between the two ceased working.

 

I installed the latest version and then added the button to the Contacts tab in Salesforce. When I use the button to upload a Salesforce contact to Constant Contact, an error is displayed "Upload Failed" and the associated comment is "Internal Server Error". The funny part is that the contact actually gets synced to Constant Contact.  Please see the attached image for more info.

 

Can you tell me what I need to do to either eliminate the error message and or help the system see that the sync actually worked?

 

Screenshot 2014-06-14 14.32.09.png

 

Thanks,

 

Eric


Screenshot 2014-06-14 14.32.09.png
Elijah_G
Marketing Legend
0 Votes

Hi Eric,

 

This issue is a known problem that we have identified within the Constant Contact for Salesforce application. As you stated it is correctly uploading the contacts, but it is reporting errors within the application. We have submitted a request to investigate and correct the issue to our team which maintains the application and we should hopefully have an update to correct this soon.

 

Best Regards,

Elijah G.
API Support Engineer
locherlav
Campaign Collaborator
0 Votes

i am faceing the Same problem please give  fix it.  below is my code and csv file
HttpWebRequest httpclient = (HttpWebRequest)WebRequest.Create("https://api.constantcontact.com/v2/activities/addcontacts?api_key=wv7crkj3rk3gy52ykqegkxqq");
string boundary = "--" + Guid.NewGuid().ToString();
string filename = "F:\\constant contact Wrapper\\Constant.csv";
httpclient.Headers.Add("Authorization", "Bearer 2269f201-044b-45f7-8015-e5e107555dd5");
// httpclient.Headers.Add("Accept", "application/json");
// httpclient.Headers.Add("content-type", "multipart/form-data");
// File fileToUse = new File();
// FileBody data = new FileBody(fileToUse);
httpclient.Method = "POST";
httpclient.ContentType = string.Format("multipart/form-data");
httpclient.Accept = "application/json";
httpclient.PreAuthenticate = true;
//string filename = "C:\\Development\\constantcontact\\emailkust.csv";
StringBuilder sb= new StringBuilder();
sb.AppendLine(boundary);
sb.AppendLine("content-disposition: form-data; name="+filename +"");
sb.AppendLine();
sb.AppendLine("Constant.csv"); //'filename
sb.AppendLine(boundary);
sb.AppendLine("content-disposition: form-data");//; name=""lists""");
sb.AppendLine();
sb.AppendLine("1") ;//' List Number
sb.AppendLine(boundary);
// sb.AppendLine("content-disposition: file; name=""data"" filename=""emailkust.csv""");
sb.AppendLine("Content-Type: text/csv");
sb.AppendLine();
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
byte[] contents = new byte[fs.Length];
fs.Read(contents, 0, contents.Length);
sb.Append(Encoding.Default.GetString(contents));
}
sb.AppendLine(boundary );
byte[] fulldata = Encoding.Default.GetBytes(sb.ToString());
// httpclient.ContentLength == fulldata.Length;
using (Stream sw = httpclient.GetRequestStream()) {
sw.Write(fulldata, 0, fulldata.Length);
}
try {
HttpWebResponse response = httpclient.GetResponse() as HttpWebResponse;
using (StreamReader sr = new StreamReader(response.GetResponseStream())) {
//MessageBox.Show(sr.ReadToEnd());
}
} catch (WebException ex) {
using (StreamReader sr = new StreamReader(ex.Response.GetResponseStream())) {
//MessageBox.Show("Error Message:" + e.Message + Constants.vbCr + Constants.vbLf + "Error Body: " + sr.ReadToEnd(), "Web Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Elijah_G
Marketing Legend

Hello locherlav,

 

 

 After reviewing your code, I see that you have commented the following line:

// sb.AppendLine("content-disposition: file; name=""data"" filename=""emailkust.csv""");

 With this line commented out, there is a very important piece of information missing from the multipart request that must be included. You will need to uncomment this line and make sure that the correct filename is used here. Once you have accomplished this, you should see success.

 

If you are still seeing an error, please reply to this post with the Error Body contained in the error message.

 

Best Regards,

Elijah G.
API Support Engineer
locherlav
Campaign Collaborator
0 Votes

   HttpWebRequest httpclient = (HttpWebRequest)WebRequest.Create("https://api.constantcontact.com/v2/activities/addcontacts?api_key=[REDACTED]");
            string boundary = "--" + Guid.NewGuid().ToString();
              string  filename = "F:\\constant contact Wrapper\\Constant.csv";
            httpclient.Headers.Add("Authorization", "Bearer [REDACTED]");
           // httpclient.Headers.Add("Accept", "application/json");
            // httpclient.Headers.Add("content-type", "multipart/form-data");
          // File fileToUse = new File();
           // FileBody data = new FileBody(fileToUse);
             httpclient.Method = "POST";
        httpclient.ContentType = string.Format("multipart/form-data");
        httpclient.Accept = "application/json";
        httpclient.PreAuthenticate = true;
           //string  filename = "C:\\Development\\constantcontact\\emailkust.csv";
            StringBuilder sb= new StringBuilder();
             sb.AppendLine(boundary);
        sb.AppendLine("content-disposition: form-data; name="+filename  +"");
        sb.AppendLine();
        sb.AppendLine("Constant.csv"); //'filename
        sb.AppendLine(boundary);
        sb.AppendLine("content-disposition: form-data; name=" + filename + "");
        //sb.AppendLine("content-disposition: form-data");//; name=""lists""");
        sb.AppendLine();
        sb.AppendLine("1") ;//' List Number
        sb.AppendLine(boundary);
        sb.AppendLine("content-disposition: form-data; name=" + filename + "");
          //   sb.AppendLine("content-disposition: file");
          //   sb.AppendLine("content-disposition: file; name=""data"" filename=""emailkust.csv""");
        //sb.AppendLine("content-disposition: form-data; filename=Constant.csv");
        sb.AppendLine("Content-Type: text/csv");
        sb.AppendLine();
            using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                    byte[] contents = new byte[fs.Length];
                    fs.Read(contents, 0, contents.Length);
                    sb.Append(Encoding.Default.GetString(contents));
            }
              sb.AppendLine(boundary );
            byte[] fulldata = Encoding.Default.GetBytes(sb.ToString());
           // httpclient.ContentLength == fulldata.Length;
            using (Stream sw = httpclient.GetRequestStream()) {
    sw.Write(fulldata, 0, fulldata.Length);
}
            try {
    HttpWebResponse response = httpclient.GetResponse() as HttpWebResponse;
    using (StreamReader sr = new StreamReader(response.GetResponseStream())) {
        //MessageBox.Show(sr.ReadToEnd());
    }
} catch (WebException ex) {
    using (StreamReader sr = new StreamReader(ex.Response.GetResponseStream())) {
        //MessageBox.Show("Error Message:" + e.Message + Constants.vbCr + Constants.vbLf + "Error Body: " + sr.ReadToEnd(), "Web Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

 

 

 

i got an error in that code:The remote server returned an error: (400) Bad Request.

please provide the my csv file is correct or not an if i can change my code?

Elijah_G
Marketing Legend
0 Votes

Hello locherlav,

 

I believe that this code you are working on is a conversion of an existing code to create a bulk upload fom VB.NET to C#. During the conversion process, several important parts of the multipart request were broken. I have taken the time to correct the code and you should see success with the code below. Please take a moment to read the comments in the code, as they are relevant to having it work properly.

 

Code:

HttpWebRequest httpclient = (HttpWebRequest)WebRequest.Create("https://api.constantcontact.com/v2/activities/addcontacts?api_key=wv7crkj3rk3gy52ykqegkxqq");
string boundary = "--" + Guid.NewGuid().ToString();
string filename = "F:\\constant contact Wrapper\\Constant.csv";
httpclient.Headers.Add("Authorization", "Bearer 2269f201-044b-45f7-8015-e5e107555dd5");
httpclient.Method = "POST";
httpclient.ContentType = string.Format("multipart/form-data");
httpclient.Accept = "application/json";
httpclient.PreAuthenticate = true;

StringBuilder sb= new StringBuilder();
sb.AppendLine(boundary);
sb.AppendLine("content-disposition: form-data; name=\"file_name\"");
sb.AppendLine();
sb.AppendLine("Constant.csv"); // filename
sb.AppendLine(boundary);
sb.AppendLine("content-disposition: form-data; name=\"lists\"");
sb.AppendLine();
sb.AppendLine("1"); // Constant Contact List ID Number
sb.AppendLine(boundary);
sb.AppendLine("content-disposition: file; name=\"data\" filename=\"emailkust.csv\"");
sb.AppendLine("Content-Type: text/csv");
sb.AppendLine();
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
    byte[] contents = new byte[fs.Length];
    fs.Read(contents, 0, contents.Length);
    sb.Append(Encoding.Default.GetString(contents));
}
sb.AppendLine(boundary + "--");
byte[] fulldata = Encoding.Default.GetBytes(sb.ToString());

using (Stream sw = httpclient.GetRequestStream()) {
    sw.Write(fulldata, 0, fulldata.Length);
}
try {
    HttpWebResponse response = httpclient.GetResponse() as HttpWebResponse;
    using (StreamReader sr = new StreamReader(response.GetResponseStream())) {
        // add code here to display the contents from sr.ReadToEnd() to see the response from ther server
    }
} catch (WebException ex) {
        using (StreamReader sr = new StreamReader(ex.Response.GetResponseStream())) {
            // add code here to display the contents from sr.ReadToEnd() to see the response from ther server
            // add code here to display e.Message to see a shorter error message
        }
}

 

If you are still having problems, please post the detailed error message here so that I can assist you.

 

Best Regards,

Elijah G.
API Support Engineer
NeoMed
Rookie
0 Votes

I am having this problem as well.  Any help would be greatly appreciated.

NeoMed
Rookie
0 Votes

<span id="j_id0:errors"><span id="j_id0:errors:j_id3:j_id4:0:j_id5">
<div class="message warningM3" role="alert">
<table border="0" cellpadding="0" cellspacing="0" class="messageTable" style="padding:0px;margin:0px;">
<tbody><tr valign="top">
<td>
<img alt="WARNING" class="msgIcon" src="/s.gif" title="WARNING">
</td>
<td class="messageCell"><div id="j_id0:errors:j_id3:j_id4:0:j_id5:j_id6:j_id8" class="messageText"><span id="j_id0:errors:j_id3:j_id4:0:j_id5:j_id6:j_id9">
<h4>Warning:</h4></span>Upload failed. See "Comment" column in the table below.<br></div>
</td>
</tr>
<tr>
<td></td>
<td>
</td>
</tr>
</tbody></table>
</div></span></span>

KaraG30
Rookie
0 Votes

I have same problem, what's going wrong? We need Fix it as soon as possible. 

Resources
Developer Portal

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

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up