web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Create Connections pro...
Power Apps
Answered

Create Connections programmatically

(0) ShareShare
ReportReport
Posted on by 39

Hi!

 

My question

I cannot find any way to programmatically create a Connection.

Any ideas on how to accomplish this, even if complicated, is of interest to me.

 

The background

In my automatic test pipeline setup I currently copy a template environment to a test environment to be able to test solution import followed by the execution of automatic tests. When I copy an environment the target environment does not lose its already existing Connections, but when I execute an environment reset instead, all existing Connections are lost. I would prefer that my pipeline would use a reset operation instead of a copy operation, but that requires me to create a Dataverse Connection programmatically after the reset, in order to connect it to the Connection Reference included in the solution package being imported. Otherwise the cloud flows in the solution cannot be verified by the automatic tests.

 

Best regards,

Henrik Svensson

I have the same question (0)
  • ivan_apps Profile Picture
    2,187 Moderator on at

    Perhaps you can trigger the opening of the app to create the connections?

    Then you can set the environment to bypass the API consent for your test - 

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powerapps.administration.powershell/set-adminpowerappapistobypassconsent?view=pa-ps-latest

     

    In theory I would imagine that should auto-create all the connections your app needs.

  • Verified answer
    ivan_apps Profile Picture
    2,187 Moderator on at

    Alternatively, this may work -

    ivan_25_0-1700481067535.png

     

  • hsvensson Profile Picture
    39 on at

    Thank you for the suggestions, @ivan_apps. I'll look into this and report back with the results.

     

    Best regards,

    Henrik Svensson

  • hsvensson Profile Picture
    39 on at

    I made it work!

     

    I am using the Power Automate Management action "Create Connection" (placed in another environment) to create a Microsoft Dataverse Connection after my test environment has been reset. That in itself is not enough to make my app user able to assign that Connection to a Connection Reference (it results in an error). I have to programmatically share the Connection to the App User first (even though both the Connection and the App User use the same service principal).

     

    Sharing a Connection programmatically is possible using the Edit Connection Role Assignment operation of the Power Apps for Makers Connector. Thus, these are the steps that did the trick:

     

    hsvensson_0-1700856526371.png

    Worth mentioning is that the resulting "Connection Name" from the "Create Connection" action is the Connection Id. And the Connector Name (to be set on the Edit Connection Role Assignment action) is not "Microsoft Dataverse", but corresponds to what is displayed as part of the URL when you open the details view of your connection.

    Another thing to be aware of is that the "properties/principal/id" value is the Object Id of your service principal (not the Application Id), i.e., this property, on the properties page of your service principal enterprise application in the Azure portal:

     

    hsvensson_1-1700856946413.png

    Thanks for pointing me in the right direction!

     

    Hopefully the information above can save someone else some time, because this took me several hours to figure out.

  • JT-31070644-0 Profile Picture
    2 on at
    Hi Henrik Svensson,

    I have followed the below instructions as mentioned in your post.
     

    I am using the Power Automate Management action "Create Connection" (placed in another environment) to create a Microsoft Dataverse Connection after my test environment has been reset. That in itself is not enough to make my app user able to assign that Connection to a Connection Reference (it results in an error). I have to programmatically share the Connection to the App User first (even though both the Connection and the App User use the same service principal).

    Sharing a Connection programmatically is possible using the Edit Connection Role Assignment operation of the Power Apps for Makers Connector. Thus, these are the steps that did the trick:

    hsvensson_0-1700856526371.png

    Worth mentioning is that the resulting "Connection Name" from the "Create Connection" action is the Connection Id. And the Connector Name (to be set on the Edit Connection Role Assignment action) is not "Microsoft Dataverse", but corresponds to what is displayed as part of the URL when you open the details view of your connection.

    Another thing to be aware of is that the "properties/principal/id" value is the Object Id of your service principal (not the Application Id), i.e., this property, on the properties page of your service principal enterprise application in the Azure portal:

     

    hsvensson_1-1700856946413.png

    Seems to be image URL in the post is broken. Hence, I'm not understanding how to provide the "Connection Name" and "Connector Name" on the Edit Connection Role Assignment action.

    Please find attached image for your reference.

    When I try to run below action I'm facing an error as below.

    {
      "error": {
        "code""InvalidPrincipalInModifyPermissions",
        "message""The permission with id '/providers/Microsoft.PowerApps/apis//connections//permissions/' in the put collection requires either the id or the email for the principal."
      }
    }




    Kindly help me out to Share a Connection programmatically.

    Thanks,
    Jeeva

  • Suggested answer
    AK-01051611-0 Profile Picture
    4 on at
    I spent days trying to figure it out and after long hours spent, I opened MS ticket trying to get it resolved but no answer from them.
     
    Then I just looked at the difference in API version and then I tried with the latest version and it worked like a charm
     
    By default when you add the Edit Connection Role Assignment, it puts the API version 2016-11-01 and according to Microsoft Documentation here Use a connection reference in a solution with Microsoft Dataverse - Power Apps | Microsoft Learn the version number must be 2020-06-01. When you change the version, the problem is resolved.
     
    -Ashar

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard