Read Data From Azure Cosmos DB Using Power Automate

In this article, I will provide information on how to read data from an existing Azure Cosmos DB using Power Automate.

Below are the components used in this document.

  1. Azure Cosmos DB
  2. Power Automate

Introduction

For details on Azure Cosmos DB, you can read the MS Doc here. To get more details on how to insert data into Cosmos DB using Power Automate, you can refer to my previous article here.

Today we will see how to read some data from Cosmos DB whenever a button is clicked on a Power App Form. This was achieved using Power Automate connecting to Azure Cosmos DB to read the data. In my example, I already had Cosmos DB created. Below is the step-by-step way to read data from Azure Cosmos DB.

Open Power Automate and create a new Flow

Note. If you already have Power Automate created, you can ignore this step.

Step 1. Browse to https://india.flow.microsoft.com and provide your Office 365 account details to log in.

 Office 365 account

Step 2. Select either “Templates” to start your Flow or you can search for the template. For my example, I am selecting “Templates” from the left navigation highlighted with yellow color in below image, and then selecting the Power Apps button, as a trigger point for my Flow a button click from Power Apps. You can select the template based on your requirements.

Templates

Step 3. Empty Flow will be opened.

Empty Flow

Power Automate to read data from Cosmos DB

Step 1. Name your Flow with the appropriate meaning. Add a new Step “Get all documents”, which will get all the rows from the Cosmos DB. In case you are not able to find it, then you should search for “Cosmos” and under that, you will be able to select the “Get all documents” Step as shown in the below screenshot.

Get all documents

Step 2. Now once you add the step, you will need to fill in the mandatory field values. The most important field is the “Partition Key Value”. Check your Azure Cosmos DB settings and get this partition key value from there.

 Azure Cosmos DB

Step 3. Save your Flow and test the flow, we should see data coming from Cosmos DB.

Cosmos DB

Step 4. Now if we have to get specific row data from Cosmos DB, we will add a new Step “Get a document”, which will get all the rows from the Cosmos DB. In case you are not able to find it, then you should search for “Cosmos” and under that, you will be able to select the “Get a document” step as shown in the below screenshot.

Step 5. Now once you add the Step, you will need to fill in the mandatory field values. The most important field is “Document ID”. This is the unique key to identify each row inside Cosmos DB.

Document ID

Step 6. Save your flow and test the flow, we should see data coming from Cosmos DB.

Save your flow

That is it. I hope you have learned something new from this article and will utilize this in your work.


Similar Articles