KBEC-00347 - Using PowerShell to call REST API of ElectricFlow

Summary:

This article discusses how to use PowerShell to call REST API of ElectricFlow.

Solution:

Either Invoke-WebRequest or Invoke-RestMethod could be used to interact with the RESTful API of ElectricFlow. When a trusted certificate is not available using https, the following error may occur.

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

In this case, below lines need to be added into the code before calling Invoke-WebRequest or Invoke-RestMethod.

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
 

An example PowerShell script is attached to this article for reference.

See also:

Applies to:

  • Production version: 5.2+
  • OS: Windows
  • PowerShell version: 3.0+
Have more questions? Submit a request

Comments

Powered by Zendesk