APIs & Integrations

JHonney
Member

Getting error "The request was aborted: Could not create SSL/TLS secure channel"

SOLVE

Hello,

 

Starting 10-Mar-2021 we started getting the exception"The request was aborted: Could not create SSL/TLS secure channel" when calling ExecuteRestPost(). 

string url = "https://api.hubapi.com/contacts/v1/contact/batch/?hapikey=" + ConfigurationManager.AppSettings["hubSpotApiKey"];
                        bool resubmit;
                        do
                        {
                            resubmit = false;
                            HttpResponseMessage response = Utils.ExecuteRestPost(client, url, contacts, false);
                            if (response.IsSuccessStatusCode)
                            {
                                recordsSucceeded += contacts.Count;
                            }
                            else // Failure.
                            {
                                // For invalid email failures, place any invalid contacts on a list and resubmit the remaining contacts. For any other failures,
                                // throw an exception and move onto the next batch. Note none of the records in a failed batch are committed to HubSpot, even if they are valid.

                                JToken invalidEmailsToken = JObject.Parse(response.Content.ReadAsStringAsync().Result)["invalidEmails"];
                                if (resubmit == false && invalidEmailsToken != null) // Note we never resubmit more than once. If a resubmit fails for any reason, throw an exception.
                                {
                                    List<string> invalidEmailsList = new List<string>();
                                    foreach (string invalidEmail in invalidEmailsToken)
                                    {
                                        invalidEmailsList.Add(invalidEmail);
                                        Utils.AppendToLog(sbLog, "Invalid email " + invalidEmail);
                                    }
                                    List<Contact1G> validContacts = new List<Contact1G>();
                                    foreach (Contact1G contact in contacts)
                                    {
                                        if (invalidEmailsList.Contains(contact.email))
                                        {
                                            invalidContacts.Add(contact);
                                        }
                                        else
                                        {
                                            validContacts.Add(contact);
                                        }
                                    }
                                    contacts = validContacts;
                                    if (contacts.Count > 0)
                                    {
                                        resubmit = true;
                                        Utils.AppendToLog(sbLog, "Resubmit batch " + batch + " with " + contacts.Count + " valid record(s)");
                                    }
                                    else
                                    {
                                        Utils.AppendToLog(sbLog, "No valid contacts exist in this batch; no resubmit attempted");
                                    }
                                }
                                else
                                {
                                    throw new Exception(Utils.FormatJson(response.Content.ReadAsStringAsync().Result));
                                }
                            }
                        }
                        while (resubmit == true);
                    }
                    catch (Exception ex)
                    {
                        Utils.AppendLogErrorHeader(sbLog, ex);
                        masterException = ex;
                    }
                }

 

We end up in the catch with the exception stated above. Nothing has changed on our end so I'm hoping you can help us figure out what's going on here.

Please let me know if there is any other relevant information I can provide.

 

Thank you 

0 Upvotes
1 Accepted solution
dennisedson
Solution
HubSpot Product Team
HubSpot Product Team

Getting error "The request was aborted: Could not create SSL/TLS secure channel"

SOLVE

Hi @JHonney , I wonder if this is related.  What version of TLS are you using?

View solution in original post

3 Replies 3
creigmalta
Member

Getting error "The request was aborted: Could not create SSL/TLS secure channel"

SOLVE

The error is generic and there are many reasons why the SSL/TLS negotiation may fail. ServicePointManager.SecurityProtocol property selects the version of the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocol to use for new connections; existing c#  connections aren't changed. Make sure the ServicePointManager settings are made before the HttpWebRequest is created, else it will not work. Also, you have to enable other security protocol versions to resolve this issue:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
SecurityProtocolType.Tls
SecurityProtocolType.Tls11
SecurityProtocolType.Ssl3;

//createing HttpWebRequest after ServicePointManager settings
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://google.com/api/")

 

If you create HttpWebRequest before the ServicePointManager settings it will fail and shows the error message.

 

0 Upvotes
JHonney
Member

Getting error "The request was aborted: Could not create SSL/TLS secure channel"

SOLVE

Hello Dennis,

This seems to be the issue we were running into. Thank you for your support.

dennisedson
Solution
HubSpot Product Team
HubSpot Product Team

Getting error "The request was aborted: Could not create SSL/TLS secure channel"

SOLVE

Hi @JHonney , I wonder if this is related.  What version of TLS are you using?