Use with a Logic Apps connector

Azure AI Video Indexer (VI) REST API supports both server-to-server and client-to-server communication. The API enables you to integrate video and audio insights into your application logic.

We support Logic Apps and Power Automate connectors that are compatible with the Azure AI Video Indexer API.

You can use the connectors to set up custom workflows to effectively index and extract insights from a large amount of video and audio files, without writing a single line of code. Using the connectors for the integration gives you visibility on the health of your workflow and a way to debug it.

Introduction

The example in this article creates Logic App flows. The Logic App and Power Automate capabilities and their editors are almost identical.

The two flow approach, two flows that work together, supports async upload and indexing of larger files effectively.

  • The first flow is triggered when a blob is added or modified in an Azure Storage account. It uploads the new file to Azure AI Video Indexer with a callback URL to send a notification once the indexing operation completes.
  • The second flow is triggered based on the callback URL and saves the extracted insights back to a JSON file in Azure Storage.

The logic apps you create in this article contain one flow per app. The second section, Create a new logic app of type consumption explains how to connect the two. The second flow stands alone and is triggered by the first one.

When a file is uploaded and indexed from the first flow, it sends an HTTP request with the correct callback URL to trigger the second flow. Then, it will retrieve the insights generated by Azure AI Video Indexer. In this example, it will store the output of your indexing job in your Azure Storage. However, it's up to you what you do with the output.

Prerequisites

  • If you don't have an Azure subscription, create an Azure free account before you begin.
  • Create an ARM-based Azure AI Video Indexer account.
  • Create an Azure Storage account. Storage accounts for VI must be a Standard general-purpose v2 storage account. Keep note of the access key for your Storage account.
    • Create two containers: one to store the media files, second to store the insights generated by Azure AI Video Indexer. In this article, the containers are videos and insights.

Generate an access token

  1. Generate an access token using the generateAccessToken. Press Try it to get the correct values for your account.
  2. Copy and paste it to Notepad for a later step.

Flow #1: Set up the file upload flow

This section describes how to set up the first, file upload, flow. The first flow is triggered when a blob is added or modified in an Azure Storage account. It uploads the new file to Azure AI Video Indexer with a callback URL to send a notification once the indexing operation completes.

The flow steps are:

  1. When a blob is added or modified (properties only) (V2)
  2. Create SAS URI by path (V2)
  3. HTTP
  4. Upload video and index

Create the When a blog is added or modified (properties only)(V2) step

  1. Create the Logic App in the same region as the Azure Video Indexer account region (recommended but not required).

  2. Call the logic app UploadIndexVideosApp.

    1. Select Consumption for Plan type.
    2. Press Review + Create -> Create.
    3. Once the Logic App deployment is complete, in the Azure portal, search and navigate to the newly created Logic App.
    4. Under the Settings section, on the left side's panel, select the Identity tab.
    5. Under System assigned, change the Status from Off to On (the step is important for later on in this tutorial).
    6. Press Save (on the top of the page).
    7. Select the Logic app designer tab, in the pane on the left.
    8. Pick a Blank Logic App flow.
    9. Search for "blob" in the Choose an Operation blade.
    10. In the All tab, choose the Azure Blob Storage component.
    11. Under Triggers, select the When a blob is added or modified (properties only) (V2) trigger.
  3. Create a When a blob is added or modified (properties only) (V2) trigger.

  4. Set the storage connection to these values:

    Key Value
    Connection name <Name your connection>.
    Authentication type Access Key
    Azure Storage Account name <Storage account name where media files are going to be stored>.
    Azure Storage Account Access Key To get access key of your storage account: in the Azure portal -> my-storage -> under Security + networking -> Access keys -> copy one of the keys.
    1. Select Create.
    2. Specify the blob storage container that is monitored for changes.
    Key Value
    Storage account name Storage account name where media files are stored
    Container /videos
    1. Select Save ->

Create SAS URI by path (V2)

  1. Select +New step

  2. Create SAS URI by path action.

    1. Select the Action tab.
    2. Search for and select Create SAS URI by path (V2).
    Key Value
    Storage account name <The storage account name where media files as stored>.
    Blob path Under Dynamic content, select List of Files Path
    Group Policy Identifier Leave the default value.
    Permissions Read
    Shared Access protocol (appears after pressing Add new parameter) HttpsOnly
    1. Select Save.
  3. Select +New Step.

