Kaseya Community

Issues Deleting Agents Through REST API

This question is not answered

Hey Guys,

So I've been working on some scripting solutions to delete agents Programmatically to save us time.  I have no problems with any GET calls but I am getting a 403 Forbidden when trying to delete Agents.  The account does have the ability to delete these agents manually in the Console, but that takes too long.

Is there a configuration or another permission that is needed for this?  We are currently using Agent Version 9.5 for our machines.

Thank You

All Replies
  • This should definitely work. Our Ticket Processing Service gets a list of agents that haven't checked in during the past ## days and issues commands to remove the agents, up to a maximum number of agents each day. It's been keeping the agent count reasonable for months. We have another app that VSA initiates - it schedules itself to run and then exits, telling VSA it's complete. It runs via scheduler a minute later, performs an agent uninstall, and then tells VSA to delete the agent before optionally downloading a new agent from a different VSA and installing it. This is used for both offboarding and VSA-VSA agent migrations.

    One thing we don't use (as it never seems to work) is the option to uninstall the agent. Just a straight agent delete has always worked.

    Another thing - 403 is a common response when the syntax isn't 100% correct, so look closely at your URI.

    Glenn

  • I've checked the URI based on Kaseya's docuementation and everything is correct from what I can see

    $AgentURI = "HTTPS://<>/api/v1.0/assetmgmt/agents/<AgentID>/false"

    Invoke-RestMethod -Headers @{'Authorization'="Bearer $SessionToken"} -Method Delete -Uri $AgentURI -ContentType application/json

    The AgentID Is retrieved from a list that is stored in a csv file.  I'm able to use GET this way without any issues at all but Delete is not working.

    This is being done using PowerShell.

  • I believe I have figured it out...

    My Csv file was saving the items in Exponential Notation... not the actual numbers...  This is now working.