Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Unanswered

Power Platform Build Tools: Connection reference

(1) ShareShare
ReportReport
Posted on by 16

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?

  • Community Power Platform Member Profile Picture
    on at
    Re: Power Platform Build Tools: Connection reference

    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.

  • _raphael Profile Picture
    6 on at
    Re: Power Platform Build Tools: Connection reference

    @ryanspain 

    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.

     

  • ryanspain Profile Picture
    100 on at
    Re: Power Platform Build Tools: Connection reference

    @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.

  • ScottCostello Profile Picture
    23 on at
    Re: Power Platform Build Tools: Connection reference

    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)"
     }
    }
  • ryanspain Profile Picture
    100 on at
    Re: Power Platform Build Tools: Connection reference

    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:

    ryanspain_0-1630603712401.png

     

     

  • ScottCostello Profile Picture
    23 on at
    Re: Power Platform Build Tools: Connection reference

    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

     

  • ryanspain Profile Picture
    100 on at
    Re: Power Platform Build Tools: Connection reference

    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.

     

    For example, using curly braces in the workflow identifier as below would result in a 400 bad request response.

     

    .../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.

     

  • ScottCostello Profile Picture
    23 on at
    Re: Power Platform Build Tools: Connection reference

    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? 

  • ryanspain Profile Picture
    100 on at
    Re: Power Platform Build Tools: Connection reference

    @ScottCostello/@stone_haha,

     

    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:

    • The CallerObjectId header should be the object ID of the AAD user you want to impersonate - Impersonate another user
    • You need to pass in a Bearer token in the Authorization header - See Use OAuth authentication with Microsoft Dataverse
    • statecode and statuscode of 1 and 2 respectively represent an Activated workflow - See Workflow table/entity reference
    • You need to update the Uri parameter of Invoke-WebRequest to use your environments name, region, and the workflow ID.
    • Most of the parameters used in this PowerShell script could be setup as variables in the pipeline using the PowerShell script task.
    • This example only activates a single flow but the same process would apply to activating multiple whereby you could loop over a list of cloud flows and attempt to activate them. A retry pattern could be used.  
  • ScottCostello Profile Picture
    23 on at
    Re: Power Platform Build Tools: Connection reference

    Hi Scott,

     

    I would like to see the script as well.  Would save a TON of time.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 85 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 57 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 55 Super User 2025 Season 1

Overall leaderboard