With the latest update from the LCS Database Movement API we’re finally able to start and stop the cloud hosted environments from a specific LCS project. Even with the correct environment status synced to LCS!
Thanks to the awesome d365fo.tools from @splaxi it’s easy to get this running in an Azure pipeline or trigger the action locally from power shell.
I wanted this action triggered by Power Automate. This sample uses a manual trigger but it could also be setup to be triggered by an automated action or as a scheduled flow. The whole flow consists of only four steps which are quickly created.

Basically we’re just triggering the flow, requesting the authentication, parsing the response of the authentication request and then we trigger the action on the environment.
I attached a sample flow on GitHub at the end of the post. You can just import it into your Power Automate and modify it for your needs.

Create an application in the Azure portal

First step is to register an application in the Azure AD. Maybe you already have one hanging around for the release pipeline, as it needs the same permissions.
You can check the official documentation on how to set it up: Database movement API – Authentication – Finance & Operations | Dynamics 365 | Microsoft Docs
Write down the client secret and the application id of the application.

Create the Power Automate flow

Next log in to Power Automate and create a new instant flow.
In the manual trigger action we add a drop-down list with the Start / Stop options.

This way we can choose which action we want to perform for the environment.

Add a new action and select the HTTP type. Here you need to fill in the following values:

Replace the ‘client_id’ and ‘client_secret’ from your AAD application and the ‘username’ and ‘password’ of a user that is present in the LCS project. Keep in mind, that the user can not have MFA activated. In my case I could use the same user as we were using for the release pipeline.

Second step is to parse the response JSON to get the authentication token.

To get the schema I took the response of a Postman request an generated the schema using the ‘Generate from sample’ button. In the attached sample you already have the schema included. So nothing more to do here.

Now we already have set everything up, to trigger the action on our environment.

The URI needs the action to perform, the project id and the environment id you want to start or stop. The project and environment id you can look up in the LCS project.
We use the input value we specified in the manual trigger action.

After everything is setup we can save the flow and give it a try. Start the flow and you can choose which action you want to perform.

Select the action and run the flow. After it ran successfully you can see the status changing in LCS.

Feel free to download the sample flow here: Github
Just import the template into your flows and set the values according to your project.

Advertisement