List Cosmos Document API
We can use Document APIs to manage document in Cosmos DB collection
https://docs.microsoft.com/en-us/rest/api/cosmos-db/documents
List Document – https://docs.microsoft.com/en-us/rest/api/cosmos-db/list-documents
Authorization behaviour for all the calls will be similar but we have to change verb as per our need, so we have to update Dataweave and HTTP request call to Azure.
Mule flow will look like this
Dataweave
%dw 2.0 import java!cosmosdb::GenerateCosmosDBAuthToken output application/java var verb = "GET" var resourceType = "docs" var resourceId = "dbs/hr/colls/employee" var key = "0SZd1Zs3hySH915hKBTQCbewWnzIEI4S2YK8yHDaRwMrnzrZSwaa0hHy8IW21x4qbsQoswWIh3FW8TOd0fpSYw==" var keyType = "master" var tokenVersion = "1.0" var serverDateTime = GenerateCosmosDBAuthToken::getServerTime() as String --- { serverDateTime: serverDateTime, authKey: GenerateCosmosDBAuthToken::generate(verb, resourceType, resourceId, key, keyType, tokenVersion, serverDateTime) }
Please change the resource id and key as per your Azure details
HTTP request
<http:request method="GET" doc:name="Cosmos DB API for SQL insert" doc:id="fb1b2aa9-39f4-4fec-ba42-99b30b9534e3" config-ref="HTTP_Request_configuration" path="dbs/hr/colls/employee/docs" > <http:headers ><![CDATA[#[output application/java --- { "Accept" : "application/json", "x-ms-version" : "2016-07-11", "x-ms-max-item-count": 10, "x-ms-documentdb-query-enablecrosspartition": "False", "Authorization" : vars.cosmosHeader.authKey, "x-ms-date" : vars.cosmosHeader.serverDateTime, "Content-Type" : "application/json" }]]]> </http:headers> </http:request>
Please see the path and different HTTP header we are passing in HTTP request call, please change the same as per your need
Test it through SOAP UI
Documents in Azure
Sample application – cosmos-document-list
Sample SOAP UI project – Cosmos-db-document-list-soapui-project