Get value from json in LogicApp - azure

Rephrasing question entirely, as first attempt was unclear.
In my logic app I am reading a .json from blob which contains:
{
"alpha": {
"url": "https://linktoalpha.com",
"meta": "This logic app does job aaaa"
},
"beta": {
"url": "https://linktobeta.com",
"meta": "This logic app does job beta"
},
"theta": {
"url": "https://linktotheta.com",
"meta": "This logic app does job theta"
}
}
I'm triggering the logic app with a http post which contains in the body:
{ "logicappname": "beta" }
But the value for 'logicappname' could be alpha, beta or theta. I now need to set a variable which contains the url value for 'beta'. How can this be achieved without jsonpath support?
I am already json parsing the file contents from the blob and this IS giving me the tokens... but I cannot see how to select the value I need. Would appreciate any assistance, thank you.

For your requirement, I think just use "Parse JSON" action to do it. Please refer to the steps below:
1. I upload a file testJson.json to my blob storage, then get it and parse it in my logic app.
2. We can see there are three url in the screenshot below. As you want to get the url value for beta, it is the second one, so we can choose the second one.
If you want to get the url value by the param logicappname from the "When a HTTP request is received" trigger, you can use a expression when you create the result variable.
In my screenshot, the expression is:
body('Parse_JSON')?[triggerBody()?['logicappname']]?['url']
As the description of your question is a little unclear and I'm confused about the meaning of I am already json parsing the file contents from the blob and this IS giving me the tokens, why is "tokens" involved in it ? And in the original question it seems you want to do it by jsonpath but in the latest description you said without jsonpath ? So if I misunderstand your question, please let me know. Thanks.

Not sure if I understand your question. But I believe you can use Pars Json action after the http trigger.
With this you will get a control over the incoming JSON message and you can choose the 'URL' value as a dynamic content in the subsequent actions.
Let me know if my understanding about your question is wrong.

Related

How to get local time when Azure Data Factory Linked Service parses Timezone offset to UTC

I have a data factory pipeline that receives JSON files from an Azure Blob storage.
These files have the following structure:
{
"Time": {
"UTC": {
"Sent": "2020-09-01T11:45:00.0Z"
}
},
"LocalTime": {
"Original": {
"Sent": "2020-09-01T13:45:00+02:00"
}
}
}
When the lookup data activity gets the file from the blob it parses the localtime to UTC. I would like to ignore the offset and just grab the datetime as is.
How do I go about doing this?
According your comment:
We decided to solve this by stripping the offset with regex while
moving the folder to the blob using a logic app.
We are glad to hear that you found a solution to solve it. I help you post it as answer, others can ref this way. This also can be beneficial to other community members. Thank you!
Thanks for posting the ask , as definitely I had never thought it would behave the way its did . For clarity of others when we try
#activity('Lookup1').output.firstRow.LocalTime.Original.Sent will give the output as "2020-09-01T11:45Z" and not "2020-09-01T13:45:00+02:00".
This is what I tried while creating the Dataset , create it as if the file is delimited and not JSON ( this is what i think you are doing ) and the intend is to read the content of the whole file as string . Please make the adjustment to the Column& row limiter as shown below
Now you can use the expression ( i hate to hard code , but then we can suyre make it dynamic )
#substring(string(activity('Lookup1').output.firstRow),187,16)
Output
{
"name": "Datepart",
"value": "2020-09-01T13:45"
}
HTH

How to use values passed in HTTP Request in Logic Apps / Assign Values to Logic App Parameters Dynamically

I am trying to make a generic Logic App(LA) to do some processing on some files. Calling the Logic App from ADF and able to pass the correct File Names. However I am not able to use/assign values passed to the Logic App to the parameters defined in the LA. What am I Missing ? Please see the screenshot.
-Thanks
Sample Execution to show the names are passed properly.
As far as I know, we can't assign PRM_FileName from the body of the request to one parameter. But we can use expression to get the value of PRM_FileName.
The expression should be triggerBody()?['PRM_FileName']. You can also assign PRM_FileName to a variable (for example named var1) and you can use the var1 in your next actions but not use the expression(shown as below screenshot).
============================Update===========================
Below is my logic app:
I did everything what you mentioned in your 3 steps except I put the PRM_FileName in the body of the request but not appending it at the end of url.
============================Update 2===========================
Please use same schema with mine:
{
"type": "object",
"properties": {
"PRM_FileName": {
"type": "string"
}
}
}
And then select the PRM_FileName into the variable directly(shown as below screenshot).
The expression should be triggerBody()?['PRM_FileName'], but in your screenshot the expression is triggerOutputs()['queries']['PRM_FileName'].

Azure Logic App - How to upload file to Azure Blob Storage from byte array

