This tutorial demonstrates how to register a Swagger file describing an Azure Resource Manager (ARM) API and then connect to it in PowerApps.

Prerequisites

Enable authentication in Azure Active Directory

First, we need to create an Azure Active Directory (AAD) application that will perform the authentication when calling the ARM API endpoint.

  1. Sign in to the Azure portal. If you have more than one Azure Active Directory tenant, make sure you're logged into the correct directory by looking at your username in the upper-right corner.

    User Name

  2. On the left-hand menu, click More services. In the Filter textbox, type Azure Active Directory, and then click Azure Active Directory.

    Azure Active Directory

    The Azure Active Directory blade opens.

  3. In the menu on the Azure Active Directory blade, click App registrations.

    App registrations

  4. In the list of registered applications, click Add.

    Add button

  5. Type a name for your application, leave Web app / API selected, and then for Sign-on URL type https://login.windows.net. Click Create.

    New app form

  6. Click the new application in the list.

    New app in list

    The Registered app blade opens. Make a note of the Application ID. We'll need it later.

  7. The Settings blade should have opened, as well. If it didn't, click the Settings button.

    Settings button

  8. In the Settings blade, click Reply URLs. In the list of URLs, add https://msmanaged-na.consent.azure-apim.net/redirect and click Save.

    Reply URLs

  9. Back on the Settings blade, click Required permissions. On the Required permissions blade, click Add.

    Required permissions

    The Add API access blade opens.

  10. Click Select an API. In the blade that opens, click the option for the Azure Service Management API and click Select.

    Select an API

  11. Click Select permissions. Under Delegated permissions, click Access Azure Service Management as organization users, and then click Select.

    Delegated permissions

  12. On the Add API access blade, click Done.

  13. Back on the Settings blade, click Keys. In the Keys blade, type a description for your key, select an expiration period, and then click Save. Your new key will be displayed. Make note of the key value, as we will need that later, too. You may now close the Azure portal.

    Create a key

Add the connection in PowerApps

Now that the AAD application is configured, let's add the custom API.

  1. In powerapps.com, in the menu on the left, click Connections. Then click New connection in the upper-right corner.

    Sugerencia:

    If you can't find the menu, it may be under a hamburger button in the upper-left corner in mobile browsers.

  2. Click Custom to display your list of custom connections, and then click New custom API.

    New custom API

  3. Type a Name for your connection, and then upload the sample ARM Swagger file. Click Next.

    Connect to a new API endpoint

  4. On the next screen, because the Swagger file uses our AAD application for authentication, we need to give PowerApps some information about our application. Under Client id, type the AAD Application ID you noted earlier. For client secret, use the key. And finally, for Resource URL, type https://management.core.windows.net/.

    Importante:

    Be sure to include the Resource URL exactly as written above, including the trailing slash.

    OAuth settings

  5. Your custom API is now registered and can be consumed within PowerApps or Microsoft Flow.

    Custom API added

Nota:

The sample Swagger does not define the full set of ARM operations and currently only contains the List all subscriptions operation. You can edit this Swagger or create another Swagger file using the online Swagger editor.

This process can be used to access any RESTful API authenticated using AAD.

Next steps

For more detailed information about how to create an app, see Create an app from data.

For more detailed information about how to use a flow in an app, see Start a flow in an app.

To ask questions or make comments about custom APIs, join our community.