Update Data Into Azure Cosmos DB Using Power Automate

In this article, I will provide information on how to update data to an existing Azure Cosmos DB using Power Automate.
 
Below are the components used in this document
  1. Azure Cosmos DB
  2. Power Automate

Introduction

 
In my example, I already have a Cosmos DB created. In case you need help with creating the database and performing any other operations on that database like putting the index, unique keys etc, you can refer to  the same MS docs mentioned above. Below is the step by step way to update data to Azure Cosmos DB.
 

Open Power Automate and create a new Flow

 
NOTE
In case you already have a Power Automate created, you can ignore this step.
 
Step 1
 
Browse to here and provide your Office 365 account details to login
 
Update Data Into Azure Cosmos DB Using Power Automate
 
Step 2
 
Select either a “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 the 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.
 
Update Data Into Azure Cosmos DB Using Power Automate
 
Step 3
 
Empty Flow will be opened.
 
Update Data Into Azure Cosmos DB Using Power Automate
 

Power Automate to update data to Cosmos DB

 
Step 1
 
Name your Flow with an appropriate meaning. Add a new Step “Create or Update document”. In case you are not able to find it, then you should search for “Cosmos” and under that you would be able to select the “Create or Update document” Step as shown in the below screen shot.
 
Update Data Into Azure Cosmos DB Using Power Automate
 
Step 2
 
Now once you add the step, you will  need to fill the mandatory field values. The most important field is “Document”. When it comes to Cosmos DB, every piece of data which gets stored in it, is considered as a JSON object. So we need to create a JSON object of the data which needs to be updated in Azure Cosmos DB. In my example: I have few text fields and few DateTime fields. My JSON object looks like below. Create your JSON object according to your Cosmos DB Column structure.
  1. {  
  2.     "$pk""intranet.contoso.com",  
  3.     "$id""uniqueKey121",  
  4.     "id""uniqueKey121",  
  5.     "PrimaryOwnerEmail": {  
  6.         "$t": 2,  
  7.         "$v""abcd@onmicrosoft.com"  
  8.     },  
  9.     "MigrationStatus": {  
  10.         "$t": 2,  
  11.         "$v""completed"  
  12.     },  
  13.     "SourceSiteURL": {  
  14.         "$t": 2,  
  15.         "$v""http://abcd.onmicrosoft.com"  
  16.     }  
  17. }  
In the above example: "$pk" stands for the Partition Key for the Azure Cosmos DB. "$id" and “id” stands for row identifier which should be unique for every row we update into the Cosmos DB. Remaining are the columns in my Cosmos DB. In my example I want to update the value of “MigrationStatus” to Completed.
 
Update Data Into Azure Cosmos DB Using Power Automate
 
Step 3
 
Save your Flow and test the flow, we should see data updated in Cosmos DB.
 
Update Data Into Azure Cosmos DB Using Power Automate
 
That is it. I hope you have learned something new from this article and will utilize this in your work.