Use injector topic in the url http request node

How can i use the injector topic in the url http request node ?

this topic containts the id(example 1002) i use in the url
http://192.168.20.35:82/json.htm?type=devices&rid=1002

Perhaps this thread can clarify

Solved it

http://192.168.20.35:82/json.htm?type=devices&rid={{payload}}

and in the injector node i use the payload for the content

1 Like

Last and most difficult part of my flow is to get the name of the device as a property in my payload..
Do i have to write complex scripts or is there an easier way?
This is my data from the http url (i need "Name" : "lantaarn")

{
	"ActTime" : 1576067493,
	"AstrTwilightEnd" : "18:36",
	"AstrTwilightStart" : "06:35",
	"CivTwilightEnd" : "17:12",
	"CivTwilightStart" : "08:00",
	"DayLength" : "07:51",
	"NautTwilightEnd" : "17:55",
	"NautTwilightStart" : "07:17",
	"ServerTime" : "2019-12-11 13:31:33",
	"SunAtSouth" : "12:36",
	"Sunrise" : "08:40",
	"Sunset" : "16:31",
	"app_version" : "4.11547",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CustomImage" : 0,
			"Data" : "Off",
			"Description" : "",
			"DimmerType" : "none",
			"Favorite" : 0,
			"HardwareID" : 2,
			"HardwareName" : "rfxcom",
			"HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver",
			"HardwareTypeVal" : 1,
			"HaveDimmer" : true,
			"HaveGroupCmd" : true,
			"HaveTimeout" : false,
			"ID" : "0E672C2",
			"Image" : "Light",
			"IsSubDevice" : false,
			"LastUpdate" : "2019-12-11 13:15:10",
			"Level" : 0,
			"LevelInt" : 0,
			"MaxDimLevel" : 15,
			"Name" : "lantaarn",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"Status" : "Off",
			"StrParam1" : "",
			"StrParam2" : "",
			"SubType" : "AC",
			"SwitchType" : "On/Off",
			"SwitchTypeVal" : 0,
			"Timers" : "false",
			"Type" : "Lighting 2",
			"TypeImg" : "lightbulb",
			"Unit" : 3,
			"Used" : 1,
			"UsedByCamera" : false,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "1002"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}

Change node with JSONata would be my first suggestion. Or just a change node as it isn’t that exciting. Try set msg.payload to msg.payload.result[0].Name

I think it works
I made a function with

msg.payload.naam = msg.payload.result[0].Name
return msg;

I finished my function and get the following error:

"TypeError: Cannot read property '0' of undefined"

This is the function
msg.payload = {}
msg.payload.naam = msg.payload.result[0].Name
msg.payload.id = msg.payload.result[0].idx
msg.payload.state = msg.payload.result[0].Status
return msg;

I think i killed the message before reading it..

This is better
name = msg.payload.result[0].Name
state = msg.payload.result[0].Status
idx = msg.payload.result[0].idx
msg.payload = {};
msg.payload.naam = name
msg.payload.state = state
msg.payload.idx = idx
return msg;

thank yoy very much @afelix i think (if by above function is ok) i not only got it working but also understand a little bit how to read and use data from a fetch!

You can simplify it a bit more, yet keep readability:

var payload = {
    naam: msg.payload.result[0].Name,
    state: msg.payload.result[0].Status,
    idx: msg.payload.result[0].idx
};
msg.payload = payload;
return msg;

thanks again!