Delete a chatbot by api

When I was recently writing a command for the CLI for Microsoft 365, I was interested in writing one that could delete a chatbot. Chatbots, also known as Power Virtual Agents, are part of Dynamics 365 Customer Service. It is therefore not surprising that the underlying APIs are dynamics 365 based.

It seemed pretty straightforward, call the right api with the delete method and you’re done.


Well not really.. When you run the above api, you bump into a “400 bad request” error, stating “The bot can not be deleted since it has dependent bot components. Remove the following dependencies before attempting to delete the bot…”.

A pretty clear description! A bot exist of several bot components and they are all linked to the bot itself. So the bot cannot be removed as long as the linked bot components still exist.

You could remove the components one by one, but you know what they say about developers… We like to keep things simple! Another api to retrieve all bot components, put this result in a loop where they are removed one by one and then finally remove the bot itself seemed a bit overkill to me. In addition, it would generate too many api executions for my liking.

For the record, deleting an individual botcomponent can be obtained by calling following api with the delete method:


But luckily there is a single api that does all this work for us on serverside and we only have to call one api. However, this api is not callable by the delete method, but must be executed according to the post method.


Blog at

%d bloggers like this: