cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
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]::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

2 Replies
d_aloy
Reliable Contributor
Reliable Contributor
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

ygross75
Level 7
Report Inappropriate Content
Message 3 of 3

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)

You Deserve an Award
Don't forget, when your helpful posts earn a kudos or get accepted as a solution you can unlock perks and badges. Those aren't the only badges, either. How many can you collect? Click here to learn more.

Community Help Hub

    New to the forums or need help finding your way around the forums? There's a whole hub of community resources to help you.

  • Find Forum FAQs
  • Learn How to Earn Badges
  • Ask for Help
Go to Community Help

Join the Community

    Thousands of customers use the McAfee Community for peer-to-peer and expert product support. Enjoy these benefits with a free membership:

  • Get helpful solutions from McAfee experts.
  • Stay connected to product conversations that matter to you.
  • Participate in product groups led by McAfee employees.
Join the Community
Join the Community