Convert CSV file as array in logic apps - azure-logic-apps

I want to read CSV file as array in logic apps. I didn't find any documents related to it. Any help on this would be appreciated. Thank you!

Based on your question here are few arounds that we can try below either way for 2 different outputs.
READ EACH OBJECT CSV FILE AS ARRAY OBJECT:
We can use split and add the output of the compose connector into Array by adding 'Initialise Variable' Connector and for converting each word into array variable we need to add for each connector inside another for each connector to iterate the items inside the CSV file then with a split variable inside the inner for each connector having split(item(),',') expression.
READ EACH ROW IN CSV FILE AS AN ARRAY:
We can use Plumsail's Parse CSV connector in order to convert each CSV row as an array considering headers in the CSV file.
Here are the screenshots for your reference
Expression in compose connector
split(body('Get_blob_content_(V2)'),'\n')
Expression in For each 2 connector
split(item(),',')
Note: Make sure you go to your code view and change the expression in your split from
split(body('Get_blob_content_(V2)'),'\\n') to split(body('Get_blob_content_(V2)'),'\n') as when we are writing the expression for this it first takes '\n' as string and adds another "" to the expression.
Here is the code view of my logic app
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "#split(body('Get_blob_content_(V2)'),'\n')",
"runAfter": {
"Get_blob_content_(V2)": [
"Succeeded"
]
},
"type": "Compose"
},
"Compose_2": {
"inputs": "#variables('array1')",
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Compose"
},
"For_each": {
"actions": {
"For_each_2": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "array1",
"value": "#items('For_each_2')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "#split(item(),',')",
"runAfter": {},
"type": "Foreach"
}
},
"foreach": "#outputs('Compose')",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_blob_content_(V2)": {
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['azureblob_1']['connectionId']"
}
},
"method": "get",
"path": "/v2/datasets/#{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/#{encodeURIComponent(encodeURIComponent('JTJmY29udGFpbmVyMjQlMmZkYXRhLWFydGljbGUuY3N2'))}/content",
"queries": {
"inferContentType": true
}
},
"metadata": {
"JTJmY29udGFpbmVyMjQlMmZkYXRhLWFydGljbGUuY3N2": "/container24/data-article.csv"
},
"runAfter": {},
"type": "ApiConnection"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "array1",
"type": "array",
"value": "#outputs('Compose')"
}
]
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_CSV": {
"inputs": {
"body": {
"content": "#{base64(body('Get_blob_content_(V2)'))}",
"headers": "url,user_id,token_id,username,password"
},
"host": {
"connection": {
"name": "#parameters('$connections')['plumsail']['connectionId']"
}
},
"method": "post",
"path": "/flow/v1/Documents/jobs/ParseCsv"
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureblob_1": {
"connectionId": "/subscriptions/<Your subscription>/resourceGroups<Your resourec group >/providers/Microsoft.Web/connections/azureblob-1",
"connectionName": "azureblob-1",
"id": "/subscriptions/<Your subscription>/providers/Microsoft.Web/locations/northcentralus/managedApis/azureblob"
},
"plumsail": {
"connectionId": "/subscriptions/<Your subscription>/resourceGroups/<Your resourec group >/providers/Microsoft.Web/connections/plumsail",
"connectionName": "plumsail",
"id": "/subscriptions/<Your subscription>/providers/Microsoft.Web/locations/northcentralus/managedApis/plumsail"
}
}
}
}
}
REFERENCES:
Convert CSV elements into a single Array using Azure Logic Apps - Stack Overflow

Related

Azure Logic apps - output array in email body

