Skip to main content

Notifications

Community site session details
Power Apps - Microsoft Dataverse
Answered

Create Connections programmatically

Like (0) ShareShare
ReportReport
Posted on 20 Nov 2023 11:05:55 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

Categories:
  • Suggested answer
    AK-01051611-0 Profile Picture
    4 on 01 May 2025 at 16:32:31
    Create Connections programmatically
    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
  • JT-31070644-0 Profile Picture
    2 on 31 Jul 2024 at 07:32:37
    Create Connections programmatically
    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

  • hsvensson Profile Picture
    39 on 24 Nov 2023 at 20:23:26
    Re: Create Connections programmatically

    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.

  • hsvensson Profile Picture
    39 on 20 Nov 2023 at 12:30:12
    Re: Create Connections programmatically

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

     

    Best regards,

    Henrik Svensson

  • Verified answer
    ivan_apps Profile Picture
    2,187 Super User 2025 Season 1 on 20 Nov 2023 at 11:51:20
    Re: Create Connections programmatically

    Alternatively, this may work -

    ivan_25_0-1700481067535.png

     

  • ivan_apps Profile Picture
    2,187 Super User 2025 Season 1 on 20 Nov 2023 at 11:45:08
    Re: Create Connections programmatically

    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.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

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 - Microsoft Dataverse

#1
stampcoin Profile Picture

stampcoin 15

#2
ankit_singhal Profile Picture

ankit_singhal 11 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 9 Super User 2025 Season 1

Overall leaderboard

Featured topics