Hi!
So we successfully implemented ALM with some Azure DevOps Pipelines and the official Power Platform Build Tools. But there's one problem:
When importing a solution which contains a Flow and its connection reference, it doesn't update itself correctly and just turns itself off.
It is as if I would import the solution with the old solution explorer UI. The new PowerApps solution UI asks when importing to update the connection references. But the old UI and the Power Platform Build Tools in Azure DevOps just disable the Flow.
So after having everything automated, we still have to go into the prod environment and update each connection reference and activate each Flow (even if it didn't change). I guess the process is worse now than without ALM.
Are there any workarounds or possibilities to use the "new UI" import API? Or am I missing something? How should this be handled with ALM?
Hi Scott, I don’t know why it’s still using the service principal rather than impersonation as it complained the service principal cannot turn on the flow either because the shared connection is not a valid one or because it is not a connection you have access permission.
how can I get the correct authority URL?
$authContextUrl="https://login.microsoftonline.com/$tenantId"
gives me the following error:
New-Object : Cannot find type [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]: verify that the
assembly containing this type is loaded.
thanks for your help.
@ScottCostello, unfortunately that error message doesn't provide us with much other than there is a problem with the inputs.
Could you try changing the body statement in PowerShell to match the below? This is a long shot!
$body = "{
`n `"statecode`": 1,
`n `"statuscode`": 2
`n}"
Also, what version of PowerShell is this executing on? i.e. run Get-Host | Select-Object Version.
This is the error message I get @ryanspain
{
"error":{
"code":"0x0",
"message":"An error occurred while validating input parameters: System.ArgumentException: Stream was not readable.\r\n at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean leaveOpen)\r\n at System.IO.StreamReader..ctor(Stream stream, Encoding encoding)\r\n at Microsoft.OData.JsonLight.ODataJsonLightInputContext.CreateTextReader(Stream messageStream, Encoding encoding)\r\n at Microsoft.OData.JsonLight.ODataJsonLightInputContext..ctor(ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings)\r\n at Microsoft.OData.Json.ODataJsonFormat.CreateInputContext(ODataMessageInfo messageInfo, ODataMessageReaderSettings messageReaderSettings)\r\n at Microsoft.OData.ODataMessageReader.ReadFromInput[T](Func`2 readFunc, ODataPayloadKind[] payloadKinds)\r\n at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)"
}
}
I've tried your code and it works for me @ScottCostello.
I even tried activating a cloud flow within a managed solution but that worked as expected too.
Could you try adding the below to your catch statement to try and extract the error message?
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd()
"Response Body: $($responseBody)"
The response should be something like the below:
Hi @ryanspain ,
I just don't see what could be wrong compared to the example you gave above. One issue I thought about is perhaps because I'm trying to modify a Managed Solution.
$tenantId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
$appId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"
$appSecret = "xxxxxxxxx.xxxxxxx.xxx.xxxxxxxxxx"
$serviceUrl = "https://xxxxxxxxxx.crmX.dynamics.com/"
<# Get Access Token #>
$authContextUrl = "https://login.microsoftonline.com/$tenantId"
$authContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext($authContextUrl)
$credential = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential($appId, $appSecret)
$authResult = $authContext.AcquireToken($serviceUrl, $credential)
<# Set Headers #>
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("CallerObjectId", "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx")
$headers.Add("Authorization", "Bearer " + $authResult.AccessToken )
$headers.Add("Content-Type", "application/json")
<# Set Body #>
$body = "{ 'statecode': 1, 'statuscode': 2 }"
<# Run Request #>
try {
$response = Invoke-WebRequest -Uri 'https://xxxxxxxxxx.crmX.dynamics.com/api/data/v9.2/workflows(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX)' -Method 'PATCH' -Headers $headers -Body $body
exit 0
}catch{
"Status Code: $($_.Exception.Response.StatusCode.value__)"
"Exception Message: $($_.Exception.Message)"
exit 1
}
$response.StatusCode
$response.StatusDescription
Hi @ScottCostello,
You would receive a 401 unauthorised if it was a privilege issue. A response code of 400 indicates a bad request which could mean a problem with the input arguements.
.../api/data/v9.2/workflows({bc9d6d8f-XXXX-XXXX-XXXX-000d3ab8a215})
If everything looks ok on your end, try pasting your snippets (with sensitive info omitted) here and I'd be happy to cast an eye over.
Finally, I'm no export on PowerShell but I generated most of my supplied sample using a neat feature of Postman that lets me turn a HTTP request into a PowerShell script.
Thanks Ryanspain!
I've got almost all of it working accept that the Invoke-WebRequest I get an error returned saying (400) Bad Request. Unfortunately I don't see any other information.
I believe I've authenticated correctly, but something is off.
I think I have the correct WorkflowId, I got it from the WorkFlow edit Url.
Could this be an issue with privileges?
You can activate/switch on cloud flows from an Azure DevOps pipeline using PowerShell while impersonating another user. i.e. the owner of the cloud flows for example. See below, a sample script for doing this.
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("CallerObjectId", "c85463fb-XXXX-XXXX-XXXX-3c73fc279d03")
$headers.Add("Authorization", "Bearer eyJ0eXAi...")
$headers.Add("Content-Type", "application/json")
$body = "{ 'statecode': 1, 'statuscode': 2 }"
$response = Invoke-WebRequest -Uri 'https://XXXXXXXX.crmX.dynamics.com/api/data/v9.2/workflows(bc9d6d8f-XXXX-XXXX-XXXX-000d3ab8a215)' -Method 'PATCH' -Headers $headers -Body $body
$response.StatusCode
$response.StatusDescription
Some notes on the above:
Hi Scott,
I would like to see the script as well. Would save a TON of time.
WarrenBelz
85
Most Valuable Professional
Michael E. Gernaey
57
Super User 2025 Season 1
mmbr1606
55
Super User 2025 Season 1