String[] Input for REST Calls - json

I am new to REST Programming. I have a requirement to automate the working of an appliance which requires me to login to the appliance, use the auth token and perform other rest calls on the appliance subsequently. I have been able to login and perform routine GET calls and parse the output of the REST calls.
Now, the specification of the REST call that I am unable to understand is as following:
Call: PUT /rest/os-deployment-build-plans/<osbp-id>/run
Input: Std headers, String[] serverIds
Basically, this call is used to run a build plan against a server, I am unable to figure out how to give the String array as input. All the calls in this appliance take only JSON as input and accept only JSON types. Any pointers as to what this might mean? Is it a JSON string? Is it an array of JSON objects?

Related

Force an Azure Logic App to recognise a text string as a token and replace it with the token's value at run time

Details of the Azure Logic App:
Triggered by an incoming webhook
The triggering webhook contains a number of json name/value pairs, such as "variable1":"05-05-2021" and "variable2":"A text string"
The first step of the Logic App is to retrieve a json object from an external source.
The retrieved json object contains string values, some of which include text that match tokens that exist in the Logic App e.g. "triggerBody()?['variable1']" and "triggerBody()?['variable2']"
The Logic App then posts the json object to another external source.
Is there any way to make the logic app recognise these string values as tokens and replace the string value with the value of the token?
For example
If the retrieved json object contains the string "The date today is triggerBody()?['variable1']"
And the triggering Webhook provided the value of variable1 as "05-05-2021"
Is there a method I can use to force the Logic App to recognise the relevant string in the json object as a token and replace it with the token's value, so that the string in the json object becomes 'The date today is 05-05-2021"
I've tried adding steps in the app to convert the json object to a string and then back into an object, in the hope that this would force the Logic App to recognise the text triggerBody()?['variable1'] as a token and replace it with the token's value, but that's not working.
Any guidance would be greatly appreciated!
Unfortunately, this isn't possible. The tokens are replaced just once. The alternatives are
Use the replace function to do this. Though this will not work dynamically and should be OK with a small list of known variables.
You could use the inline function to replace tokens with values. Note that this requires an integration account.
Originally answered on Microsoft Q&A

NodeJS Joi Vlidation - How to return JSON response instead of a string?

Recently, Iv'e been using the Joi validation library in-order to validate the data which comes in from a request (building a RESTful API).
I was using the .label() method to generate a string response and send it back to the user, but I couldn't find any way to send a JSON response back to the user?
Tried sending a premade JSON inside the string, searching the documentation and the internet of course - couldn't find any mention of it.
Current code example:
textField: Joi.string().required().max(4).label("This example field didn't pass the testing phase, please try again)"),
Any ideas?
If you need to send data in case of error,try .error() method. you can pass error in it.

Parsing JSON with Node Red with telegram bot

I am trying to get JSON working with my telegram bot which I have already created. I can the bot send and receive message in the debug screen from telegram in Node Red.
I want to take the return api message from telegram and then parse it out to eventually have it do something like turn on the led if I send it "LED-ON" command or similar.
Currently I see this type of JSON format. And I want to basically parse the content field out from the JSON object to get me LED-ON.
{
"chatId":64XXXXX7,
"messageId":337,
"type":"message",
"content":"LED-ON",
"date":"2017-09-09T07:07:38.000Z",
"inbound":true
}
I used the JSON node but from the debug it only changes the message from json object to json string. But I still can't parse out LED-ON.
Also if once i get LED-ON filtered and send it out to a split node to generate a MQTT message to turn the LED, do I need it to be a object or string? Sorry I just am very new to programming.
I can share flow if it dosen't make sense.
There is no need for the JSON node if the content is already a JSON object.
I'm at a loss as to why you would need a split node, a switch node or a function node should be all that is needed to test the value in msg.payload.content
The MQTT node will always convert any outbound msg.payload to a string before publishing.
EDIT:
All nodes (including function nodes) need to return an object. The msg.payload should normally hold the "output" from a node, Also no need to declare msg as it is already in scope, so in the case of your example it should be:
msg.payload = msg.payload.content;
return msg;
Also you may do better asking questions like this on the Node-RED Slack team (linked from the Node-RED home page) as it's likely to need a little back and forth, which Stack Overflow is not best suited to.

Pass JSON object vs JSON string in HTTP POST

I'm building a REST API in JAVA and C# and I was wondering about the way I should pass data to those services.
What I'm familiar with as the right way is to send JSON object as the data in the POST body:
{name:'Dor'}
but I can also pass a string and parse the JSON in my service:
'{name:'Dor'}'
What is the preferable way from performance factor? or any other factors?
Basically, if you need to send the json data across via jquery, then we need to use stringify, else the data would be serialized into to key=value pair.
So, you cannot send the json object directly via jquery ajax method.
How it works behind the hood:
In $.ajax function, if we provide data as
data :{key1:"value1", key2:"value2"}
is serialized to key1=value1&key2=value2
if we provide data as
data :'{key1:"value1", key2:"value2"}' or JSON.stringify({key1:"value1", key2:"value2"})
is sent as {key1:"value1", key2:"value2"}
So, what we can conclude is that, we cannot pass json object directly via jquery, we can send only json string. Hope this clarifies everyone.

Spring RESTful service returning JSON from another service

I have been creating Spring RESTful services for a while and typically I am building my own services so I create domain objects and populate them and the framework takes care of the conversion to JSON.
I have a situation now where I simply need my service to act as a pass through to another system's service that is already RESTful and returns JSON.
URL https://:/service/serviceInfo
Method GET
HTTP Content Type Produces: application/json
I simply want to wrap this call (I will apply some security checks on the service) and pass that JSON returned straight back to my service without mapping it back to Java objects, only to return as JSON to the client. Is there a simple way to do this, with minimal code?
Thanks in advance.
Can you see if this works for you?
#RequestMapping("/child")
public String testMethod(#RequestParam String param) {
return new RestTemplate().exchange("https://api.twitter.com/1/statuses/user_timeline.json", HttpMethod.GET, null, String.class).getBody();
}
You just replace the url for your own. I can also guide you to using the RestTemplate with POST or DELETE requests etc. if you need. Also adding parameters or headers if you need. I've used it extensively in some projects.