Kaseya Community

Powershell access to REST API (get agents)

  • We have just upgraded from 9.2 to 9.4 and I am anxious to start using the REST API. Using the discussion elsewhere, I have successfully retrieved the following:

    TenantId : 1
    Token : <number>
    UserName : <userName>
    RoleId : 2
    ScopeId : 2
    AdminId : 975203
    MachineId :
    MachineGroupName :
    CultureInfo : en-US
    TimePref : Browser
    OffSetInMinutes : 0
    Attributes :

    Now I want to connect to the /assetmgmt/agents node. When I read something, in one of the 9.3 posts, that made me think that I needed the token number from the first response, but I cannot get any agents back.

    What would the Powershell code look like?

    Thanks.

  • It should be something like this:

    $Base_Uri = 'https://kaseya.domain.com/api/v1.0';
    Invoke-RestMethod -Method Get -Uri $($Base_Uri + "/assetmgmt/agents") -Headers @{'Authorization' = "Bearer $tokenId"}

    Nate

  • That looks a lot like what I was trying. I must have had a typo. 

    How would one return more than 100 items? I assume I should be able to specify the result size, but Invoke-RestMethod -Method Get -Uri $($Base_Uri + "/assetmgmt/agents?size=200") -Headers @{'Authorization' = "Bearer $tokenId"} still only returns 100.

    Is that answer documented somewhere? I can't seem to find it.

    Thanks.

  • I believe the 100 is the maximum allowed by the API. You may need to make multiple requests for separate groups of agents by adding a filter query to the URI, i.e. by something common in the computers name. That is how I got around it. Once you've pulled all the groups into PowerShell you can work on them together.

  • If I can't change the size, maybe there is an offset filter. I'll give it a try.

  • Found it. They have $skip and $top filters.

    help.kaseya.com/.../9040000