ONTAP Rest API Discussions
ONTAP Rest API Discussions
Hello,
I am working on retrieve Dev NetApp Cluster information through ONTAP REST API with PowerShell.
But, when I initiate NetApp REST API though PowerShell in my laptop and got error like below.
PS C:\Users\TAC5665> $Cred = Get-Credential
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
PS C:\Users\TAC5665> $Params = @{
>> Uri = https://nasoc03.d2-tdbfg.com/api/network/ethernet/ports
>> Authentication = "Basic"
>> Credential = $Cred
>> }
PS C:\Users\TAC5665>
PS C:\Users\TAC5665> Invoke-RestMethod @Params
Invoke-RestMethod : A parameter cannot be found that matches parameter name 'Authentication'.
At line:1 char:19
+ Invoke-RestMethod @Params
+ ~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Current My laptop PowerShell version as 5.1
PS C:\Users\TAC5665> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.2364
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.2364
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Solved! See The Solution
You don't need Authentication - just Credential is sufficient (I believe they're actually mutually exclusive).
Example:
Invoke-RestMethod -Method Get -Uri 'https://{clusterip}/api/cluster' -Credential (Get-Credential)
Also, since you're using PSv5 and IF ONTAP is using a self-signed certificate you'll need to use the self-signed cert 'hack'.
If you don't already have this:
#Accept Self-Signed Certificates
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;
}
}
"@ -ea SilentlyContinue -wa SilentlyContinue
[System.Net.ServicePointManager]::CertificatePolicy = [TrustAllCertsPolicy]::new()
You don't need Authentication - just Credential is sufficient (I believe they're actually mutually exclusive).
Example:
Invoke-RestMethod -Method Get -Uri 'https://{clusterip}/api/cluster' -Credential (Get-Credential)
Also, since you're using PSv5 and IF ONTAP is using a self-signed certificate you'll need to use the self-signed cert 'hack'.
If you don't already have this:
#Accept Self-Signed Certificates
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;
}
}
"@ -ea SilentlyContinue -wa SilentlyContinue
[System.Net.ServicePointManager]::CertificatePolicy = [TrustAllCertsPolicy]::new()
Thanks a lot for advise. Di do not know detail about our Env using which certificate, but I tried above command from our PowerShell v.5.1 env and got error like below
PS C:\Users\TAC5665> Invoke-RestMethod -Uri "https://nasoc03.d2-tdbfg.com/api/cluster" -Credential (Get-Credential)
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Invoke-RestMethod : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
At line:1 char:1
+ Invoke-RestMethod -Uri "https://nasoc03.d2-tdbfg.com/api/cluster" -Cr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
What I research before The parameter authentication is only available within powershell 6.0+.
https://github.com/dnewsholme/GoogleDynamicDNS/issues/1
Is that true?
Plz advise on that.
Thanks a lot John. It worked for me your solution....