Edit

Share via


How to: Create a basic asset management API with Azure Functions (preview)

This article walks you through creating a basic mock API for an asset management application using Azure Functions. The API exposes a single operation to return a list of assets. You'll also learn how to create a custom connector in Power Platform using API Management.

Note

Preview features aren’t meant for production use and may have restricted functionality. These features are available before an official release so that customers can get early access and provide feedback.

This basic API provides a mock asset list and is ready for integration with Power Platform using a custom connector via API Management.

Prerequisites

Create a new Azure Function in the Azure portal

  1. Go to the Azure portal.

  2. Select Create a resource > Web > Function App.

  3. Select Consumption.

  4. Fill in the required details:

    Detail Description
    Subscription Select your subscription
    Resource Group Create a new one or use an existing one
    Function App name Choose a unique name
    Runtime stack Node.js
    Region Choose a region close to you
  5. Select Review + create and then Create.

    Create Function in Azure

  6. Once deployment is complete, go to your new Function App.

  7. Select Create function.

  8. If asked, select: Development environment: Develop in portal.

  9. Select HTTP trigger as the template, give it the name GetAssets, and set Authorization level to Anonymous because no authentication is required in this basic example.

    Create HTTP trigger

  10. Select Create to create the function.

  11. In the Code + Test tab, replace the function code with the mock API code from the next section.

  12. Select Save.

Implement the mock API

Edit GetAssets/index.js to return a mock list of assets:

module.exports = async function (context, req) {
    context.res = {
        // status: 200, /* Defaults to 200 */
        body: [
            { id: 1, name: "Laptop", type: "Electronics", status: "Available" },
            { id: 2, name: "Projector", type: "Electronics", status: "In Use" },
            { id: 3, name: "Desk", type: "Furniture", status: "Available" },
            { id: 4, name: "Office Chair", type: "Furniture", status: "In Use" },
            { id: 5, name: "Monitor", type: "Electronics", status: "Available" },
            { id: 6, name: "Whiteboard", type: "Office Supply", status: "Available" },
            { id: 7, name: "Phone", type: "Electronics", status: "In Use" },
            { id: 8, name: "Tablet", type: "Electronics", status: "Available" },
            { id: 9, name: "Printer", type: "Electronics", status: "Maintenance" },
            { id: 10, name: "Filing Cabinet", type: "Furniture", status: "Available" }
        ]
    };
};

Expose your function app via API management

  1. In the Azure portal, search for and select API Management services.

  2. Select + Create to create a new API Management instance. The Developer tier is free for development/testing.

  3. Fill in the required details and deploy the instance.

  4. Once deployed, open your API Management instance.

  5. In the left menu, select APIs > + Add API > Function App.

    Add API

  6. Select your Function App and the GetAssets function.

    Import API

  7. Complete the wizard to import your function as an API operation.

  8. After import, go to your API in API Management.

  9. In the top menu, select Settings for your API.

  10. Under Security, set Subscription required to Off. This removes the need for a subscription key (API key) when calling the API.

    Update security settings

  11. Save your changes.

Create a custom connector in Power Platform using API Management (from Azure portal)

  1. In API Management Services In the left menu within APIs, select Power Platform.

  2. Select Create a connector.

  3. Select Your API:

    Create custom connector

  4. Select your environment and display name and then select Create. The custom connector is created in your selected environment.

  5. In Power Apps, go to Custom connectors to review, edit, and test your new connector.

    Test custom connector

Next steps

  • Create a new code app using this custom connector with Power Apps SDK
  • Expand the API with more operations as needed. Don't forget to update the connector with the new operations when you do.
  • Secure your API if you move beyond development/testing.