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,
- Azure Cosmos DB
- 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 was 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 login
Step 2
Select either “Templates” to start your Flow or you can search for the template. For my example I am selecting “Templates” from left navigation highlighted with yellow color in below image and then selecting Power Apps button, as trigger point for my Flow is a button click from Power Apps. You can select the template based on your requirements.
Step 3
Empty Flow will be opened.
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 screen shot.
Step 2
Now once you add the step, you will need to fill 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.
Step 3
Save your Flow and test the flow, we should see data coming from 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 screen shot.
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.
Step 6
Save your flow and test the flow, we should see data coming from Cosmos DB.
That is it. I hope you have learned something new from this article and will utilize this in your work.