Create an HTTP action

  1. Search for and create an HTTP action using the values in the following table:

    Key Value Notes
    Method POST
    URI [Access token](#generate-an-access token)
    Body { "permissionType": "Contributor", "scope": "Account" } See the REST doc example, make sure to delete the POST line.
    Add new parameter Authentication
    1. Fill the required parameters for authentication according to the following table:
    Key Value
    Authentication type Managed identity
    Managed identity System-assigned managed identity
    Audience https://management.core.windows.net
    1. Select Save.

Set up permissions

  1. Set up the permissions between the Logic app and the Azure AI Video Indexer account.

  2. Set up system assigned managed identity for permission on Azure AI Video Indexer resource. In the Azure portal, go to your Azure AI Video Indexer resource/account.

    1. On the left side blade, and select Access control.
    2. Select Add -> Add role assignment -> Contributor -> Next -> User, group, or service principal -> +Select members.
    3. Under Members, search for the Logic Apps name you created (in this case, UploadIndexVideosApp).
    4. Press Select.
    5. Press Review + assign.

Create an Upload video and index action

  1. Select Video Indexer(V2).

  2. From Video Indexer(V2), select Upload Video and index.

  3. Set the connection to the Video Indexer account with the parameters in the following table:

    Key Value
    Connection name <Enter a name for the connection>, in this case aviconnection.
    API key This is your personal API key, which is available under Profile in the developer portal Because this Logic App is for ARM accounts we do not need the actual API key and you can fill in a dummy value like 12345
    1. Select Create.

    2. Fill Upload video and index action parameters.

      Tip

      If the VI Account ID cannot be found and isn't in the drop-down, use the custom value.

      Key Value
      Location Location of the associated the Azure AI Video Indexer account.
      Account ID Account ID of the associated Azure AI Video Indexer account. You can find the Account ID in the Overview page of your account, in the Azure portal. Or, the Account settings tab, left of the Azure AI Video Indexer website.
      Access Token Use the body('HTTP')['accessToken'] expression to extract the access token in the right format from the previous HTTP call.
      Video Name Select List of Files Name from the dynamic content of When a blob is added or modified action.
      Video URL Select Web Url from the dynamic content of Create SAS URI by path action.
      Body Can be left as default.
    3. Select Save.

Flow #2: Create a new logic app of type consumption

Create the second flow, Logic Apps of type consumption. The second flow is triggered based on the callback URL and saves the extracted insights back to a JSON file in Azure Storage.

The flow steps are:

  1. When a HTTP request is received
  2. HTTP
  3. Get Video Index
  4. Create blob (V2)

Set up the trigger

  1. Search for and select the When an HTTP request is received.

    For the trigger, there is a HTTP POST URL field. The URL won’t be generated until after you save your flow; however, you'll need the URL eventually.

    Tip

    We will come back to the URL created in this step.

Generate an access token

You might need to generate another access token depending on how you set up the first one. Copy and paste it into Notepad.

  1. Generate an access token.
  2. Select Save -> + New step.

Set up Get Video Indexer insights

  1. Search for "Video Indexer".

  2. From Video Indexer(V2), select the Get Video Index action.

    Set the connection name:

    Key Value
    Connection name <A name for connection>. For example, aviconnection.
    API key This is your personal API key, which is available under Profile at the developer portal. For more information, see Subscribe to the API.
    1. Select Create.

    2. Fill out the required parameters according to the table:

      Key Value
      Location The Location of the Azure AI Video Indexer account.
      Account ID The Video Indexer account ID can be copied from the resource/account Overview page in the Azure portal.
      Video ID* For Video ID, add dynamic content of type Expression and put in the following expression: triggerOutputs()['queries']['id'].
      Access Token From the dynamic content, under the Parse JSON section select the accessToken that is the output of the parse JSON action.

      *This expression tells the connecter to get the Video ID from the output of your trigger. In this case, the output of your trigger will be the output of Upload video and index in your first trigger.

    3. Select Save -> + New step.

Create a blob and store the insights JSON.

  1. Search for "Azure blob", from the group of actions.

  2. Select Create blob(V2).

  3. Set the connection to the blob storage that will store the JSON insights files.

    Key Value
    Connection name <Enter a connection name>.
    Authentication type Access Key
    Azure Storage Account name <* The storage account name where insights will be stored*>.
    Azure Storage Account Access key Go to Azure portal-> my-storage-> under Security + networking ->Access keys -> copy one of the keys.
    1. Select Create.
    2. Set the folder in which insights will be stored.
    Key Value
    Storage account name <Enter the storage account name that would contain the JSON output (in this tutorial is the same as the source video).>
    Folder path From the dropdown, select the /insights
    Blob name From the dynamic content, under the Get Video Index section select Name and add _insights.json, insights file name will be the video name + insights.json
    Blob content From the dynamic content, under the Get Video Index section, select the Body.
    1. Select Save flow.

Update the callback URL to get notified when an index job is finished.

Once the flow is saved, an HTTP POST URL is created in the trigger.

  1. Copy the URL from the trigger.
  2. Go back to the first flow and paste the URL in the Upload video and index action for the Callback URL parameter.

Make sure both flows are saved.