I created a logic app to get data when I trigger the logic app URI from external application. I am getting http response as expected into the logic app. As next step I am parsing JSON to get the values for specific items ("e.g. Table1") and pass into a variable. However, I get as null value into the variable
Below is the output of Logic app run where you can see the null value. Unable to find the root cause...
Http Trigger
Body:
{
"headers": {
"Connection": "close",
"Accept": "application/json",
"Accept-Encoding": "br,gzip,deflate",
"Accept-Language": "en-GB,en; q=0.9",
"Host": "prod-56.eastus2.logic.azure.com",
"Referer": "http://localhost:3000/",
"User-Agent": "Mozilla/5.0,(Macintosh; Intel Mac OS X 10_15_7),AppleWebKit/537.36,(KHTML, like Gecko),Chrome/86.0.4240.183,Safari/537.36",
"origin": "http://localhost:3000",
"sec-fetch-site": "cross-site",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"Content-Length": "125",
"Content-Type": "application/json"
},
"body": {
"studyName": "S",
"studyDescription": "DD",
"Table1": "/csdm/table1.csv",
"Table2": "/csdm/table2.csv",
"Table3": "/csdm/table3.csv"
}
}
I had the same problem. The reason was the wrong schema in the Parse JSON step. I also followed the Logic app read property of json stored in variable link. What I did was, I created a variable of the Object type called JSON_content and I placed the 'body' from the Logic App HTTP request trigger as the value. Then I added the Parse JSON action with the Content = JSON_content variable. Important thing was, that I used the input schema from the JSON_Content variable for the Parse JSON schema (using the Use sample payload to generate schema). Then the Dynamic content of the Parse JSON step consisted of JSON names (and values), which were not null finally, which I used further in the Logic App flow.
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 am trying to get the table contents of website Trading Statistics to analyze it. So I used python requests library in order to send a post request as the web page is a form. Using Mozila's Inspect feature I get post data and headers request data and request url. But I get an internal error from server and contents which are in the format of a json file is not shown. Here I included the code and the error. I don't know the reason I get this error and how to change my code to get the true contents.
import requests
import json
url='http://en.ime.co.ir/subsystems/ime/services/home/imedata.asmx/GetAmareMoamelatList'
headers={"Host": "en.ime.co.ir",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0",
"Accept": "text/plain, */*; q=0.01",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json; charset=utf-8",
"X-Requested-With": "XMLHttpRequest",
"Content-Length": "119",
"Origin": "http://en.ime.co.ir",
"Connection": "keep-alive",
"Referer": "http://en.ime.co.ir/spot-trading-statistics.html",
"Cookie": "ASP.NET_SessionId=jh5e35r25o0mmlvvdotwsr2t; SiteBikeLoadBanacer=e565cf8d0d6f8936cafc1b4ba323aebc71ac38c59885ac721a10cf66fd62c302; AmareMoamelatGridTblsaveId.bs.table.columns=[0,1,2,3,4,5,7,8,9,10,11,12,15,17,20,21]"}
data={'fari':'false',
'GregorianFromDate':'2021/12/18',
'GregorianToDate':'2021/12/18',
'MainCat':'0',
'Cat':'0',
'SubCat':'0',
'Producer':'0'}
req=requests.post(url, verify=True,data=data,headers=headers)
print(req):
"<Response [500]>"
print(req.content):
"b'The page cannot be displayed because an internal server error has occurred.'"
The problem here is that the server only accepts valid JSON data.
Here's what you can do.
import requests
import json
url = "https://en.ime.co.ir/subsystems/ime/services/home/imedata.asmx/GetAmareMoamelatList"
# Minimal headers will do
headers = {
"accept": "text/plain, */*; q=0.01",
"accept-language": "en-US,en;q=0.9",
"content-type": "application/json; charset=UTF-8"
}
# Setup your body data here
payload = {
"Language": "1",
"fari": "false",
"GregorianFromDate": "2021/12/18",
"GregorianToDate": "2021/12/18",
"MainCat": "0",
"Cat": "0",
"SubCat": "0",
"Producer": "0"
}
# Convert the dict into a json string
payload_json = json.dumps(payload)
req = requests.post(url, verify=True, data=payload_json, headers=headers)
print(req.content)
Explanation
Why minimal headers will do the job fine?
A: Thanks to urllib3, usually Requests will auto config the headers for you, but not limited to
accept
accept-encoding
connection
content-length
host
user-agent
In this case, some headers aren't really that important because you're sending your HTTP requests to an API endpoint.
The header you need to care here is content-type. Setting it wrongly will cause problems.
To ensure that the destination server understood that you're trying to send a JSON body not a RAW body. You need to set the header "content-type": "application/json; charset=UTF-8"
Why was converting dict to json object string necessary?
A: You must encode your dict into a valid json string so that the server can process the data.
Here, let's see how the data looks like.
import json
#################
""" The server will definitely accept this. """
data = {
"Work" : "true",
"Sleep" : "false"
}
# Convert python dict into JSON string
data_json = json.dumps(data)
# It prints '{"Work": "true", "Sleep": "false"}'
print(repr(data_json))
#################
""" Most server should accept JSON string like this too, it's still valid. """
data = '{ \
"Work" : "true", \
"Sleep" : "false" \
}'
# It prints '{ "Work" : "true", "Sleep" : "false" }'
print(repr(data))
#################
""" The server will NOT accept this, this ISN'T valid. """
data = {
"Work" : "true",
"Sleep" : "false"
}
# It prints {'Work': 'true', 'Sleep': 'false'}
# Notice that it's missing quotation mark at start and end.
print(repr(data))
I have an azure function which works well when I call it from postman . I am trying to invoke the same from logic app as when an HTTP request is received. However, I am unable to pass raw content in the APIM as it does not give me an option for the same. It let me add only the subscription key.
My Azure APIM accepts file name, subscription key only.
Any help in this regard is much appreciated.
Postman : (I have added Headers - Content-Type, Accept: using )
Headers:
Content-Type :
Accept:
Ocp-Apim-Subscription-Key
Body:
{
"name": "olaf"
}
Azure Logic App: (Using Peek Code);
{
"inputs": {
"method": "post",
"headers": {
"Accept": "application/json",
"Content-Type": "text/csv"
},
"pathTemplate": {
"template": "/scg-liquidTransformer-functionApp/liquidtransformer/{liquidtransformfilename}",
"parameters": {
"liquidtransformfilename": "#{encodeURIComponent('xmlsample.liquid')}"
}
},
"api": {
"id": "/subscriptions/XXXXXXXXXXXXXXXXXXXXX/resourceGroups/scg-mel-dev-arg-liquidtransformer/providers/Microsoft.ApiManagement/service/scg-liquidTransformer-functionApp-apimservice/apis/scg-liquidtransformer-functionapp"
},
"subscriptionKey": "XXXXXXXXXXXXXXXXXXXXXXXX"
}
}
I need to send body {} as a parameter input in the azure functionenter image description here.
Thanks,
Paul.
enter image description here
You need to do configuration in your APIM, please refer to the steps below:
1. Go to your APIM, find your api and click the "pencil" icon.
2. In next page, click "Request" tab and click "Add representation" to add "application/json".
3. Then click "New definition"
4. Input the json sample of request body, it will generate the schema automatically in "Payload" box.
5. Click "Save", then go back to your logic app and add the APIM api. You can find there is a field "name" for you to choose.
I've got a really simple Logic app:
HTTP request (works as end-point web hook for Slack)
Send request from Slack (URI) to Service Bus queue
I haven't made any changes in Logic App but Send message action suddenly started reporting this error:
Decoding as string is not supported for content envelope of type
'application/x-www-form-urlencoded'.
Send message is defined like that:
"Send_message": {
"inputs": {
"body": {
"Label": "#{triggerBody()}"
},
...
I see only difference in request outputs:
BEFORE
Headers
{
"Accept": "*/*",
"User-Agent": "Slackbot,1.0,(+https://api.slack.com/robots)",
"Content-Type": "application/x-www-form-urlencoded"
...
}
Body
{
"$content-type": "application/x-www-form-urlencoded",
"$content": "dG9r..."
}
NOW
Headers
{
"Accept": "*/*",
"User-Agent": "Slackbot,1.0,(+https://api.slack.com/robots)",
"Content-Type": "application/x-www-form-urlencoded"
...
}
Body
{
"$content-type": "application/x-www-form-urlencoded",
"$content": "dG9r...",
"$formdata": [
{
"key": "token",
"value": "..."
},
{
"key": "team_id",
"value": "..."
},
{
"key": "trigger_word",
"value": "!"
},
...
]
}
$formdata is now a part of the output of Request as JSON array consisting of all query parameters.
Does anyone have any ideas? I would greatly appreciate any help to make it work again.
Edit: West Europe fixed and working
Yes, in the effort to have native support for x-www-form-urlencoded data in the runtime there was a bug that was recently released. We are rolling back and patching now. Can you send me an email so we can target your region for a fix, and share a workaround? Apologies in advance - as a general rule we never want to ship anything that will break existing logic apps. In this case adding some new metadata around form-data no longer allowed people to stringify x-www-form-urlencoded data (which is what you are doing here).
I have a small logic app which is meant to fetch data from somewhere and store it on blob. I then would like to send the URL to all devices via push notification. I wish to send the URL as a raw notification, so on the app/background task, i can do some processiong.
The problem is when i use logic app to create a http POST request to send a notification, i get a 400 error. The same header with authentication and etc, with the payload and URL works fine on a POSTMAN or REST API CLIENT. THe following are the inputs and outputs. Please help. Brain dead already.
This is the input.
{
"uri": "https://xxoppoc.servicebus.windows.net/xxopPOC/messages/?api-version=2015-01",
"method": "POST",
"headers": {
"Authorization": "SharedAccessSignature sr=sb%3a%2f%2fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxt%2f&sig=qEnxxxxxxxxxxxx&skn=DefaultFullSharedAccessSignature",
"Content-Type": "application/octet-stream",
"ServiceBusNotification-Format": "windows",
"ServiceBusNotification-Tags": "MyTag",
"X-WNS-Type": "wns/raw"
},
"body": "Some Raw Information. Hello World"
}
This is the output:
{
"statusCode": 400,
"headers": {
"transfer-Encoding": "chunked",
"date": "Wed, 30 Mar 2016 14:10:41 GMT",
"server": "Microsoft-HTTPAPI/2.0"
},
"body": {
"$content-type": "application/xml; charset=utf-8",
"$content": "PEVycm9yPjxDb2RlPjQwMDwvQ29kZT48RGV0YWlsPlRoZSBjb250ZW50IHR5cGUgZm9yIGEgJ3ducy9yYXcnIG5vdGlmaWNhdGlvbiBtdXN0IGJlICdhcHBsaWNhdGlvbi9vY3RldC1zdHJlYW0nLlRyYWNraW5nSWQ6NTNmNjhlMGItNDc1MC00ZDRkLWJiNTAtMzJjNTBmOGIyNDk1X0czLFRpbWVTdGFtcDozLzMwLzIwMTYgMjoxMDo0MSBQTTwvRGV0YWlsPjwvRXJyb3I+"
}
}
Let me mention again, I got the authentication correct as it works on Advanced REST Client on chrome and POSTMAN. The above logic app also works if i send a wns/toast notification with xml as its content-type. I however need it to be a wns/raw notification. Please help. Thank you
EDIT/PROGRESS
Thanks to MichaelB, We figured out that the content-type is being modified. I sent the request to a different URL to look at the header. The following was observed:
Content-Type: application/octet-stream; charset=utf-8
If I use the above Content-Type on POSTMAN. It actually fails as well. So this could be 1 step. Why is Azure Logic Apps adding charset-utf-8 to the end of my content type. Can I stop it?