Value from nested array

I have an array returning from HTTP request

{

    "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

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.

[{"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"]]}]
1 Like

Works. Thanks a ton.

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