Delete Entity on Azure Table Storage from Logic App - azure-logic-apps

I have a requirement to delete old records after X days from Azure Table Storage, so I have created a Logic App for that and run on daily bases to remove old data.
I have use the Get All Entities based on the condition in filter query and then run for each with delete entity in it.
Everything is running fine except the Delete Entity, it is giving 404 Resource Not Found error. I have used the same Partition and Row Key from For Each and also used Etag = * but still it is giving me 404.
Input
{
"method": "delete",
"headers": {
"If-Match": "*"
},
"path": "/Tables/deleteordertest/entities/etag(PartitionKey='2021-09-27T19:16:07.778815Z',RowKey='1')",
"host": {
"connection": {
"referenceName": "azuretables"
}
}
}
Output:
{
"statusCode": 404,
"headers": {
"Cache-Control": "no-cache",
"x-ms-request-id": "11d3c7fe-3002-004a-5ed3-0d0096000000",
"x-ms-version": "2016-05-31",
"X-Content-Type-Options": "nosniff",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "true",
"Date": "Thu, 20 Jan 2022 08:01:02 GMT",
"Content-Length": "251",
"Content-Type": "application/json"
},
"body": {
"odata.error": {
"code": "ResourceNotFound",
"message": {
"lang": "en-US",
"value": "The specified resource does not exist.\nRequestId:11d3c7fe-3002-004a-5ed3-0d0096000000\nTime:2022-01-20T08:01:02.6479920Z"
}
}
}
}
Working on Postman
If I try same thing in postman then it is working fine, so I don't know what can be the issue here. I have already tried to add and remove encodeURIComponent but no luck.
I doubt about the : in the PartitionKey but it is working while using Replace Entity (Merge), so it cannot be possible that it will work for one item and not for another..
If any one can help me here or guide me for any alternative.

