Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to: Azure Logic Apps (Consumption + Standard)
From a workflow in Azure Logic Apps, you can connect to Azure Cosmos DB and work with documents by using the Azure Cosmos DB connector. For example, you can use connector operations to create, update, read, query, or delete documents.
You can connect to Azure Cosmos DB from both Consumption and Standard logic app workflows by using the managed connector operations, which are hosted, managed, and run in global, multitenant Azure. For Standard workflows, Azure Cosmos DB also provides built-in operations that run alongside the runtime for single-tenant Azure Logic Apps. Built-in operations offer better performance, higher throughput, and sometimes different functionality. For example, in a Standard workflow, you can use the built-in trigger to monitor an Azure Cosmos DB container for new or updated items. You can combine Azure Cosmos DB operations with others in a workflow to support scenarios like event sourcing and general data processing.
Currently, only stateful workflows in a Standard workflow can use both the managed connector operations and built-in operations. Stateless workflows can use only the built-in operations.
The Azure Cosmos DB connector supports only Azure Cosmos DB accounts created with Azure Cosmos DB for NoSQL.
An Azure account and subscription. If you don't have an Azure subscription, sign up for a trial Azure subscription.
A logic app workflow from where you want to access an Azure Cosmos DB account. To use the Azure Cosmos DB built-in trigger, you need to start with a blank workflow.
For reference information about the Azure Cosmos DB managed connector operations, such as triggers, actions, and limits, see the managed connector's reference page.
For reference information about the Azure Cosmos DB built-in operations, such as triggers, actions, and limits, see the built-in operations reference page.
In Azure Logic Apps, every workflow must start with a trigger, which fires when a specific event happens or when a specific condition is met.
If you're working with a Standard workflow, the built-in trigger named When an item is created or modified is available and is based on the Azure Cosmos DB change feed design pattern. This trigger is unavailable for Consumption workflows.
No Azure Cosmos DB triggers are available for Consumption workflows. Instead, add a trigger that works for your scenario.
In Azure Logic Apps, an action is a step in a workflow that follows a trigger or another action. The Azure Cosmos DB connector offers actions for both Consumption and Standard workflows. The following examples show how to use an action that creates or updates a document.
To add an Azure Cosmos DB action to a Consumption workflow, follow these steps:
In the Azure portal, open your Consumption workflow in the designer.
If the workflow is blank, add any trigger that you want.
This example starts with the When an HTTP request is received trigger.
Under the trigger or action where you want to add the Azure Cosmos DB action, follow these general steps to add the Azure Cosmos DB action that you want.
This example uses the action named Create or update document (V3).
If you're prompted for connection details, create a connection to your Azure Cosmos DB account now.
In the action information pane, on the Parameters tab, provide the following necessary information:
Parameter Required Value Description Azure Cosmos DB account name Yes <Cosmos-DB-account-name> The account name for the Azure Cosmos DB account. Database ID Yes <Cosmos-DB-database-name> The database to connect. Collection ID Yes <Cosmost-DB-container-name> The container to query. Document Yes <JSON-document> The JSON document to create. This example uses the request body from the trigger output.
Tip: If the HTTP trigger's Body token doesn't appear in the dynamic content list for you to add, next to the trigger name, select See more.
Note: Make sure that the body is well-formed JSON, and at a minimum, contains theid
property and the partition key property for your document. If a document with the specifiedid
and partition key exists, the document is updated. Otherwise, a new document is created.For example:
To add any other available parameters, open the Advanced parameters list.
Configure any other parameters or settings as needed.
On the designer toolbar, select Save.
Test the workflow to confirm that the action creates a document in the specified container.
When you add a trigger or action that connects to a service or system, and you don't have an existing or active connection, Azure Logic Apps prompts you to provide the connection information, which varies based on the connection type, for example:
- A name to use for the connection
- Your account credentials
- The server or system name
- A connection string
- The authentication type to use
Before you can configure an Azure Cosmos DB trigger or Azure Cosmos DB action, you need to connect to a database account.
For a Consumption workflow, an Azure Cosmos DB connection requires the following information:
Parameter | Required | Value | Description |
---|---|---|---|
Connection Name | Yes | <connection-name> | The name to use for the connection. |
Authentication Type | Yes | <connection-type> | The authentication type to use. This example uses Access key. - If you select Access Key, provide the remaining required property values to create the connection. - If you select Microsoft Entra ID Integrated, no other property values are required, but you have to configure the connection by following the steps for Microsoft Entra authentication and Azure Cosmos DB connector. - To set up a managed identity, see Authenticate access and connections to Azure resources with managed identities in Azure Logic Apps. |
Account ID | Yes | <account-ID> | The name for the Azure Cosmos DB account to use for this connection. |
Access Key To Your Azure Cosmos DB Account | Yes | <access-key> | The access key for the Azure Cosmos DB account to use for this connection. This value is either a read-write key or a read-only key. Note: To find the key, go to the Azure Cosmos DB account page. In the account menu, under Settings, select Keys. Copy one of the available key values. |
Note
After you create the connection, if you have a different Azure Cosmos DB connection that you want to use instead, or if you want to create a new connection, select Change connection in the Parameters tab on the trigger or action information pane.
The Query items built-in action in a Standard workflow has many dynamic content outputs available for use in subsequent actions. To get the query result items or item metadata as an iterable object, follow these steps:
In the Azure portal, open your Standard workflow in the designer.
If the workflow is blank, add any trigger that you want.
This example starts with the Recurrence trigger.
Under the trigger or action where you want to add the Azure Cosmos DB action, follow these general steps to add the Azure Cosmos DB action named Query items.
If you're prompted for connection details, create a connection to your Azure Cosmos DB account.
In the action information pane, on the Parameters tab, provide the following necessary information:
Parameters Required Value Description Database Id Yes <database-ID> The database to connect. Container Id Yes <container-ID> The container to query. SQL Query Yes <sql-query> The SQL query for the request. The following example shows the Query items action:
Configure any other parameters or settings as needed.
Under the Query items action, follow these general steps to add an action that you want to run on all the returned query items.
This example uses the Azure Cosmos DB built-in action named Delete an item.
In the Delete an item action, you can access outputs from the Query items action by following these steps:
Select inside any input field to show the available options.
Select the lightning icon to open the dynamic content list.
From the Query items section in the list, select the output you want, or select See more for more outputs.
For example, you can select Response Items Item to populate the Item Id field with IDs from the query results.
After you select the Response Items Item, the For each action is automatically added to iterate through all the query results. The For each loop contains the Delete an item action.
Add any other actions that you want to the loop.
On the designer toolbar, select Save.
Test the workflow to confirm that the actions return the output that you expect.