"Could not create SSL/TLS secure channel." error using Powershell to POST to the REST API via Orchestration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2020 01:36 PM
This isn't a question so much as an answer! I've been wrestling with trying to create an Orchestration activity to create a record in ServiceNow's REST API using Powershell. The Powershell script is easily built using the REST API Explorer, but when testing the script I kept getting the error "Invoke-RestMethod : The request was aborted: Could not create SSL/TLS secure channel." I figured I'd post the resolution here to hopefully spare someone the hours I spent googling the issue. I found an answer here, but it's simply a matter of adding one line to your script before making the REST call....
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
The issue is apparently caused by ServiceNow's enforcement for TLS 1.2 (details here ).
- Labels:
-
Integrations
- 4,465 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 05:56 AM
Thanks,
This saved me a few hours of searching.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2021 12:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2022 05:54 PM
Someone needs to buy this man a drink!! Thank you so much, good sir!!! Saved me with this!!!