Calling multipart/form-data REST service in Azure Logic Apps - azure

I have made a workflow using Http Listener and Http actions in Azure Logic Apps. Listener is to catch POST request and Http action has details of my api which is hosted over azure web app. Request is multipart/form-data type and posts a file along with 3 other string values.
My problems are
If I'm explicitly setting content type header as multipart/form-data in Http action, it is not passing any boundary to api controller and my api is giving error "request was rejected because no multipart boundary was found".
If I'm trying to pass #triggers().outputs.body.ContentType as header of my http action, I'm getting this error:
{"code":"InvalidTemplate","message":"Unable to process template
language expressions in action 'http' inputs at line '1' and column
'11': 'Error converting value \"multipart/form-data;
boundary=----WebKitFormBoundaryi3knGy6dh92BdKdr\" to type
'Microsoft.WindowsAzure.ResourceStack.Common.Collections.InsensitiveDictionary`1[System.String]'.
Path 'headers'.'."}
Please help, how can I pass content type and boundary both to my api using Http action?

The headers object in the Logic app definition is a JSON object with keys and values. Specifically, if you want to pass the content-type header like above your object definition in the code view would look like:
"MyAction" : {
"type" : "http",
"inputs" : {
"headers" : {
"Content-type" : "#triggerBody().ContentType"
},
"body" : … rest of properties here …
Hopefully this is why your API isn't getting the boundary either.

Related

How to submit "form-data" in ADF "Web" activity POST call

I am trying to move data from a RESTFul API running on my on-prem application to ADB with ADF. I have installed self-paced IR in my private network to run the activity/pipeline. Now in one of my
API requires form-data to submit in POST call. Equivalent Postman looks like below
How to perform the same in ADF (As I will be running in self-paced IR dataflow is not applicable)? I am trying with "Web" Activity but dont know how to pass form data in it.
You are unable to pass form data in your ADF's Web Activity as you have selected incorrect method in Web activity:
You can select POST method from the dropdown as such:
After this you will get a place to add request body.
Also to get same effect of selecting form-data in postman, you can set 2 cookies as:
Content-Length: length of your request body in bytes
Content-Type: multipart/form-data; boundary= some value as boundary
Content-Type header reference

How to use "#odata.id" in JSON body when using the HTTP action in Azure Logic Apps?

I'm using Azure Logic Apps to call out to the Microsoft Graph API using the HTTP - HTTP action. For this API I need to execute a POST request with the following body:
{
"#odata.id": "<guid>"
}
When I try to save the Logic App, this error shows:
Failed to save logic app <redacted>. The template validation failed: 'The template action '<redacted>' at line '1' and column '144589' is not valid: "Unable to parse template language expression 'odata.id': expected token 'LeftParenthesis' and actual 'Dot'.".'.
How can I use this attribute in my JSON payload?
EDIT: as requested, a screenshot of the part of the Logic App that generates the error on Saving.
From this article:
Logic Apps workflow definitions with the Workflow Definition Language schema
If you have a literal string that starts with the # character, prefix the # character with another # character as an escape character: ##
So in your case, this should work:
{
"##odata.id": "your value here"
}

azure logic app & http step response

I have 2 HTTP actions, one after another in a logic app, how do I read the response from a previous HTTP action in the second HTTP action?
First HTTP call (REST) returns a response in JSON format -
{
"authResult": {
"isPasswordExpired": true,
"authToken": "cxxcxcxc",
"message": "Login Successful"
}
}
I want to send authtoken from the result in second http action as authorization header.
As Derke Li mentioned that we could use exression or Parse Json to do that. I also do a demo about how to use the Parse JSON action.
1.Add the Parse Json action after the first Http action
2.Add the parse content and click on the button "Use sample payload to generate schema" and that will pop a new window. Paste in your "authResult" json. As seen in the below image.
3.Then we could pick the token from the dynamic content.
4.We could check the result.
There are two ways you can do this.
Use expression to directly reference the property. #body('NameOfFirstHTTPAction')?['authResult']?'[authToken]
Add a "Parse JSON" action in between the two HTTP action, and provide a sample response of the first HTTP action to generate a schema. Then, in the second HTTP action, you will see authToken as a token from the dynamic content picker for you to reference.

Set Web properties of a site using SharePoint rest api

From Microsoft SharePoint documentation i can get web properties of a site using this request: "http:///_api/web/" (refer: https://msdn.microsoft.com/en-us/library/office/dn499819.aspx).
There are some properties which are R/W.
When i try to create these R/W properties i get 200 OK response but the properties value remain unchanged.
eg. property_name - SaveSiteAsTemplateEnabled.
initially it's value is True
initial get response:
{
"odata.metadata": "https://druvainternal.sharepoint.com/sites/testsharepoint/subsite1copy/_api/$metadata#Edm.Boolean",
"value": true
}
Then when i try to change its value using post call or merge call.
request:
"post"
endpoint - _api/web/SaveSiteAsTemplateEnabled
body = {"value":False}
The response i get is:
{"odata.metadata":"https://druvainternal.sharepoint.com/sites/testsharepoint/subsite1copy/_api/$metadata#Edm.Boolean","value":true
}
whose value is still True.
Am i sending the right request? In documentations it's not mentioned about how to set these properties.
Since Web.SaveSiteAsTemplateEnabled property is a property of Web class, you need to construct a request to update a Web resource for that matter.
The following example shows how to update SPWeb.SaveSiteAsTemplateEnabled property:
Endpoint Url: [web url]/api/web
Method: POST
Headers:
"X-HTTP-Method":"MERGE"
"If-Match":"*"
Data:
{"SaveSiteAsTemplateEnabled":false,"__metadata":{"type":"SP.Web"}}

Logic App Send Message error with JSON

I'm using Logic App to send a message to a service bus on Azure. The logic app starts with a HTTP Request for the trigger which contains a JSON payload in the body. The 'Body' of the request is set as the Content of the Send Message action. Since the payload is JSON when posting I set the Content-Type to application/json. This generates an error on the Send Message action;
{"code":"InvalidTemplate","message":"Unable to process template language expressions in action 'Send_message.' inputs at line '1' and column '1221': 'The template language function 'encodeBase64' expects its parameter to be a string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#encodeBase64 for usage details.'."}
So tried changing the Content-Type to text/plain and it works? Is this a bug or should convert the JSON to a text value somehow before using it in the Send Message action?
Sending a message to service bus requires the message content to be base64 encoded. Since your content is a JSON, you would need to stringify it explicitly prior to encoding, i.e. use #encodeBase64(string(jsonContent))
Changing the content type to text/plain has the same effect, since in that case the content is treated as a string to begin with.

Resources