following the api document NSP_8.3_Manager_API_Reference_Guide_revF_en-us
i am using the following power shell code to get session ID from my nps .
i able to get the uid and password from session api:
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
$this.WebClient.Credentials = New-Object System.Net.NetworkCredential -ArgumentList @($this.Username, $UnsecurePassword)
$user = $this.Username
$pass = $UnsecurePassword
$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$this.WebClient.Headers.Add('accept','application/vnd.nsm.v2.0+json')
$this.WebClient.Headers.add('Content-Type','application/json')
$this.WebClient.Headers.add('NSM-SDK-API',$base64)
$Session= $this.WebClient.DownloadString("https://$myServer/sdkapi/session")
# get the session uid and code correctly
$JsonSession = $Session | ConvertFrom-Json
$user=$JsonSession.userId
$pass= $JsonSession.session
$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$this.NSMSDKAPI = $base64
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$this.WebClient.Headers.Add('accept','application/vnd.nsm.v2.0+json')
$this.WebClient.Headers.add('Content-Type','application/json')
$this.WebClient.Headers.add('NSM-SDK-API',$this.NSMSDKAPI)
$response = $this.WebClient.DownloadString("${url}?${query_string}")
i get the 401 unauthorized error
my user is defined as super user
Hi ygross
I'm not an API user but I would say that your code seems to have all the required Auth fields...Have you raised this with support? I would be interested in knowing the answer/fix to this please
Cheers
David
found the problem
when i run the second call to api i need to change the
$this.WebClient.Headers.add('NSM-SDK-API',$this.NSMSDKAPI)
to
$this.WebClient.Headers.Set('NSM-SDK-API',$this.NSMSDKAPI)
Corporate Headquarters
6220 America Center Drive
San Jose, CA 95002 USA