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
TempIdentityTokenin 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:
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¶
- 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.)
- Name the connector
KnowledgeLakeand select the file. - General: check that Host is your tenant host and Base URL is
/api. - Security: the authentication type is API Key, with parameter name
TempIdentityTokenand location Header. Set the parameter label toAPI token. - Definition: each action appears with an operation id such as
V1KWorkItemAPIController_GetWorkItem. Set a short summary on the actions you use, for exampleGet work item. This is the name you see in the flow designer. - 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¶
- Go to Test, select New connection, paste the token string and select Create connection.
- Test
V1KWorkItemAPIController_GetWorkItemwith a knownWorkItemId. 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
Successas well as the status. Add a Condition after each call:body('Get_work_item')?['Success']is equal totrue. - 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) orbody('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:
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.
Run a saved search¶
- Get saved searches (
V1_RepositoryAPI/GetSavedSearches) with an empty body. - Filter array on
body('Get_saved_searches')?['Data']whereSavedSearchNameequals your search name. Takefirst(...). - Run saved search (
V1_RepositoryAPI/RunSavedSearch) withSearchId=SavedSearchId,SearchCatalogId,StartRow=0,RowLimit=200, andSearchConditions:
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.
- Trigger: SharePoint When a file is created in a folder.
- New work item (
V1_KWorkItemAPI/NewWorkItem):WorkItemName= the file name without extension. Read the id frombody('New_work_item')?['Data']?['WorkItemId']. - Add document: use the HTTP action, which gives you full control of the multipart body. Method
POST, URIhttps://{tenant}/api/V1_KWorkItemAPI/AddDocument, headerTempIdentityTokenfrom 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\"}]}"
}
]
}
- Condition:
body('Add_document')?['Success']is equal totrue. - Get all workflows (
V1_WorkflowAPI/GetAllWorkflows), then Filter array whereWorkflowNameequals your workflow name. - Send to workflow (
V1_WorkflowAPI/SendToWorkflow):WorkflowIdfrom the filtered item,WorkItemIdfrom 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.
Related¶
- Introduction
- Authentication: rotate the token, then update the connection.
- Find and resubmit failed jobs