I have trouble using my array variable in my V2 email in Logic apps. I would like to output my array in the email body. For example if my array is ["1","2",3"]. Im want each value on its own row.
1
2
3
I have 2 issues, outputting my array in the email body(only strings showing in the dynamic menu) and making each value on a row.
After reproducing from my end, I could able to achieve your requirement by replacing "," with "< br>< br>" while sending the email using Send an email (V2) action. Below is the expression that worked for me.
replace(string(variables('SampleArray')),',','<br><br>')
Here is the flow of my Logic App
Result in my Inbox:
To reproduce the same, you can use below codeview in your logicapp
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"SampleArray": {
"inputs": {
"variables": [
{
"name": "SampleArray",
"type": "array",
"value": [
1,
2,
3
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Body": "<p>#{replace(string(variables('SampleArray')),',','<br><br>')}</p>",
"Importance": "Normal",
"Subject": "Sample",
"To": "<YOUR-EMAIL>"
},
"host": {
"connection": {
"name": "#parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"operationOptions": "DisableAutomaticDecompression",
"runAfter": {
"SampleArray": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "/subscriptions/<SUB-ID>/resourceGroups/<RG>/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/<SUB-ID>/providers/Microsoft.Web/locations/centralus/managedApis/office365"
}
}
}
}
}

How do I loop though a text file, line by line, and append each line to an array?

I'm trying to loop through a .txt, line by line, but there does not seem to be a good way to do this.
The idea is to extract each line and append it to an array.
Consider you have a text file like
and I'm trying to read the same file from blob storage. In order to make each line into an array, you can use a compose connector with a split() function in it. Here is my logic app screenshot for reference:-
Here is the split expression in compose connector
split(body('Get_blob_content_(V2)'),'
')
RESULT
Below is the Code view of my logic app:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "#split(body('Get_blob_content_(V2)'),'\r\n')",
"runAfter": {
"Get_blob_content_(V2)": [
"Succeeded"
]
},
"type": "Compose"
},
"Get_blob_content_(V2)": {
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "get",
"path": "/v2/datasets/#{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/#{encodeURIComponent(encodeURIComponent('JTJmY29udGFpbmVyMSUyZnNhbXBsZVRleHRGaWxlLnR4dA=='))}/content"
},
"metadata": {
"JTJmY29udGFpbmVyMSUyZnNhbXBsZVRleHRGaWxlLnR4dA==": "/container1/sampleTextFile.txt"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureblob": {
"connectionId": "/subscriptions/<YourSubscriptionId>/resourceGroups/<YourResourceGroup>/providers/Microsoft.Web/connections/azureblob",
"connectionName": "azureblob",
"id": "/subscriptions/<YourSubscriptionId>/providers/Microsoft.Web/locations/northcentralus/managedApis/azureblob"
}
}
}
}
}

How to conditionally transform JSON based on body response in Azure Logic App

