Has anyone got the api to work successfully with powershell?

Answered

Comments

5 comments

  • Avatar
    Renato Dattilo

    You're close!

     

    I just started using the API myself and had the same issue.  

    Error 406 is client side, so I looked into it.  It needs an 'Accept' header that tells the server a valid response can only contain types of info.  As a shot in the dark, and just by looking at what the API returns (json) I decided to add in the MIME type for json: 

    $header = @{"Authorization" = "Bearer $apikey"; "Accept"="application/json"}

    Invoke-RestMethod -Uri https://us.api.knowbe4.com/v1/account/ -header $header

     

    1
    Comment actions Permalink
  • Avatar
    Lauren Ashley (Edited )

    Hi Renato! 

    Thanks for providing this solution!

    Andy, if this does not resolve the error, feel free to let us know, or email support@KnowBe4.com for assistance.

    Thanks! 

    Lauren
    KnowBe4

    0
    Comment actions Permalink
  • Avatar
    Andy Helsby

    Thank you Renato - this worked a treat!

    I also found a powershell module at https://www.powershellgallery.com/packages/KnowBe4/1.1.1 that also helped me to get information back from Knowbe4. It has three functions included, Get-KnowBe4Campaign Get-KnowBe4User Get-KnowBe4IncompleteTraining. Interestingly it uses curl.exe instead of the builtin invoke-restmethod commands.

     

    @Lauren - it would be useful to add the sample code to your documentation to help others in the future.

     

    $knowbe4apikey="insertyourapikeyhere"
    $hdrs=@{"Authorization"="Bearer $knowbe4apikey";"Accept"="application/json"}
    $uri="https://us.api.knowbe4.com/v1/groups"
    $response = Invoke-RestMethod -uri $uri -Headers $Hdrs
    $response


    id : 694443
    name : Clickers
    group_type : console_group
    adi_guid :
    member_count : 10
    status : active

    id : 710278
    name : Report Viewers
    group_type : console_group
    adi_guid :
    member_count : 1
    status : active

    id : 710090
    name : Tset
    group_type : console_group
    adi_guid :
    member_count : 1
    status : archived

    0
    Comment actions Permalink
  • Avatar
    Lauren Ashley

    Thanks, Andy! 

    I've added a note for our team to add this information to our Knowledgebase. 

    It appears that you've provided all of the information we could need, but would you be open to me, or someone else from our team reaching out for clarification, if necessary?

    As always, we appreciate your involvement in our product, and our community board, Andy.

    Thanks again!

    Lauren
    KnowBe4

    0
    Comment actions Permalink
  • Avatar
    Andy Helsby

    Sure that will work - you also need the following line first

    [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11,tls,ssl3"

     

    0
    Comment actions Permalink

Please sign in to leave a comment.