# Value from nested array

**URL:** https://discourse.nodered.org/t/value-from-nested-array/55922
**Category:** General
**Tags:** http-request, security
**Created:** [31 December 2021 09:47 UTC](https://discourse.nodered.org/t/value-from-nested-array/55922 "2021-12-31T09:47:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dineshaj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dineshaj/32/53342_2.png) [@dineshaj](https://discourse.nodered.org/u/dineshaj)
#### Post date: [31 December 2021 09:47 UTC](https://discourse.nodered.org/t/value-from-nested-array/55922/1 "2021-12-31T09:47:42Z")

</div>

I have an array returning from HTTP request

```auto
{

    "status": "success",

    "message": [

        {

            "Account": {

                "company_name": "ABC1",

                "api_token": "abc1",

                "api_key": "xyz1"

            }

        },

        {

            "Account": {

                "company_name": "ABC2",

                "api_token": "abc2",

                "api_key": "xyz2"

            }

        },

        {

            "Account": {

                "company_name": "ABC3",

                "api_token": "abc3",

                "api_key": "xyz3"

            }

        }

    ]

}

```

I want to take api\_key and api\_token from each array and use them for basic authentication for the next HTTP request. Any help would be apprecated.

Thanks

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [31 December 2021 10:02 UTC](https://discourse.nodered.org/t/value-from-nested-array/55922/2 "2021-12-31T10:02:35Z")

</div>

Assuming this data is in msg.payload.message, use a change node to move/copy the `message` array to `msg.payload` and feed it through a split node. You will get 3 messages - each with the contents of the array elelemnt that you can use to build a URL/query.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/8/88b42b1984290a53aed5b7ef3a90737e65c586a2.png)

```auto
[{"id":"19bcbddb2faffc27","type":"split","z":"484d58c6fda0204f","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1210,"y":480,"wires":[["45ca0005dfa8869a"]]},{"id":"3eff9920a2e57005","type":"change","z":"484d58c6fda0204f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.message","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1400,"y":440,"wires":[["19bcbddb2faffc27"]]},{"id":"45ca0005dfa8869a","type":"debug","z":"484d58c6fda0204f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1390,"y":480,"wires":[]},{"id":"724f2bc4338b6b4e","type":"inject","z":"484d58c6fda0204f","name":"faking http request","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"status\": \"success\", \"message\": [{ \"Account\": { \"company_name\": \"ABC1\", \"api_token\": \"abc1\", \"api_key\": \"xyz1\" } }, { \"Account\": { \"company_name\": \"ABC2\", \"api_token\": \"abc2\", \"api_key\": \"xyz2\" } }, { \"Account\": { \"company_name\": \"ABC3\", \"api_token\": \"abc3\", \"api_key\": \"xyz3\" } }] }","payloadType":"json","x":1190,"y":440,"wires":[["3eff9920a2e57005"]]}]

```

---

<div class="post-metadata">

### Author: ![dineshaj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dineshaj/32/53342_2.png) [@dineshaj](https://discourse.nodered.org/u/dineshaj)
#### Post date: [31 December 2021 10:21 UTC](https://discourse.nodered.org/t/value-from-nested-array/55922/3 "2021-12-31T10:21:51Z")

</div>

Works. Thanks a ton.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [14 January 2022 10:22 UTC](https://discourse.nodered.org/t/value-from-nested-array/55922/4 "2022-01-14T10:22:11Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