I am trying to create a Logic App that is triggered by an HttpRequest that contains as payload a JSON request. Inside of this JSON, one field contains the file:
{
"EntityId": "45643",
"SharedGuid": "00000000-0000-0000-0000-000000000000",
"Document": {
"DocumentName": "MyFileName.pdf",
"File": "JVBERi0xLjMKJfv8/f4KMS.....lJUVPRg=="
}}
This "file" content is being generated by the customer application by using the following C# function: File.ReadAllBytes("local path here").
I managed to upload the byte array to blob storage. But the file is not valid once it is uploaded in the Blob Storage.
I tried different file contents for the file in the JSON schema definition as: string, binary, application/octet-stream.
Any help will be appreciated.
Did you do the operation to convert the byte to Base64String in your httprequest code, just like the code below:
byte[] b = File.ReadAllBytes(#"filepath");
string s = Convert.ToBase64String(b);
According to the file content you provided, it seems you have convert it to base64string as above, so I provide the solution below:
For this requirement, you can just parse the response data as string(do not need to use "binary" in schema) in your "Parse JSON" action and then use base64ToBinary() method in the "Create blob" action, please refer to the screenshot shown as below:
The expression in "Blob content" is:
base64ToBinary(body('Parse_JSON')?['Document']?['File'])
Hope it helps~
If still have any problem, please feel free to let me know.

Multiple output text value setting in watson conversation

I have following node in the conversation. I want to raise the action and based on that need to call the API. In success scenario, will show the output.text[0] and error scenario getting from output.text[1]
{
"output": {
"text": {
"values": [
"I want to get this with success scenario",
"I want to get this with error scenario"
],
"selection_policy": "sequential"
},
"action": "MyAction"
}
}
But when I am accessing this conversation node in node.js, it will always give 1st value, i.e. 'I want to get this with success scenario' It will never give output like 'I want to get this with error scenario' .
How to resolve this issue ?
This is really complicated to answer because depends your Business role inside your Chatbot.
But, if you wanna answer one message according to the Condition...
You can see in your output the selection_policy is sequential, in the other words, first will show the 1st phrase, and just if the condition access again by the user, will show the second message.
"The order in which values in the array are returned depends on the attribute selection_policy."
The better form to solve this is to create two conditions inside the Node flow for each phrase.
For example first condition flow:
if bot recognizes successScenario response "I want to get this with success scenario"
In another second condition flow:
if bot recognizes errorScenario response "I want to get this with error scenario"
And your app with Nodejs will get the value according the condition.
See the official documentation about this here, search about selection_policy.
I have resolved that issue with the following way.
{
"output": {
"text": {
"values": [
{
"successMsg": "success Message",
"errorMsg": "error message"
}
]
},
"action": "MyAction"
}
}
Reason for not going for new node, because with this action, I need to create the API and based on the API call success and fail display this message to the user. Then it will help to save one roundtrip because no need to send results status again to conversation service, it will identify the what to present to user based on the this node itself.

Azure Logic Apps - Get Blob Content - Setting Content type

The Azure Logic Apps action "Get Blob Content" doesn't allow us to set the return content-type.
By default, it returns the blob as binary (octet-stream), which is useless in most cases. In general it would be useful to have text (e.g. json, xml, csv, etc.).
I know the action is in beta. Is that on the short term roadmap?
Workaround I found is to use the Logic App expression base64ToString.
For instance, create an action of type "Compose" (Data Operations group) with the following code:
"ComposeToString": {
"inputs": "#base64ToString(body('Get_blob_content').$content)",
"runAfter": {
"Get_blob_content": [
"Succeeded"
]
},
"type": "Compose"
}
The output will be the text representation of the blob.
So I had a blob sitting in az storage with json in it.
Fetching blob got me a octet back that was pretty useless, as I was unable to parse it.
BadRequest. The property 'content' must be of type JSON in the
'ParseJson' action inputs, but was of type 'application/octet-stream'.
So I setup an "Initialize variable", content type of string, pointing to GetBlobContent->File Content. The base64 conversion occurs under the hood and I am now able to access my json via the variable.
No code required.
JSON OUTPUT...
FLOW, NO CODE...
Enjoy! Healy in Tampa...
After fiddling much with Logic Apps, I finally understood what was going on.
The JSON output from the HTTP request is the JSON representation of an XML payload:
{
"$content-type": "application/xml",
"$content": "77u/PD94bWwgdm..."
}
So we can decode it, but it is useless really. That is an XML object for Logic App. We can apply xml functions to it, such as xpath.
You would need to know the content-type.
Use #{body('Get_blob_content')['$content']} to get the content part alone.
Is enough to "Initialize Variable" and take the output of the Get Blob Content as type "String". This will automatically parse the content:

Resources