I Want to have an Azure Logic App that receives HTTP data from multiple device types.
Each device has different body JSON schema structure.
Base on the response body (structure or specific value) I want to execute specific Liquid Map so that the result will be normalized response.
(Assume that I cannot check on HTTP headers...)
Is there a better pattern than Logic App?
Thanks!
You can create a basic json schema with atleast one field that could identify where the call came from (caller should send that field in the body) and based on that field parse the incoming json against a more comprehensive schema (format 1, 2 etc).
However, I would recommend creating separate logic apps if there is a major diff b/w input posted from the sources. It is not a good practice to have different flows based on the caller. Logic app should have minimal logic. Your approach might be not be good in the long term.
Here is one of the workaround that you can try.
Here is my logic app
I have considered a sample data to explain this in a better way.
Here is the data that I'm sending to the HTTP Trigger:-
{
"devices": [
{
"device_number": 1,
"device_type": "mobile",
"device_name": "MobileA"
},
{
"device_number": 2,
"device_type": "desktop",
"device_name": "DesktopA"
},
{
"device_number": 3,
"device_type": "tablet",
"device_name": "TabletA"
},
{
"device_number": 4,
"device_type": "desktop",
"device_name": "DesktopB"
}
]
}
Then I'm trying to parse the whole data that I'm sending for future use and performing some functions which segregates the json into device_number, device_type and device_name.
Here is the schema that I'm using to parse that data that is sent to the Http Trigger
{
"type": "object",
"properties": {
"devices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"device_number": {
"type": "integer"
},
"device_type": {
"type": "string"
},
"device_name": {
"type": "string"
}
},
"required": [
"device_number",
"device_type",
"device_name"
]
}
}
}
}
In the next step I'm parsing the Data for your understanding but this is completely avoidable when you are storing the whole data into arrays
For combining or normalizing the results we can either use a compose connector and save to storage account else we can also directly send the same data directly using cosmos db Create or update document connector.
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": {
"Compose": {
"inputs": {
"DevicesInformation": [
{
"DeviceNames": "#{variables('DeviceName')}",
"DeviceNumbers": "#{variables('DeviceNumber')}",
"DeviceTypes": "#{variables('DeviceType')}"
}
]
},
"runAfter": {
"Parse_DeviceName": [
"Succeeded"
],
"Parse_DeviceNumber": [
"Succeeded"
],
"Parse_DeviceType": [
"Succeeded"
]
},
"type": "Compose"
},
"Create_or_update_document_(V3)": {
"inputs": {
"body": {
"DevicesInformation": [
{
"DeviceNames": "#{variables('DeviceName')}",
"DeviceNumbers": "#{variables('DeviceNumber')}",
"DeviceTypes": "#{variables('DeviceType')}"
}
],
"id": "#{guid()}"
},
"host": {
"connection": {
"name": "#parameters('$connections')['documentdb_1']['connectionId']"
}
},
"method": "post",
"path": "/v2/cosmosdb/#{encodeURIComponent('AccountNameFromSettings')}/dbs/#{encodeURIComponent('container2408')}/colls/#{encodeURIComponent('#devices')}/docs"
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"For_each": {
"actions": {
"Append_to_DeviceNumber_variable": {
"inputs": {
"name": "DeviceNumber",
"value": "#items('For_each')?['device_number']"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "#body('Parse_Data')?['devices']",
"runAfter": {
"Initialize_variable_DeviceNumber": [
"Succeeded"
]
},
"type": "Foreach"
},
"For_each_2": {
"actions": {
"Append_to_DeviceType_variable": {
"inputs": {
"name": "DeviceType",
"value": "#items('For_each_2')?['device_type']"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "#body('Parse_Data')?['devices']",
"runAfter": {
"Initialize_variable_DeviceType": [
"Succeeded"
]
},
"type": "Foreach"
},
"For_each_3": {
"actions": {
"Append_to_DeviceName_variable": {
"inputs": {
"name": "DeviceName",
"value": "#items('For_each_3')?['device_name']"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "#body('Parse_Data')?['devices']",
"runAfter": {
"Initialize_variable_DeviceName": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_variable_DeviceName": {
"inputs": {
"variables": [
{
"name": "DeviceName",
"type": "array"
}
]
},
"runAfter": {
"Parse_Data": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_DeviceNumber": {
"inputs": {
"variables": [
{
"name": "DeviceNumber",
"type": "array"
}
]
},
"runAfter": {
"Parse_Data": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_variable_DeviceType": {
"inputs": {
"variables": [
{
"name": "DeviceType",
"type": "array"
}
]
},
"runAfter": {
"Parse_Data": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_Data": {
"inputs": {
"content": "#triggerBody()",
"schema": {
"properties": {
"devices": {
"items": {
"properties": {
"device_name": {
"type": "string"
},
"device_number": {
"type": "integer"
},
"device_type": {
"type": "string"
}
},
"required": [
"device_number",
"device_type",
"device_name"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
},
"runAfter": {},
"type": "ParseJson"
},
"Parse_DeviceName": {
"inputs": {
"content": "#variables('DeviceName')",
"schema": {
"items": {
"type": "string"
},
"type": "array"
}
},
"runAfter": {
"For_each_3": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Parse_DeviceNumber": {
"inputs": {
"content": "#variables('DeviceNumber')",
"schema": {
"items": {
"type": "integer"
},
"type": "array"
}
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Parse_DeviceType": {
"inputs": {
"content": "#variables('DeviceType')",
"schema": {
"items": {
"type": "string"
},
"type": "array"
}
},
"runAfter": {
"For_each_2": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"documentdb_1": {
"connectionId": "/subscriptions/<YOUR_SUBSCRIPTION_ID>/resourceGroups/<YOUR_RESOURCE_GROUP>/providers/Microsoft.Web/connections/documentdb-1",
"connectionName": "documentdb-1",
"id": "/subscriptions/<YOUR_SUBSCRIPTION_ID>/providers/Microsoft.Web/locations/northcentralus/managedApis/documentdb"
}
}
}
}
}

How to display array in Slack Webhook of Azure Logic Apps?

I have LogicApps. It receives property ListOfNames array in HTTP request.
I have difficulty to display correctly in Slack webhook. How to format body?
Current message displayed in Slack:
ListOfNames:
["Name1 \n","Name2\n","Name3\n"]
Target message in slack:
ListOfNames:
Name1
Name2
Name3
I tried Split:
Code: No errors, but don't array items listed correctly in message:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "#split(string(triggerBody()?['ListOfTesNames']),'\\n') ",
"runAfter": {},
"type": "Compose"
},
"HTTP_Webhook": {
"inputs": {
"subscribe": {
"body": {
"blocks": [
{
"text": {
"text": "*[dev] Testing:* \n ListOfTestNames #{outputs('Compose')} ",
"type": "mrkdwn"
},
"type": "section"
},
{
"text": {
"text": "Please check test results from database ",
"type": "mrkdwn"
},
"type": "section"
}
]
},
"method": "POST",
"uri": "https://hooks.slack.com/services/1111111111111111111111"
},
"unsubscribe": {}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"runtimeConfiguration": {
"staticResult": {
"name": "HTTP_Webhook0",
"staticResultOptions": "Disabled"
}
},
"type": "HttpWebhook"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"staticResults": {
"HTTP_Webhook0": {
"outputs": {
"headers": {},
"statusCode": "OK"
},
"status": "Succeeded"
}
},
"triggers": {
"manual": {
"inputs": {
"method": "POST",
"schema": {
"properties": {
"ListOfTestNames": {
"type": "array"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
You can add a compose connector before the webhook connector and use split functionality which gives the right format and then add the output of the compose connector to your webhook connector.
Here is a screenshot for your reference:
Note: Make sure you modify the expression in your split from compose connector as split(triggerBody()?['ListOfFiles'],'\n') to split(triggerBody()?['ListOfFiles'],'\n') because when we write the expression for this, it first takes '\n' as a string and then adds another ''.
Below is the split expression in compose connector:
split(triggerBody()?['ListOfFiles'],'
')
Updated Answer
As we are retrieving an array and passing it to the body of text it is adding the extra characters to it. We have created a new Logic App and added each item that we are retrieving to a variable and finally added that variable to the Webhook body.
Here is the screenshot of the logic app
Here is my code view
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"For_each_2": {
"actions": {
"Append_to_string_variable": {
"inputs": {
"name": "ListOfFilesFinal",
"value": "#{items('For_each_2')},"
},
"runAfter": {},
"type": "AppendToStringVariable"
}
},
"foreach": "#split(item(),',')",
"runAfter": {},
"type": "Foreach"
}
},
"foreach": "#triggerBody()?['ListOfFiles']",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"HTTP_Webhook": {
"inputs": {
"subscribe": {
"body": {
"blocks": [
{
"text": {
"text": "*[dev] Testing: * \n ListOfTestNames : #{variables('ListOfFilesFinal')} ",
"type": "mrkdwn"
},
"type": "section"
},
{
"text": {
"text": "Please check test results from database ",
"type": "mrkdwn"
},
"type": "section"
}
]
},
"method": "POST",
"uri": "#listCallbackUrl()"
},
"unsubscribe": {}
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"runtimeConfiguration": {
"staticResult": {
"name": "HTTP_Webhook0",
"staticResultOptions": "Disabled"
}
},
"type": "HttpWebhook"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "ListOfFilesFinal",
"type": "string"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"staticResults": {
"HTTP_Webhook0": {
"outputs": {
"headers": {},
"statusCode": "OK"
},
"status": "Succeeded"
}
},
"triggers": {
"manual": {
"inputs": {
"method": "POST",
"schema": {
"properties": {
"ListOfFiles": {
"type": "array"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}

Transform property name for JSON of current bitcoin market data

UPDATE - I've amended the original question so that I'm now supplying code that can be used to easily set up a test Azure Logic App in Azure and repeat my scenario.
I have an Azure Logic App to retrieve Crypto market data from a public API and convert it to a CSV table.
I'm performing an API request by using an HTTP action in the workflow. The action does a GET of https://api.wazirx.com/api/v2/trades?market=btcusdt. This results in a response with the following structure:
[{"id":239067645,"market":"btcusdt","price":"61999.0","volume":"0.00005","funds":"3.09995","created_at":"2021-10-25T04:00:38Z","side":null}, {"id":239065383,"market":"btcusdt","price":"61966.0","volume":"0.00021","funds":"13.01286","created_at":"2021-10-25T03:57:25Z","side":null}]
I want to transform the property name of one of the properties from the API response ("market") to a custom property name ("pair"), so that I get the following as the input into the 'Create CSV table' action of my Azure Logic App:
[{"id":239067645,"pair":"btcusdt","price":"61999.0","volume":"0.00005","funds":"3.09995","created_at":"2021-10-25T04:00:38Z","side":null},{"id":239065383,"pair":"btcusdt","price":"61966.0","volume":"0.00021","funds":"13.01286","created_at":"2021-10-25T03:57:25Z","side":null}]
I'm currently using the following workflow and source code. The source code can be directly used to create the Logic App workflow in Azure using the 'consumption' SKU for an Azure Logic App. The workflow is failing at the 'Create CSV table step' as it's getting null from the body of the 'For each'.
How can I adapt my workflow code so that the input into the 'Create CSV table' action is the desired input?
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Create_CSV_table": {
"inputs": {
"format": "CSV",
"from": "#body('For_each')"
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Table"
},
"For_each": {
"actions": {
"Compose": {
"inputs": {
"pair": "#items('For_each')?['market']"
},
"runAfter": {},
"type": "Compose"
}
},
"foreach": "#body('Parse_JSON')",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Foreach"
},
"HTTP": {
"inputs": {
"method": "GET",
"uri": "https://api.wazirx.com/api/v2/trades?market=btcusdt"
},
"runAfter": {},
"type": "Http"
},
"Parse_JSON": {
"inputs": {
"content": "#body('HTTP')",
"schema": {
"items": {
"properties": {
"created_at": {
"type": "string"
},
"funds": {
"type": "string"
},
"id": {
"type": "integer"
},
"market": {
"type": "string"
},
"price": {
"type": "string"
},
"side": {},
"volume": {
"type": "string"
}
},
"required": [
"id",
"market",
"price",
"volume",
"funds",
"created_at",
"side"
],
"type": "object"
},
"type": "array"
}
},
"runAfter": {
"HTTP": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
}
}
Try to use Logic App expression to handle JSON array object as string and then transfer it back to JSON array.
More information for logic app expression: https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference
Please try this logic app code:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "#json(replace(string(body('HTTP')),'\"market\"','\"pair\"'))",
"runAfter": {
"HTTP": [
"Succeeded"
]
},
"type": "Compose"
},
"Create_CSV_table": {
"inputs": {
"format": "CSV",
"from": "#outputs('Compose')"
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "Table"
},
"HTTP": {
"inputs": {
"method": "GET",
"uri": "https://api.wazirx.com/api/v2/trades?market=btcusdt"
},
"runAfter": {},
"type": "Http"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
}
}
This is how I achieved your requirement
Since Create CSV table only takes Array values as input. I have initialized an array variable and Added Append to array variable connector instead of compose then passing the same to Create CSV table.
Here are the logic app screenshots
Here is the workflow
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Create_CSV_table": {
"inputs": {
"format": "CSV",
"from": "#variables('Array')"
},
"runAfter": {},
"type": "Table"
}
},
"foreach": "#variables('Array')",
"runAfter": {
"For_each_2": [
"Succeeded"
]
},
"type": "Foreach"
},
"For_each_2": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "Array",
"value": {
"created_at": "#items('For_each_2')['created_at']",
"funds": "#items('For_each_2')['funds']",
"id": "#items('For_each_2')['id']",
"pair": "#items('For_each_2')['market']",
"price": "#items('For_each_2')['price']",
"side": "#items('For_each_2')['side']",
"volume": "#items('For_each_2')['volume']"
}
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "#body('Parse_JSON')",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"HTTP": {
"inputs": {
"method": "GET",
"uri": "https://api.wazirx.com/api/v2/trades?market=btcusdt"
},
"runAfter": {},
"type": "Http"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "Array",
"type": "array"
}
]
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "#body('HTTP')",
"schema": {
"items": {
"properties": {
"created_at": {
"type": "string"
},
"funds": {
"type": "string"
},
"id": {
"type": "integer"
},
"market": {
"type": "string"
},
"price": {
"type": "string"
},
"side": {},
"volume": {
"type": "string"
}
},
"required": [
"id",
"market",
"price",
"volume",
"funds",
"created_at",
"side"
],
"type": "object"
},
"type": "array"
}
},
"runAfter": {
"HTTP": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {},
"kind": "Http",
"type": "Request"
}
}
}
}

Resources