Skip to content

Power Automate / Logic Apps Examples

Power Automate and Azure Logic Apps can call the KnowledgeLake API through a custom connector made from your tenant's own spec. The connector turns every API action into a flow action with typed inputs and outputs. This page shows how to import the spec, connect with a token, and build four tasks: get a work item, upsert metadata, run a saved search, and create a work item and send it to a workflow.

At a glance

  • Tool A Power Automate custom connector, or a Logic Apps custom connector
  • Built from Your tenant's OpenAPI 2.0 document (V2_JSON)
  • Authentication API key TempIdentityToken in the header, stored only in the connection
  • Tasks on this page Get a work item, upsert metadata, run a saved search, create a work item and send it to a workflow

For the call shape, the token header and the response envelope, see the Introduction.

What you need

  • A Power Automate license that allows custom connectors and the HTTP action (premium), or an Azure Logic Apps resource.
  • A token for a service account, with the features your flows use (for these examples: Manage Work Items, Manage Workflows, Run Searches). See Authentication.

Step 1: Get the spec

Your tenant serves an OpenAPI 2.0 document, which is the version custom connectors import:

https://{tenant}/api/OpenAPI/V2_JSON/V2_JSON?domain=https://{tenant}

Open the URL in a browser and save the file as knowledgelake.openapi.json. The document needs no token. It already declares the TempIdentityToken header as the API key.

Step 2: Create the custom connector

  1. In Power Automate, go to Data > Custom connectors > New custom connector > Import an OpenAPI file. (In Logic Apps, create a Logic Apps Custom Connector resource and import the same file.)
  2. Name the connector KnowledgeLake and select the file.
  3. General: check that Host is your tenant host and Base URL is /api.
  4. Security: the authentication type is API Key, with parameter name TempIdentityToken and location Header. Set the parameter label to API token.
  5. Definition: each action appears with an operation id such as V1KWorkItemAPIController_GetWorkItem. Set a short summary on the actions you use, for example Get work item. This is the name you see in the flow designer.
  6. Select Create connector.

You can also import from the URL. That works only from the Power Automate and Azure portal origins that the tenant allows for cross-site requests. If URL import fails, use the file.

If the import is slow or the designer is hard to use with every action in it, delete the actions you do not need on the Definition page, or remove their paths from the file before import.

When your tenant is upgraded, import the spec again to pick up new actions. A fresh import includes the V1_JobsAPI and V1_RPAAPI actions, for example to post a message to a team channel when QueryForJobRuns returns a job in Error.

Step 3: Create a connection

  1. Go to Test, select New connection, paste the token string and select Create connection.
  2. Test V1KWorkItemAPIController_GetWorkItem with a known WorkItemId. The response body shows "Success": true.

Store the token only in the connection. Do not put it in a flow variable or a compose action, where run history shows it.

Check Success in every flow

  • Check Success as well as the status. Add a Condition after each call: body('Get_work_item')?['Success'] is equal to true.
  • An HTTP 401, 412 or 422 makes the action fail. To handle it, add an action after it with Configure run after set to has failed, and read the reason from body('Get_work_item')?['Messages'] (412) or body('Get_work_item')?['MessageKey'] (401, 422).

The names in body('...') are the action names in your flow, with spaces replaced by underscores.

Get a work item

Action: Get work item (V1_KWorkItemAPI/GetWorkItem). Input WorkItemId.

Read a work item value:

body('Get_work_item')?['Data']?['Metadata']?['Index']?['Vendor']

Loop over documents with Apply to each on body('Get_work_item')?['Data']?['Documents']. Inside, a document's id is items('Apply_to_each')?['Id'] and a value is items('Apply_to_each')?['Metadata']?['Index']?['Title'].

Upsert metadata

Action: Upsert work item metadata (V1_KWorkItemAPI/UpsertWorkItemMetadata). Inputs WorkItemId and Metadata, an array. Switch the Metadata input to array mode and enter:

[
  { "Bucket": "Index", "Key": "NeedsReview", "Value": "Yes" },
  { "Bucket": "General", "Key": "ReviewedBy", "Value": "power-automate" }
]

For one document, use Upsert document metadata (UpsertDocumentMetadata) with WorkItemId, DocumentId and the same Metadata array. Every Value is a string. Wrap expressions with string(...) when the source is a number or a boolean.

  1. Get saved searches (V1_RepositoryAPI/GetSavedSearches) with an empty body.
  2. Filter array on body('Get_saved_searches')?['Data'] where SavedSearchName equals your search name. Take first(...).
  3. Run saved search (V1_RepositoryAPI/RunSavedSearch) with SearchId = SavedSearchId, SearchCatalogId, StartRow = 0, RowLimit = 200, and SearchConditions:
{ "Strings": { "<ConditionId from GetSavedSearches>": "Gateway Fleet Services LLC" } }

Results are in body('Run_saved_search')?['Data']?['Results']. To read more rows, loop with Do until and add RowLimit to StartRow until a page has fewer rows than RowLimit.

Create a work item and send it to a workflow

This flow starts when a file lands in a SharePoint library.

  1. Trigger: SharePoint When a file is created in a folder.
  2. New work item (V1_KWorkItemAPI/NewWorkItem): WorkItemName = the file name without extension. Read the id from body('New_work_item')?['Data']?['WorkItemId'].
  3. Add document: use the HTTP action, which gives you full control of the multipart body. Method POST, URI https://{tenant}/api/V1_KWorkItemAPI/AddDocument, header TempIdentityToken from a secure source (an environment variable of type Secret, or Azure Key Vault Get secret with secure outputs on), and this body:
{
  "$content-type": "multipart/form-data",
  "$multipart": [
    {
      "headers": { "Content-Disposition": "form-data; name=\"WorkItemId\"" },
      "body": "@{body('New_work_item')?['Data']?['WorkItemId']}"
    },
    {
      "headers": { "Content-Disposition": "form-data; name=\"File\"; filename=\"@{triggerOutputs()?['headers']?['x-ms-file-name']}\"" },
      "body": @{triggerBody()}
    },
    {
      "headers": { "Content-Disposition": "form-data; name=\"MetadataParameter\"" },
      "body": "{\"Metadata\":[{\"Bucket\":\"Index\",\"Key\":\"SourceLibrary\",\"Value\":\"Invoices\"}]}"
    }
  ]
}
  1. Condition: body('Add_document')?['Success'] is equal to true.
  2. Get all workflows (V1_WorkflowAPI/GetAllWorkflows), then Filter array where WorkflowName equals your workflow name.
  3. Send to workflow (V1_WorkflowAPI/SendToWorkflow): WorkflowId from the filtered item, WorkItemId from step 2.

Add every document before Send to workflow. See Create a work item and send it to a workflow for what can go wrong.