How do I extract the content of my request that's been received inside of the logic app?
I've got a regular http-triggered logic app, like so:
I'm sending it a POST request through postman like so:
{
"$content-type": "application/octet-stream",
"$content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><cases><file-path>yes</file-path></cases>"
}
I'm attempting to extract the $content payload:
"#{string(xml(string(triggerBody()?['content'])))}"
The issue I am getting is:
How do I extract the content of my request that's been received inside of the logic app?
Here's the entire initialize variable step:
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "contentOfRequest",
"type": "String",
"value": "#{string(xml(string(triggerBody()?['content'])))}"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
}
Cause the request body is string, it doesn't support select property. so you need parse it Json format firstly, then you will be able to select $content.
About how to get the Json Schema, just click the Use sample payload to generate schema in the Parse Json action and paste your Json data, then click the done.
And then extract the $content value with body('Parse_JSON')?['$content'], in this way you will get the content value.
Related
I have out form one of the tasks in Logic App:
{
"headers": {
"Connection": "close",
"Content-Type": "application/json"
},
"body": {
"systemAlertId": "....",
"endTimeUtc": null,
"entities": [
{
"$id": "us_1",
"hostName": "...",
"azureID": "someID",
"type": "host"
},
{
"$id": "us_2",
"address": "fwdedwedwedwed",
"location": {
"countryCode": "",
},
"type": "ip"
},
],
}
}
I need initialize some variable named resourceID that contains value someID which is read from above example.
Value someID will always be found in the first member of Entities array, in that case I guess need to use function first
Any idea how expression of Initial variable should look?
Thanks
Considering the mentioned data you are receiving from Http trigger, I have used Parse JSON in order to get the inner values of the mentioned JSON. Here is how you can do it.
and now you can initialize the resourceID using 'Initialise variable' connector and set its value to azureID as per your requirement.
Have a look at the Parse JSON action.
To reference or access properties in JavaScript Object Notation (JSON) content, you can create user-friendly fields or tokens for those properties by using the Parse JSON action. That way, you can select those properties from the dynamic content list when you specify inputs for your logic app. For this action, you can either provide a JSON schema or generate a JSON schema from your sample JSON content or payload.
With the information in the JSON available in an object, you can more easily access it.
I wanted to know if its possible to perform a file upload request to azure logic app's HTTP listener?
I am not looking for built-in HTTP trigger which makes an HTTP call to the specified URL OR built-in HTTP action which makes an HTTP call to the specified URL
One of the workarounds is through postman. Here is my logic app for your reference
postman request :-
Here is the output :-
Yes, it's possible for an Azure Logic App to receive files via an HTTP POST request. Here is the request body JSON schema to use in the Logic App:
{
"properties": {
"formdata": {
"items": {
"properties": {
"key": {
"type": "string"
},
"type": {
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"key",
"value",
"type"
],
"type": "object"
},
"type": "array"
},
"mode": {
"type": "string"
}
},
"type": "object"
}
The Python script below will send a request to the Logic App, including a dictionary of parameters and a separate dictionary associating each filename with its contents.
import requests
import pathlib
attachments = ["path/to/first_file.txt", "path/to/second_file.txt"] # Insert file paths
logic_app_url = "paste_logic_app_url_here" # Insert URL in quote marks
file_dict = {}
for filepath in attachments:
file_dict[pathlib.Path(filepath).name] = open(filepath, 'rb')
payload = {"first_key": "first_val"} # Extra fields to include in your request
response = requests.post(logic_app_url, headers=None, data=payload,
files=file_dict)
I've run the request above, and it works. The request is received and processed by the Logic App. However, I haven't yet figured out how to parse the individual attachments in the Azure Logic App GUI. I think this may require a For Each loop as explained in Microsoft docs. I hope this helps!
In Azure logic app how to convert xml to json or json to xml based on the requirement.
The data is dynamic i,e they can be in any format. And xpath expression is required to get the required node.
The functions that you said are the correct ones, here is an example to get an xpath value from an input converted in xml:
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "xpathValue",
"type": "String",
"value": "#xpath(xml(body('Get_blob_content_using_path')), 'string(/*[local-name()=\"Part\" and namespace-uri()=\"\"])')"
}
]
},
I am a newbie to azure logic app. My aim is to send some variables to logic app(via java service code, which in turn invokes the request trigger with the provided POST URL as REST API) and obtain response as JSON.
Currently i have created a request trigger and the JSON schema looks as follows:-
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {},
"id": "http://example.com/example.json",
"properties": {
"CustomerName": {
"type": "string"
},
"InvoiceFee": {
"type": "integer"
},
"InvoiceNo": {
"type": "integer"
}
},
"required": [
"CustomerName",
"InvoiceFee",
"InvoiceNo"
],
"type": "object"
}
From the request trigger, i am directing to response action and the following to be returned as JSON response.
{
"CustomerName": #{triggerBody()['CustomerName']},
"InvoiceFee": #{triggerBody()['InvoiceFee']},
"InvoiceNo": #{triggerBody()['InvoiceNo']}
}
Screenshot below:-
enter image description here
Could you please provide me some reference links of how to access logic app from java service?
I am don't know regarding how to pass the custom created object such that the parameters of the object maps to "CustomerName", "InvoiceNo", "InvoiceFee" properties.
My created java service code is as follows:-
InvoiceDTO invoiceDTOObject2 = new InvoiceDTO();
invoiceDTOObject2.setCustomerName("Sakthivel");
invoiceDTOObject2.setInvoiceNo(123);
invoiceDTOObject2.setInvoiceFee(4000);
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("URL TO PROVID").resolveTemplate("properties", invoiceDTOObject2);
Response response = target.request().get();
String jsonResponse = response.readEntity(String.class);
System.out.println("JSON Reponse "+jsonResponse);
Looking at your code
Response response = target.request().get();
You are doing a GET-operation. Your Logic App HTTP Trigger would require you to perform a POST-operation using your InvoiceDTO-entity as body (serialized as JSON).
So should look something like this:
Response response = target.request().post( InvoiceDTO.entity(invoiceDTOObject2, MediaType.APPLICATION_JSON));
Not sure if it's 100% correct, my java is a little rusty, but that's the general idea.
I have a simple Azure Logic App with the following components:
Recurrence
HTTP Get from HTTPS url
I've tried to configure the next component to save the HTTP response body to OneDrive with OneDrive Connector configured as follows:
FilePath: ApiTest/test.json
Content: #{body('http')}
Content Transfer Encoding: None
This gives the following error:
{"code":"InvalidTemplate","message":"Unable to process template language expressions in action 'microsoftonedriveconnector' inputs at line '1' and column '11': 'Template language expression cannot be evaluated: one of string interpolation segment value has unsupported type 'Object'. Please convert the value to string using the 'string()' function.'."}
If I then use #{string(body('http'))} I get:
{"code":"InvalidTemplate","message":"Unable to process template language expressions in action 'microsoftonedriveconnector' inputs at line '1' and column '11': 'The template language function 'string' was invoked with an invalid parameter. The value cannot be converted to the target type.'."}
How can I use the body of HTTP Connector and save it to One Drive?
I don't have an answer, but I am wrestling with this very issue right now. I will post if I find a solution and would be very interested in case any one else finds a solution. I do find one thing interesting. There is a header and body option on the consuming end of my Http Connector which works when it runs. The error (as the above poster notes) occurs when passing that value to the next card. But, when I look at the output (link) on the run tab, I see a json value for the header and for the body. Does this need to be wrapped in a json parser?
This works for me just fine and generated the file in the /random/test.txt folder, however I believe the problem in your case is that you are downloading a JSON file which is causing it to be interpreted as an object by the engine.
I'll follow up with the team and maybe we need a "ToJson" call, or a way to "Passthrough", or make "String" more "flexible" (though that could be weird).
"fileContent": {
"Content": "#{body('http')}",
"ContentTransferEncoding": "None"
},
Actions in code view looks like:
"http": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "http://www.carlosag.net/"
},
"conditions": []
},
"microsoftonedriveconnector": {
"type": "ApiApp",
"inputs": {
"apiVersion": "2015-01-14",
"host": {
"id": "/subscriptions/xxx/resourceGroups/zzz/providers/Microsoft.AppService/apiApps/MicrosoftOneDriveConnector",
"gateway": "https://yyy.azurewebsites.net"
},
"operation": "UploadFile",
"parameters": {
"filePath": "random/test.json",
"fileContent": {
"Content": "#{body('http')}",
"ContentTransferEncoding": "None"
},
"overwrite": true
},
"authentication": {
"type": "Raw",
"scheme": "Zumo",
"parameter": "#parameters('/subscriptions/...')"
}
},
You should try "#body('http')". I believe this will work. "#{body('http')}" is a form of string interpolation: expected output value is string and not a JSON.
I initialized a String variable 'Content' and set the value to the body of the HTTP.
#{body('HTTP')}
And then I convert the String to JSON to read the desired node with an expression.
json(variables('Content'))?['ExcelFile']
I went a step further and base64 decoded to binary in order to upload to Sharepoint. Going to OneDrive would likely be the same.
base64ToBinary(json(variables('Content'))?['ExcelFile'])