# Use injector topic in the url http request node

**URL:** <https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015>\
**Category:** General\
**Created:** [11 December 2019 11:59 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015 "2019-12-11T11:59:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pvanklink](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvanklink](https://discourse.nodered.org/u/pvanklink)\
**Post date:** [11 December 2019 11:59 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015/1 "2019-12-11T11:59:08Z")

</div>

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](http://192.168.20.35:82/json.htm?type=devices&rid=1002)

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [11 December 2019 12:10 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015/2 "2019-12-11T12:10:05Z")

</div>

Perhaps this thread can clarify

> [@HTTP request node - query string](https://discourse.nodered.org/t/http-request-node-query-string/9235):
>
> The http request node was greatly improved in Node-REd version 0.20 with the addition of Bearer and Digest authentication modes. Additionally, a new option was added to allow building a query string from msg.payload. This is explained in the release notes as quoted below: The HTTP Request node can optionally automatically encode msg.payload as query string parameters for a GET request. What is missing perhaps is a quick note in the help text explaining that msg.payload in such case is expec…

---

<div class="post-metadata">

**Author:** ![pvanklink](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvanklink](https://discourse.nodered.org/u/pvanklink)\
**Post date:** [11 December 2019 12:13 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015/3 "2019-12-11T12:13:37Z")

</div>

Solved it

[http://192.168.20.35:82/json.htm?type=devices&rid={{payload}](http://192.168.20.35:82/json.htm?type=devices&rid=%7B%7Bpayload%7D)}

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

---

<div class="post-metadata">

**Author:** ![pvanklink](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvanklink](https://discourse.nodered.org/u/pvanklink)\
**Post date:** [11 December 2019 12:34 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015/4 "2019-12-11T12:34:05Z")

</div>

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")

```auto
{
	"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"
}

```

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [11 December 2019 12:35 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015/5 "2019-12-11T12:35:31Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![pvanklink](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvanklink](https://discourse.nodered.org/u/pvanklink)\
**Post date:** [11 December 2019 12:51 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015/6 "2019-12-11T12:51:05Z")

</div>

I think it works  
I made a function with

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

---

<div class="post-metadata">

**Author:** ![pvanklink](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvanklink](https://discourse.nodered.org/u/pvanklink)\
**Post date:** [11 December 2019 12:56 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015/7 "2019-12-11T12:56:25Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![pvanklink](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvanklink](https://discourse.nodered.org/u/pvanklink)\
**Post date:** [11 December 2019 13:06 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015/8 "2019-12-11T13:06:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [11 December 2019 13:42 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015/9 "2019-12-11T13:42:05Z")

</div>

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

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![pvanklink](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvanklink](https://discourse.nodered.org/u/pvanklink)\
**Post date:** [11 December 2019 22:09 UTC](https://discourse.nodered.org/t/use-injector-topic-in-the-url-http-request-node/19015/10 "2019-12-11T22:09:33Z")

</div>

thanks again!