After reproducing from our end found that the reason that you are receiving a 404 status code because of removing encodeURIComponent which will be refering to the entity that we are retrieving. After adding the encodeURIComponent in Get entities action solved the error.
Here is my logic app
Here is the codeview of my logic app
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Delete_Entity_2": {
"inputs": {
"headers": {
"If-Match": "*"
},
"host": {
"connection": {
"referenceName": "azuretables"
}
},
"method": "delete",
"path": "/Tables/#{encodeURIComponent('Table2408')}/entities/etag(PartitionKey='#{encodeURIComponent(items('For_each')?['PartitionKey'])}',RowKey='#{encodeURIComponent(items('For_each')?['RowKey'])}')"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"foreach": "#body('Get_entities')?['value']",
"runAfter": {
"Get_entities": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_entities": {
"inputs": {
"host": {
"connection": {
"referenceName": "azuretables"
}
},
"method": "get",
"path": "/Tables/#{encodeURIComponent('Table2408')}/entities",
"queries": {
"$filter": "PartitionKey le '5'"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"triggers": {
"Recurrence": {
"recurrence": {
"frequency": "Second",
"interval": 15
},
"type": "Recurrence"
}
}
},
"kind": "Stateful"
}
Here is the output :-

Related

How to iterate over the headers in an Azure Logic App?

In a http triggered Logic App I'd like to iterate over the incoming http headers and use only the x-... headers. These headers should be appended to a JSON message.
I know how to access the headers using triggerOutputs()['headers'], how to iterate over collections and how to construct a JSON message using compose. But how to iterate over the headers?
Note: I don't know the x-... header names and I'd like to append any x-... header into the message, I don't want to update the Logic App if a new header is being added or one is removed.
I tried to create a ForEach that iterates over triggerOutputs()['headers'], but that's not a collection.
The header content:
{
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Accept": "*/*",
"Accept-Encoding": "br,gzip,deflate",
"Host": "prod-42.westeurope.logic.azure.com:443",
"x-batch-uuid": "e74f68b9-d69e-4d50-bfe2-65bd6b38dd45",
"x-event": "12361",
"x-sequence": "1",
"x-trigger-id": "sample-trigger-id",
"x-trigger-time": "1672935303",
"x-uuid": "66fa9513-ab42-4f31-90ff-b44582f7d72f",
"Content-Length": "308",
"Content-Type": "application/json"
}
Current version with static x-header copy action
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"MessageBody": {
"inputs": {
"data": "#triggerBody()",
"meta": "#outputs('X-Headers')"
},
"runAfter": {
"X-Headers": [
"Succeeded"
]
},
"type": "Compose"
},
"Send_message": {
"inputs": {
"body": {
"ContentData": "#{base64(outputs('MessageBody'))}"
},
"host": {
"connection": {
"name": "#parameters('$connections')['servicebus']['connectionId']"
}
},
"method": "post",
"path": "/#{encodeURIComponent(encodeURIComponent('schedule-events'))}/messages"
},
"runAfter": {
"MessageBody": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"X-Headers": {
"inputs": {
"x-batch-uuid": "#{triggerOutputs()?['headers']?['x-batch-uuid']}",
"x-event": "#{triggerOutputs()?['headers']?['x-event']}",
"x-sequence": "#{triggerOutputs()?['headers']?['x-sequence']}",
"x-trigger-id": "#{triggerOutputs()?['headers']?['x-trigger-id']}",
"x-trigger-time": "#{triggerOutputs()?['headers']?['x-trigger-time']}",
"x-uuid": "#{triggerOutputs()?['headers']?['x-uuid']}"
},
"runAfter": {},
"type": "Compose"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"person": {
"properties": {
"href": {
"type": "string"
},
"personId": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"servicebus": {
"connectionId": "/subscriptions/.../resourceGroups/.../providers/Microsoft.Web/connections/servicebus-1",
"connectionName": "servicebus-1",
"id": "/subscriptions/.../providers/Microsoft.Web/locations/westeurope/managedApis/servicebus"
}
}
}
}
}
As mentioned by #skin, you cannot iterate for each loop over an object. Headers is an object, and we can iterate for each loop for array only. As a workaround I have tried a below method. Kindly try if it helps in your case.
Created logic app as shown below,
In for each loop, taken condition as shown below
if(startsWith(item(),'-x'),true,false)
Logic app ran successfully as shown below,

How to create an invoice template

Not sure if this is even possible, but what I'm looking to do create an invoice template via some SQL output and send them out as emails.
What I have tried so far is run a piece of SQL that contains all the details of an invoice, parse it as JSON, then create a csv table and lastly send them out via email with a CSV as an attachment.
The issue that I'm facing is that it's pretty basic; I would like to create a template of sorts and later converted to a PDF.
I'm moving away from SSRS and trying to use a logic app for the first time so not sure if this is something even achievable.
Appreciate any tips/help. Thanks in advance.
Regards
One way to achieve this is to use to Create CSV table with Custom Headers from Sql connector Get rows (V2) action and then convert it to Excel using 3rd party connector Plumsail's Csv to Excel action to transform the results of it into pdf using Convert Excel to PDF action of Adobe PDF services Connector.
Below is the flow of my logic app where I receive a sorted csv's pdf in my email attachments.
RESULTS:
TABLE IN SQL DATABASE
RESULT IN LOGIC APP
RESULT IN MAIL
To reproduce the same in your logic app, you can use below code view
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Convert_Excel_to_PDF": {
"inputs": {
"body": {
"$content-type": "multipart/form-data",
"$multipart": [
{
"body": "EXCEL_TO_PDF",
"headers": {
"Content-Disposition": "form-data; name=\"intent\""
}
},
{
"body": "pdfFile.xlsx",
"headers": {
"Content-Disposition": "form-data; name=\"inputFileName\""
}
},
{
"body": "#body('Csv_to_Excel')",
"headers": {
"Content-Disposition": "form-data; name=\"InputFile0\""
}
}
]
},
"headers": {
"x-api-key": "PowerAutomate"
},
"host": {
"connection": {
"name": "#parameters('$connections')['adobepdftools']['connectionId']"
}
},
"method": "post",
"path": "/operation/v1/createPDFFromExcel"
},
"runAfter": {
"Csv_to_Excel": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Create_CSV_table": {
"inputs": {
"columns": [
{
"header": "BillNo",
"value": "#item()?['billNo']"
},
{
"header": "OrderedDate",
"value": "#item()?['orderedDate']"
},
{
"header": "OrderValue",
"value": "#item()?['orderValue']"
}
],
"format": "CSV",
"from": "#body('Get_rows_(V2)')?['value']"
},
"runAfter": {
"Get_rows_(V2)": [
"Succeeded"
]
},
"type": "Table"
},
"Csv_to_Excel": {
"inputs": {
"body": {
"content": "#{base64(body('Create_CSV_table'))}",
"hasHeaderRecords": true
},
"host": {
"connection": {
"name": "#parameters('$connections')['plumsail_3']['connectionId']"
}
},
"method": "post",
"path": "/flow/v1/Documents/jobs/Csv2Xlsx"
},
"runAfter": {
"Create_CSV_table": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Get_rows_(V2)": {
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['sql']['connectionId']"
}
},
"method": "get",
"path": "/v2/datasets/#{encodeURIComponent(encodeURIComponent('default'))},#{encodeURIComponent(encodeURIComponent('default'))}/tables/#{encodeURIComponent(encodeURIComponent('[dbo].[Invoices]'))}/items",
"queries": {
"$orderby": "billNo asc"
}
},
"runAfter": {},
"type": "ApiConnection"
},
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Attachments": [
{
"ContentBytes": "#{body('Convert_Excel_to_PDF')?['fileContent']}",
"Name": "#body('Convert_Excel_to_PDF')?['fileName']"
}
],
"Body": "<p>This is a sample email</p>",
"Importance": "Normal",
"Subject": "Sample",
"To": "<TO_MAIL_ID>"
},
"host": {
"connection": {
"name": "#parameters('$connections')['office365_1']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"runAfter": {
"Convert_Excel_to_PDF": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"Recurrence": {
"evaluatedRecurrence": {
"frequency": "Minute",
"interval": 3
},
"recurrence": {
"frequency": "Minute",
"interval": 3
},
"type": "Recurrence"
}
}
},
"parameters": {
"$connections": {
"value": {
"adobepdftools": {
"connectionId": "/subscriptions/<SUB_ID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/adobepdftools-4",
"connectionName": "adobepdftools-4",
"id": "/subscriptions/<SUB_ID>/providers/Microsoft.Web/locations/centralus/managedApis/adobepdftools"
},
"office365_1": {
"connectionId": "/subscriptions/<SUB_ID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/office365-1",
"connectionName": "office365-1",
"id": "/subscriptions/<SUB_ID>/providers/Microsoft.Web/locations/centralus/managedApis/office365"
},
"plumsail_3": {
"connectionId": "/subscriptions/<SUB_ID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/plumsail-3",
"connectionName": "plumsail-3",
"id": "/subscriptions/<SUB_ID>/providers/Microsoft.Web/locations/centralus/managedApis/plumsail"
},
"sql": {
"connectionId": "/subscriptions/<SUB_ID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/sql",
"connectionName": "sql",
"id": "/subscriptions/<SUB_ID>/providers/Microsoft.Web/locations/centralus/managedApis/sql"
}
}
}
}
}

I am able to set up to receive emails, but I am unable to upload attachments to onedrive. Please tell me how to upload the file

I want to store a specific Excel file attached to an email I receive in outlook in a specific folder in onedrive.
(I have the process to store the file in blob, but I want to process the Excel file, so I am thinking of saving it once in onedrive.)
I am able to set up to receive emails, but I am unable to upload attachments to onedrive. Please tell me how to upload the file.
The contents of the Excel file, but there are multiple sheets.
The json looks like this. (partially hidden)
{
"id": "/subscriptions/XXXXXXXX/resourceGroups/XXXXXXXX/providers/Microsoft.Web/sites/test/workflows/excel_test2",
"name": "test/excel_test2",
"type": "Microsoft.Web/sites/workflows",
"kind": "Stateful",
"location": "XXXXXXXX",
"properties": {
"files": {
"workflow.json": {
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Update_file": {
"inputs": {
"body": "#base64ToBinary(items('For_each')?['contentBytes'])",
"host": {
"connection": {
"referenceName": "onedriveforbusiness"
}
},
"method": "put",
"path": "/datasets/default/files/#{encodeURIComponent(encodeURIComponent('filebox\\raw\\*.xlsm'))}"
},
"runAfter": {
"Getting Attachments_(V2)": [
"Succeeded"
]
},
"runtimeConfiguration": {
"contentTransfer": {
"transferMode": "Chunked"
}
},
"type": "ApiConnection"
},
"Getting Attachments_(V2)": {
"inputs": {
"host": {
"connection": {
"referenceName": "office365"
}
},
"method": "get",
"path": "/codeless/v1.0/me/messages/#{encodeURIComponent(triggerBody()?['id'])}/attachments/#{encodeURIComponent(items('For_each')?['id'])}"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"foreach": "#triggerBody()?['attachments']",
"runAfter": {},
"type": "Foreach"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"triggers": {
"When you receive a new email_(V3)": {
"inputs": {
"fetch": {
"method": "get",
"pathTemplate": {
"template": "/v3/Mail/OnNewEmail"
},
"queries": {
"fetchOnlyWithAttachment": true,
"folderPath": "Id::XXXXXXXX=",
"importance": "Any",
"includeAttachments": true
}
},
"host": {
"connection": {
"referenceName": "office365"
}
},
"subscribe": {
"body": {
"NotificationUrl": "#{listCallbackUrl()}"
},
"method": "post",
"pathTemplate": {
"template": "/GraphMailSubscriptionPoke/$subscriptions"
},
"queries": {
"fetchOnlyWithAttachment": true,
"folderPath": "Id::XXXXXXXX=",
"importance": "Any"
}
}
},
"metadata": {
"Id::XXXXXXXX=": "XXXXXXXX_1"
},
"splitOn": "#triggerBody()?['value']",
"type": "ApiConnectionNotification"
}
}
},
"kind": "Stateful"
}
},
"flowState": 2,
"health": {
"state": 1
}
}
}
One way to achieve your requirement is to create a file in OneDrive with the same name as you are receiving from outlook. Below is the flow of my logic app.
Below is the mail I'm receiving in my outlook
RESULTS:
Results in Logic Apps
Results in One drive

How to send array from Web Activity of ADF to Logic App Webhook?

I try to send list from Web Activity Azure Data Factory, but I cannot make list/array to passed correctly to webhook. Please advice!
I have used this tutorial as base:
https://www.youtube.com/watch?v=ttmETFGYSLg
I have Web activity in Azure Data Factory Posting following body: (this works fine)
{
"ListOfTestNames:" : #{variables('Test_name_list')}
}
I have Logic Apps with "When HTTP request is received".Method is set Post and Schema is followings:
{
"properties": {
"ListOfTestNames": {
"type": "array"
}
},
"type": "object"
}
I have HTTP Webhook in Logic Apps. This works fine and return body including ListOfTestName
#{triggerBody()}
I have HTTP Webhook in Logic Apps:This does not return anything. I wonder why?
#{triggerBody()?['ListOfTestNames']}
I tried both type Array and String
Logic Apps Code: (generated by designer)
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"HTTP_Webhook": {
"inputs": {
"subscribe": {
"body": {
"blocks": [
{
"text": {
"text": "*These are list of names* \n ListOfTestNames #{triggerBody()?['ListOfTestNames:']} ",
"type": "mrkdwn"
},
"type": "section"
},
{
"text": {
"text": "There is currently bug and list of names are not displayed ",
"type": "mrkdwn"
},
"type": "section"
}
]
},
"method": "POST",
"uri": "https://hooks.slack.com/services/11111111111111111111111111111111111111111"
},
"unsubscribe": {}
},
"runAfter": {},
"type": "HttpWebhook"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"method": "POST",
"schema": {
"properties": {
"ListOfTestNames:": {
"type": "array"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
After reproducing the problem on our end, we discovered that the expression you're using is invalid, however it worked when we tried to use
#triggerBody()?['ListOfTestNames']
but not when using
#{triggerBody()?['ListOfTestNames']}
Here are the screenshots for your reference:
When #triggerBody()?['ListOfFiles'] is used:
When #triggerBody() is used :

Can I chain multiple actions for every item in a repeat list

tried a simple logic app where I was able to retrieve a list from an API. Using the repeat over a list feature, I was able to send an email for every item in the list.
But I really want to be able to perform several chained actions/steps for every item in the list...isn't that possible? I know I can have multiple actions/steps that perform something for each item in the same list...but these are not chained as in the following code:
"triggers": {
"recurrence": {
"recurrence": {
"frequency": "Day",
"interval": 1
},
"type": "Recurrence"
}
},
"actions": {
"http": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "https://example.com/pcme/3/7",
"headers": {
"Content-Type": "application/json",
"Authorization": "Basic my auth"
}
},
"conditions": []
},
"office365connector": {
"type": "ApiApp",
"inputs": {
"apiVersion": "2015-01-14",
"host": {
"id": "/subscriptions/xxxx/resourcegroups/workflows/providers/Microsoft.AppService/apiapps/office365connector",
"gateway": "https://workflowsxxxxxx.azurewebsites.net"
},
"operation": "SendMail",
"parameters": {
"message": {
"To": "some-email#me.com",
"Subject": "#repeatItem().activationCode"
}
},
"authentication": {
"type": "Raw",
"scheme": "Zumo",
"parameter": "#parameters('/subscriptions/xxxxxx/resourcegroups/workflows/providers/Microsoft.AppService/apiapps/office365connector/token')"
}
},
"repeat": "#body('http')",
"conditions": [
{
"expression": "#equals(actions('http').status, 'Succeeded')"
}
]
},
"office365connector0": {
"type": "ApiApp",
"inputs": {
"apiVersion": "2015-01-14",
"host": {
"id": "/subscriptions/xxxx/resourcegroups/workflows/providers/Microsoft.AppService/apiapps/office365connector",
"gateway": "https://workflowsdxxxx.azurewebsites.net"
},
"operation": "SendMail",
"parameters": {
"message": {
"To": "some-email#gmail.com",
"Subject": "#repeatItem().cardNumber"
}
},
"authentication": {
"type": "Raw",
"scheme": "Zumo",
"parameter": "#parameters('/subscriptions/xxxxx/resourcegroups/workflows/providers/Microsoft.AppService/apiapps/office365connector/token')"
}
},
"repeat": "#body('http')",
"conditions": [
{
"expression": "#equals(actions('http').status, 'Succeeded')"
}
]
}
Thank you for any help.
Regards
One option for chaining actions over each item in the list is to use a nested logic app.
The way you would set it up is to have a child logic app with a chain of actions that you want to apply to each individual item. The parent logic app would then use the workflow action type in order to invoke a run of the child logic app each of your repeat items.
Your parent workflow would then be defined as
"actions": {
"http": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "https://example.com/pcme/3/7",
"headers": {
"Content-Type": "application/json",
"Authorization": "Basic my auth"
}
},
"conditions": []
},
"processEachItem" : {
"type": "workflow",
"inputs": {
"uri": <child flow direct invoke uri>,
"apiVersion": "2015-02-01-preview",
"trigger": {
"name" : "runNow",
"outputs": { "item": "#repeatItem()" }
},
"authentication": {
"type" : " Basic",
"username" : "myKey",
"password" : "xxxxxxxxxxxxxxx",
},
"repeat": "#body('http')",
}
}
}
The following blog post explains the details on how to use nested workflows (how to obtain the direct invoke URI and configure authentication) and has a nice sample: https://blogs.msdn.microsoft.com/carlosag/2015/05/31/using-nested-azure-logic-apps-or-invoking-flows-from-another-logic-app/

Resources