I want to call node red HTTP page, like node_red_url:1880/test and have a json formatted output back, like:
{"result": [{"Type": "Temp","Data": "30.0 C","id": "31"}]}
Data will be pulled from a MQTT node
is this possible?
Ive found a static page, but i cant to find out how to add dynamic data to it
https://cookbook.nodered.org/http/serve-json-content.html
Yes it's perfectly possible. You just have to realise that the MQTT delivery has to be totally separate from the HTTP request.
MQTT-in -> function node to store latest value in the context
HTTP In -> function node to retrieve value from context -> HTTP Response node
Related
I have extracted 10 values from a Json path extractor, naming device_1,device_2,device_3 to device_10. I am able to see these 10 values in debug sampler and now i want to pass on these value to the next http request one by one (may be by using a loop) but i am not able to find any way where i can pass all these 10 values one by one to next http request. As of now i am sending only 1st value as ${device_1} in the http request but i want 10 different users to access all 10 values one by one.
I believe ForEach Controller is something you're looking for.
Configure it like:
and use ${device} in the HTTP Request sampler which is inside the ForEach Controller.
The HTTP Request will be executed as many times as there are matches generated by the JSON Extractor.
The similar concept is described in Using Regular Expressions in JMeter article
Post request Json Extractor Get request debug sampler error message I'm using Jmeter for stress testing of my application. Test plan that I'm building has a POST request which creates a user and the next PATCH request updates it. Basically I want to extract user_id from Json response received after POST request and add that id in the body of the next request. For that I use Json extractor in my POST request and when I check Debug Sampler the value is successfully stored. But when I try to use extracted user_id in any subsequent requests of the same thread it is not recognized. However when I tried to extract user_id of already created user with GET request then this user_id is normally recognized by other requests. I'm not sure whether Json extractor is not normally used with POST requests or I'm doing something wrong.
It's impossible to provide an answer without seeing the screenshot of your Test Plan or even better Schematic View (the option is available under "Tools" main menu entry since JMeter 5.1)
Given you're able to see the extracted value in the debug sampler I can think of 2 possible options:
Your syntax of referring the user_id variable is wrong, in JMeter the Variables are accessed like ${user_id}
Placement of your JSON Extractor is wrong, i.e. instead of putting it as a child of a specific sampler you have it at the same level as all Samplers therefore it's getting applied to the Debug Sampler as well and the extracted value gets overwritten. See Scoping Rules user manual section for more information
I am using postman to get certain responses. Below is my response.
Here I have some other api request links integrated with this response. Is there any possibility that I can get values inside these apis also. Its like retrieve values forom both parent api request and child api request.
I know this is possible using a java code. But is there any other exsiting software that I can use for this?
In your case I would recommend combining multiple requests into a chain or even a workflow. The idea is to have the first request fetch href endpoints that get called in subsequent requests. For that, the initial request needs a post-request test script that reads the href values from the response and stores it in a environment or global variable.
Like so:
// persist project href for next request
pm.environment.set("projectUrlPath", pm.response.json().embedded.elements[0]._links.project.href);
Your next request in the line would than use this variable to build the request url. Like so:
http://www.example.com{{projectUrlPath}}
The key is to correctly navigate to the right attribute in the response json JavaScript object. This online tool might help you with that:
https://www.w3schools.com/js/tryit.asp?filename=tryjs_json_parse
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.
I have a http request I am trying to make on an afterSave method in my Cloud Code. I have been able to create my request, and when I console.log(response) it outputs a block that contains the information that I am after. I am aware that response.text is a string so I am trying to run JSON.parse(response.text) so I can access my API response.
I can print out what appears to be an object after running JSON.parse, but much of the data within my response is stripped out. I know it is not the fault of the API because I have another function that runs on the client with the same query and it works correctly.
What is the correct way to parse the response.text from a Parse.Cloud.httpRequest to maintain my data.
Try var result = JSON.parse(response['text']).