Concat String And JSON Payload Logic Apps - azure-logic-apps

I need concat string and json and pass into http post body but logic app always convert with back slash
INPUT
json = {"action":"UO","orderdetails":{"OrderID":"12345","PID":"PROD123"}}
OUTPUT REQUIRE
updateorder= {"action":"UO", "orderdetails" { "OrderID":"12345", "PID":"PROD123" } }
If I add updateorder=json below option logic app adding extra "\" in output so request is fail.
updateorder= {\"action\":\"UO\", \"orderdetails\" { \"OrderID\":\"12345\", \"PID":\"PROD123\" } }

You could use a json function to turn it back into json
json(body('Name_of_action'))

Related

Azure Logic App post request always return Bad Request

When call API with Content-Type: as application/x-www-form-urlencoded I always get Bad request(Status code 400).
If I paste same details in Postman it's work without any issue.
I am assuming body must be formatting before sending request!
Update 1
I need to add prefix updateorder=" somehow in front of json payload and Json payload should not convert to text.
if I use concat OR put updateorder= just befor json payload its convert into text as per below and request is invalid.
Using replace from "\"" to "" does not work as well as its again convert json payload into text so request is invalid in this scenraio as well.
I have created logic app with your requirements.
Here is reference image for that:
I call the API in content-type using your code body, I also got same error code.
Case-1:
I tried with
{
"updateOrder": {
"id": "1",
"orderDetails": {
"name": "sam",
"sal": "1000"
}
}
}
It worked successfully for me I got success code 201, and it is not converting into text also.
Here is the reference image:
So, you can try these changes in your BODY After updateorder instead of equals to (=) you should try semi colon (:).
Case-2:
After trying Case-1 still you're getting error once check this and try if you are trying to get any token for authentication and if you are sending credentials in body then use this
Instead of Content-Type use "Accept" (Enter key) and instead of application/x-www-form-URL encoded use "* / *"(Enter value)
Enter Key: Accept
Enter value: */*
Here is the reference image for that:

Adding simple array to JSON payload in Bot Framework Composer

I have a simple problem where I am not able to insert an array in json payload to call graph api to update user profile while using Bot Framework Composer.
Example:
Step1. I created a property Conversation.UpdatedSkills which holds following value
["SharePoint","Dotnet","Analytics"]
Now I want to build JSON object for MS Graph service and working sample payload looks like this.
{
"skills":["SharePoint","Dotnet","Analytics"]
}
Step2. Now to build this JSON dynamically, I need pass body as JSON Object in Send an HTTP Request activity and I have folllowing code to generate payload.
{
"skills":"${conversation.UpdatedSkills}"
}
The output from Step2 looks something like this.
{
“skills”: “[\r\n “SharePoint”,\r\n “Dotnet”,\r\n “Analytics”\r\n]”
}
DESIRED JSON WAS THIS:
{
"skills":["SharePoint","Dotnet","Analytics"]
}
My question is, How do I pass my array from step 1 such a way so that it creates json object that works in service. The object created using step 2 is not the right object that service takes.
Any idea?
I tried different string manipulations but I think this is basic and there has to be something.
Don't use the string interpolation ${ }, but use an expression (=). For your example above, it should be:
{
"skills": "=conversation.UpdatedSkills"
}

How to use / in parameter during rest webservice call from angularjs?

I need to send a value like app/role as parameter through rest webservice url from angularjs
In controller.js
var roleName = 'app/role';
checkRole.check({'roleName': roleName}, function(data){}
In model.js
popModel.factory('checkRole', function ($resource) {
return $resource('./rest/checkRole/:roleName',{roleName:'#roleName'},{
check: {'method':'GET'},
});
});
The rest webservice call in java
#GET
#Path("/checkRole/{roleName}")
#Produces(MediaType.APPLICATION_JSON)
public Response checkRole(#Context HttpServletRequest request, #PathParam("roleName") String roleName);
When i pass it i am getting browser console error as
Bad request response from the server.
For normal parameter values like 'Test', 'Solution', 'Application' etc. If i use with / as a parameter no process is done and i am getting error.
/ is reserved character for GET request. So, you can't use them directly. If you use them, you would get Bad Request Error.
One of the solution can be to encode the URL on client side and decode it on server.
Reference:
Characters allowed in GET parameter
How to handle special characters in url as parameter values?

POST request via requestJS to send Array of JSON Objects and image files

I'm building REST API with NODEjs, using Express routers and Multer middleware to handle multiple body data and files.
My endpoint route 127.0.0.1/api/postData expects: json data with fields, one of which is array of json objects (I'm having nested mongoose schema) and 2 named images (png/jpg).
I need to send Post request via cURL with the following 5-object data structure:
name String
description String
usersArray Array of json objects like: [{"id": "123"}, {"id": "456}]
imgIcon Png/Image providing /path/to/imageIcon.png
imgHeader Png/Image providing /path/to/imageHeader.png
Any idea how to write this request with the help of request.js node http request library ?
Try the following:
request.post({
url:'http://127.0.0.1:7777/api/postData'
, formData: formData
, qsStringifyOptions : {
arrayFormat : 'brackets' // [indices(default)|brackets|repeat]
}
}, function (err, httpResponse, body) {
// do something...
}
I found three options for arrayFormat in https://www.npmjs.com/package/qs (used by https://www.npmjs.com/package/request):
'indices' sends in postbody: (this is the default case)
usersArray%5B0%5D%5Bid%5D=a667cc8f&usersArray%5B1%5D%5Bid%5D=7c7960fb
decoded:
usersArray[0][id]=a667cc8f&usersArray[1][id]=7c7960fb
'brackets' sends in postbody:
usersArray%5B%5D%5Bid%5D=a667cc8f&usersArray%5B%5D%5Bid%5D=7c7960fb
decoded:
usersArray[][id]=a667cc8f&usersArray[][id]=7c7960fb
'repeat' sends in postbody:
usersArray%5Bid%5D=a667cc8f&usersArray%5Bid%5D=7c7960fb
decoded:
usersArray[id]=a667cc8f&usersArray[id]=7c7960fb
these are three different ways to serialize arrays before posting. Basically it depends on the receiving end how these need/can be formatted. In my case it helped to use 'brackets'

Restangular data sent is being splitted

Restangular.one('suppliers', 'me').getList('websites').then(
(data) ->
$scope.websites = data
$scope.websites.patch()
)
I'm just trying this for a quick test.
So the api call on /suppliers/me/websites returns an array but when I try to patch from the Restangular object it sends the data splitted as you can see below.
[{"0":"h","1":"t","2":"t","3":"p","4":":","5":"/","6":"/","7":"w","8":"w","9":"w","10":".","11":"p","12":"f","13":"c","14":"o","15":"n","16":"c","17":"e","18":"p","19":"t","20":".","21":"c","22":"o","23":"m"}]
I'm new to Angular & Restangular , what am I missing ?
Edit : To be clear, I insta patch for the test but normally I modify the websites array by adding / removing.
It looks as if you're returning a string from your service, whereas a valid JSON response is expected by Restangular.
For example:
[{"website": "http://www.example.com"}, {"website": "http://www.domain.com"}]
EDIT: I just noticed that in your question, you say your service returns an array. Double-check what it does return and make sure that it is valid JSON.
EDIT 2: It seems that Restangular expects not only valid JSON, but also JSON formatted as my code sample above is (ie. [{"key": "value"}] and not ["value"].

Resources