cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
ygross
Level 7
Report Inappropriate Content
Message 1 of 3

mcafee nsp api

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]:Smiley TonguetrToStringAuto($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]:Smiley FrustratederverCertificateValidationCallback = {$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]:Smiley FrustratederverCertificateValidationCallback = {$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

2 Replies
d_aloy
Level 12
Report Inappropriate Content
Message 2 of 3

Re: mcafee nsp api

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

Re: mcafee nsp api

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)