# Automatic token HTTP request

**URL:** <https://discourse.nodered.org/t/automatic-token-http-request/63516>\
**Category:** General\
**Tags:** http-request\
**Created:** [6 June 2022 14:00 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516 "2022-06-06T14:00:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 14:00 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/1 "2022-06-06T14:00:02Z")

</div>

hello.

I have two functions in my flow, the first requests a token for the connection, the second makes a request to know the consumption of a 4G card with the previous token.

I'm looking to do the function in one go:  
request a token and then inject it into the consumption request.  
How can I do ?

flow json

```auto
[{"id":"692c6984.8f8378","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"574eca6a.6af534","type":"http request","z":"692c6984.8f8378","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://api.matooma.com/token","tls":"","persist":false,"proxy":"","authType":"basic","x":350,"y":80,"wires":[["b9544847.833b58","6b30d846.467b88"]]},{"id":"334d337d.3c77fc","type":"inject","z":"692c6984.8f8378","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":80,"wires":[["574eca6a.6af534"]]},{"id":"b9544847.833b58","type":"string","z":"692c6984.8f8378","name":"","methods":[{"name":"between","params":[{"type":"str","value":"\":\""},{"type":"str","value":"\","}]},{"name":"trim","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":500,"y":80,"wires":[["311cbf55.3b5de"]]},{"id":"d9d65a56.b2e4a8","type":"http request","z":"692c6984.8f8378","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/v1/consumptions/total/8931080019084156174?start=2022-06-01&end=2022-06-06","tls":"","persist":false,"proxy":"","authType":"bearer","x":390,"y":200,"wires":[["e8559536.1f9218"]]},{"id":"e8559536.1f9218","type":"debug","z":"692c6984.8f8378","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":200,"wires":[]},{"id":"311cbf55.3b5de","type":"debug","z":"692c6984.8f8378","name":"string","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":80,"wires":[]},{"id":"895d5462.4e5248","type":"inject","z":"692c6984.8f8378","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":200,"wires":[["d9d65a56.b2e4a8"]]},{"id":"6b30d846.467b88","type":"debug","z":"692c6984.8f8378","name":"request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":500,"y":20,"wires":[]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a28e0f61782e3b67c70268167b6f95179d68e66.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2022 14:56 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/2 "2022-06-06T14:56:27Z")

</div>

something like this should work. Notice I output a parsed json object from first http request node, then save the token. I then delete any headers and rebuild Authorization headers with msg.token.

Untested as no access to api.

```auto
[{"id":"334d337d.3c77fc","type":"inject","z":"692c6984.8f8378","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":80,"wires":[["574eca6a.6af534"]]},{"id":"574eca6a.6af534","type":"http request","z":"692c6984.8f8378","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/token","tls":"","persist":false,"proxy":"","authType":"basic","x":350,"y":80,"wires":[["6b30d846.467b88","28c9829b.21043e"]]},{"id":"6b30d846.467b88","type":"debug","z":"692c6984.8f8378","name":"request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":500,"y":20,"wires":[]},{"id":"28c9829b.21043e","type":"change","z":"692c6984.8f8378","name":"","rules":[{"t":"set","p":"token","pt":"msg","to":"payload.access_token","tot":"msg"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $$.token","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":80,"wires":[["d9d65a56.b2e4a8","849fec3c.71214"]]},{"id":"d9d65a56.b2e4a8","type":"http request","z":"692c6984.8f8378","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/v1/consumptions/total/8931080019084156174?start=2022-06-01&end=2022-06-06","tls":"","persist":false,"proxy":"","authType":"","x":390,"y":200,"wires":[["e8559536.1f9218"]]},{"id":"849fec3c.71214","type":"debug","z":"692c6984.8f8378","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":720,"y":40,"wires":[]},{"id":"e8559536.1f9218","type":"debug","z":"692c6984.8f8378","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":200,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 15:25 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/3 "2022-06-06T15:25:54Z")

</div>

thank you, after some adaptation I managed to solve the problem.

I attach the code for who want.

```auto
[{"id":"692c6984.8f8378","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"af04a848.8a9298","type":"inject","z":"692c6984.8f8378","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":160,"wires":[["81f93031.6f048"]]},{"id":"7ca49257.13bd7c","type":"debug","z":"692c6984.8f8378","name":"request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":420,"y":100,"wires":[]},{"id":"9a84ae67.9cf7a","type":"http request","z":"692c6984.8f8378","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/v1/consumptions/total/8931080019084156174?start=2022-06-01&end=2022-06-06","tls":"","persist":false,"proxy":"","authType":"","x":150,"y":320,"wires":[["e13cd190.a7106"]]},{"id":"b3fc4df9.d228b","type":"debug","z":"692c6984.8f8378","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"headers","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":120,"wires":[]},{"id":"e13cd190.a7106","type":"debug","z":"692c6984.8f8378","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":330,"y":320,"wires":[]},{"id":"81f93031.6f048","type":"http request","z":"692c6984.8f8378","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://api.matooma.com/token","tls":"","persist":false,"proxy":"","authType":"basic","x":270,"y":160,"wires":[["7ca49257.13bd7c","4a40f452.38831c"]]},{"id":"d5bbd6a4.189048","type":"change","z":"692c6984.8f8378","name":"","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":160,"wires":[["9a84ae67.9cf7a","b3fc4df9.d228b","2989355a.bb11da"]]},{"id":"4a40f452.38831c","type":"string","z":"692c6984.8f8378","name":"","methods":[{"name":"between","params":[{"type":"str","value":"\":\""},{"type":"str","value":"\","}]},{"name":"trim","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":430,"y":160,"wires":[["d5bbd6a4.189048"]]},{"id":"2989355a.bb11da","type":"debug","z":"692c6984.8f8378","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"headers.Authorization","targetType":"msg","statusVal":"","statusType":"auto","x":760,"y":60,"wires":[]}]

```

in my last request I have a unique ICCID ([https://api.matooma.com/v1/consumptions/total/8931080019084156174?start=2022-06-01&end=2022-06-06](https://api.matooma.com/v1/consumptions/total/8931080019084156174?start=2022-06-01&end=2022-06-06) **ex: 8931080019084156174** ), but I have several cards to test to add up the consumption of each card in order to make a consumption dashboard.  
How can I change this value in my url by retrieving the ICCIDs in a file (txt or excel ...)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2022 15:48 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/4 "2022-06-06T15:48:10Z")

</div>

```auto
[{"id":"334d337d.3c77fc","type":"inject","z":"692c6984.8f8378","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":100,"wires":[["574eca6a.6af534"]]},{"id":"574eca6a.6af534","type":"http request","z":"692c6984.8f8378","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/token","tls":"","persist":false,"proxy":"","authType":"basic","x":360,"y":260,"wires":[["6b30d846.467b88","28c9829b.21043e"]]},{"id":"6b30d846.467b88","type":"debug","z":"692c6984.8f8378","name":"request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":510,"y":200,"wires":[]},{"id":"28c9829b.21043e","type":"change","z":"692c6984.8f8378","name":"","rules":[{"t":"set","p":"token","pt":"msg","to":"payload.access_token","tot":"msg"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $$.token","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":260,"wires":[["849fec3c.71214","db63a27b.fbd93"]]},{"id":"849fec3c.71214","type":"debug","z":"692c6984.8f8378","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":220,"wires":[]},{"id":"db63a27b.fbd93","type":"template","z":"692c6984.8f8378","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"8931080019084156174\n8931080019084156175","output":"str","x":310,"y":320,"wires":[["8a05e20e.fdb87"]]},{"id":"8a05e20e.fdb87","type":"split","z":"692c6984.8f8378","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":450,"y":320,"wires":[["6ca8d878.deda8"]]},{"id":"6ca8d878.deda8","type":"change","z":"692c6984.8f8378","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"\"https://api.matooma.com/v1/consumptions/total/\" & $$.payload & \"?start=2022-06-01&end=2022-06-06\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":320,"wires":[["d9d65a56.b2e4a8"]]},{"id":"d9d65a56.b2e4a8","type":"http request","z":"692c6984.8f8378","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/v1/consumptions/total/8931080019084156174?start=2022-06-01&end=2022-06-06","tls":"","persist":false,"proxy":"","authType":"","x":400,"y":380,"wires":[["e8559536.1f9218"]]},{"id":"e8559536.1f9218","type":"debug","z":"692c6984.8f8378","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":380,"wires":[]}]

```

example of spliting text and sending each card.

ps you do not need the string node the http request can output the parsed json, and you can extract the token using the change node as i showed, show us the payload from first request response, then i can show you how to get token correctly.  
[edit] moved split to after first request as you do not need to request token again.

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 16:10 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/5 "2022-06-06T16:10:14Z")

</div>

Good job!!! Just a "bearer" correction must have a capital "b".  
template can be loaded via an external file? I explain myself, when I activate a new sim card I register it in a file in my network and I would not want to have to do it also in the node-red.

on the same principle I am therefore able to do the start and end of the url so that the date changes every day?!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2022 16:14 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/6 "2022-06-06T16:14:07Z")

</div>

> [@LinkView\_Maze](#):
>
> Good job!!! Just a "bearer" correction must have a capital "b"

As said this was untested so missed my typo.

Yes you can do same with date in url.

The template node can be a file read node and you save cards to text file or similar.  
If solved mark solution for future users to find easier.

[edit] you may want to add a switch node after first response and check that the token is set and statusCode equals 200 before moving on to second requests.

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 18:34 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/7 "2022-06-06T18:34:42Z")

</div>

```auto
[{"id":"334d337d.3c77fc","type":"inject","z":"692c6984.8f8378","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":100,"wires":[["574eca6a.6af534"]]},{"id":"574eca6a.6af534","type":"http request","z":"692c6984.8f8378","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/token","tls":"","persist":false,"proxy":"","authType":"basic","x":360,"y":260,"wires":[["6b30d846.467b88","28c9829b.21043e"]]},{"id":"6b30d846.467b88","type":"debug","z":"692c6984.8f8378","name":"request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":510,"y":200,"wires":[]},{"id":"28c9829b.21043e","type":"change","z":"692c6984.8f8378","name":"","rules":[{"t":"set","p":"token","pt":"msg","to":"payload.access_token","tot":"msg"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $$.token","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":260,"wires":[["849fec3c.71214","db63a27b.fbd93"]]},{"id":"849fec3c.71214","type":"debug","z":"692c6984.8f8378","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":220,"wires":[]},{"id":"db63a27b.fbd93","type":"template","z":"692c6984.8f8378","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"8931080019084156174\n8931080019084156175","output":"str","x":310,"y":320,"wires":[["8a05e20e.fdb87"]]},{"id":"8a05e20e.fdb87","type":"split","z":"692c6984.8f8378","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":450,"y":320,"wires":[["6ca8d878.deda8"]]},{"id":"6ca8d878.deda8","type":"change","z":"692c6984.8f8378","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"\"https://api.matooma.com/v1/consumptions/total/\" & $$.payload & \"?start=2022-06-01&end=2022-06-06\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":320,"wires":[["d9d65a56.b2e4a8"]]},{"id":"d9d65a56.b2e4a8","type":"http request","z":"692c6984.8f8378","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/v1/consumptions/total/8931080019084156174?start=2022-06-01&end=2022-06-06","tls":"","persist":false,"proxy":"","authType":"","x":400,"y":380,"wires":[["e8559536.1f9218"]]},{"id":"e8559536.1f9218","type":"debug","z":"692c6984.8f8378","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":380,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 18:38 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/8 "2022-06-06T18:38:48Z")

</div>

Sorry for my insistence and surely out of context of the topic.

I manage to isolated the msg.payload.consumption[0].offer.data from each request . How can I add all the values?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2022 20:06 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/9 "2022-06-06T20:06:47Z")

</div>

With no sample data it difficult to get right, but at a guess

```auto
[{"id":"574eca6a.6af534","type":"http request","z":"bf9e1e33.030598","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/token","tls":"","persist":false,"proxy":"","authType":"basic","x":300,"y":3180,"wires":[["6b30d846.467b88","28c9829b.21043e"]]},{"id":"334d337d.3c77fc","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":70,"y":3020,"wires":[["574eca6a.6af534"]]},{"id":"6b30d846.467b88","type":"debug","z":"bf9e1e33.030598","name":"request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":450,"y":3120,"wires":[]},{"id":"28c9829b.21043e","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"token","pt":"msg","to":"payload.access_token","tot":"msg"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $$.token","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":3180,"wires":[["849fec3c.71214","db63a27b.fbd93"]]},{"id":"849fec3c.71214","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":3140,"wires":[]},{"id":"db63a27b.fbd93","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"8931080019084156174\n8931080019084156175","output":"str","x":250,"y":3240,"wires":[["8a05e20e.fdb87"]]},{"id":"8a05e20e.fdb87","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":390,"y":3240,"wires":[["6ca8d878.deda8"]]},{"id":"6ca8d878.deda8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"\"https://api.matooma.com/v1/consumptions/total/\" & $$.payload & \"?start=2022-06-01&end=2022-06-06\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":3240,"wires":[["d9d65a56.b2e4a8"]]},{"id":"d9d65a56.b2e4a8","type":"http request","z":"bf9e1e33.030598","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/v1/consumptions/total/8931080019084156174?start=2022-06-01&end=2022-06-06","tls":"","persist":false,"proxy":"","authType":"","x":340,"y":3300,"wires":[["1cd9599.bfea5a6"]]},{"id":"1cd9599.bfea5a6","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"parts.type","pt":"msg","to":"array","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":3340,"wires":[["c6c76181.bb3fb"]]},{"id":"c6c76181.bb3fb","type":"join","z":"bf9e1e33.030598","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":470,"y":3340,"wires":[["7a042c8f.2597bc"]]},{"id":"7a042c8f.2597bc","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($$.payload[*].consumption[0].offer.data)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":3360,"wires":[["e8559536.1f9218"]]},{"id":"e8559536.1f9218","type":"debug","z":"bf9e1e33.030598","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":3220,"wires":[]}]

```

[edit] updated with msg.parts.type and added [0] to final JSONata expression

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 20:40 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/10 "2022-06-06T20:40:16Z")

</div>

I don't have a result and no error

```auto
[{"id":"4e595dc2.98eb64","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"334d337d.3c77fc","type":"inject","z":"4e595dc2.98eb64","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":100,"y":40,"wires":[["2537b085.5efae"]]},{"id":"574eca6a.6af534","type":"http request","z":"4e595dc2.98eb64","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/token","tls":"","persist":false,"proxy":"","authType":"basic","x":130,"y":120,"wires":[["28c9829b.21043e"]]},{"id":"28c9829b.21043e","type":"change","z":"4e595dc2.98eb64","name":"","rules":[{"t":"set","p":"token","pt":"msg","to":"payload.access_token","tot":"msg"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $$.token","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":120,"wires":[["4a8db008.ca703"]]},{"id":"8a05e20e.fdb87","type":"split","z":"4e595dc2.98eb64","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"","x":430,"y":200,"wires":[["6ca8d878.deda8"]]},{"id":"6ca8d878.deda8","type":"change","z":"4e595dc2.98eb64","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"card","tot":"msg"},{"t":"set","p":"url","pt":"msg","to":"\"https://api.matooma.com/v1/consumptions/total/\" & $$.card & \"?start=2022-\" & $$.month & \"-01&end=\" & $$.date","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":200,"wires":[["d9d65a56.b2e4a8"]]},{"id":"d9d65a56.b2e4a8","type":"http request","z":"4e595dc2.98eb64","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":790,"y":200,"wires":[["d7c50515.fe2138"]]},{"id":"2537b085.5efae","type":"moment","z":"4e595dc2.98eb64","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Paris","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"fr-FR","output":"","outputType":"msg","outTz":"Europe/Paris","x":320,"y":40,"wires":[["4bd6bdf3.b20c94"]]},{"id":"970fdb9b.0bee58","type":"string","z":"4e595dc2.98eb64","name":"Month","methods":[{"name":"between","params":[{"type":"str","value":"-"},{"type":"str","value":"-"}]}],"prop":"payload","propout":"month","object":"msg","objectout":"msg","x":650,"y":60,"wires":[["574eca6a.6af534"]]},{"id":"4a8db008.ca703","type":"file in","z":"4e595dc2.98eb64","name":"","filename":"/home/pi/Documents/card.txt","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":240,"y":200,"wires":[["8a05e20e.fdb87"]]},{"id":"4bd6bdf3.b20c94","type":"string","z":"4e595dc2.98eb64","name":"Date","methods":[{"name":"delRightMost","params":[{"type":"str","value":"T"}]}],"prop":"payload","propout":"date","object":"msg","objectout":"msg","x":510,"y":40,"wires":[["970fdb9b.0bee58"]]},{"id":"fdfe4aad.6fe628","type":"ui_chart","z":"4e595dc2.98eb64","name":"","group":"e051b2b2.40092","order":0,"width":"21","height":"14","label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":990,"y":300,"wires":[[]]},{"id":"d7c50515.fe2138","type":"join","z":"4e595dc2.98eb64","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":590,"y":280,"wires":[["27c2b014.b4e8"]]},{"id":"27c2b014.b4e8","type":"change","z":"4e595dc2.98eb64","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($$.payload.consumption[*].offer.data)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":280,"wires":[["c9d53e73.dc11b","fdfe4aad.6fe628"]]},{"id":"c9d53e73.dc11b","type":"debug","z":"4e595dc2.98eb64","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":260,"wires":[]},{"id":"e051b2b2.40092","type":"ui_group","name":"Default","tab":"18f38411.1cc31c","order":1,"disp":true,"width":"21","collapse":false,"className":""},{"id":"18f38411.1cc31c","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

I don't post my ID and password sorry

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2022 20:44 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/11 "2022-06-06T20:44:40Z")

</div>

I did not ask for a password or an ID.

I did point out you supplied no data, i.e the result of at least one payload from the second  
http request. You can sanitize if sensitive data.

Or better still after the join node a debug output of the joined payloads, that would save me having to build it to test.

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 20:48 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/12 "2022-06-06T20:48:59Z")

</div>

how can I provide you with the results of the request?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2022 20:51 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/13 "2022-06-06T20:51:08Z")

</div>

Use debug nodes after the nodes to see the payloads. Then use the copy value button. It appears after you hover next to the object name.

ps. tip name you debug nodes for easier viewing in the debug sidebar.

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 20:57 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/14 "2022-06-06T20:57:00Z")

</div>

> [@E1cid](#):
>
> la valeur. Il apparaît après que vous avez survolé à côté du nom de l'objet

sorry im new to node red  
resut debug after the last http resquest :

```auto
{"target":"iccid","target_value":"8931080019084156190","capacity":{"data":481036337152,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0},"consumption":[{"offer":{"data":941168640,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0}},{"counter":{"data":0,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0}}]}

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2022 21:12 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/15 "2022-06-06T21:12:33Z")

</div>

Using your sample of one http request result, I have simulated a second request in a split/http/join and outputted the sum of the two values.

This should work

```auto
[{"id":"334d337d.3c77fc","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":430,"y":3100,"wires":[["db63a27b.fbd93"]]},{"id":"db63a27b.fbd93","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"8931080019084156174\n8931080019084156175","output":"str","x":230,"y":3140,"wires":[["8a05e20e.fdb87"]]},{"id":"8a05e20e.fdb87","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":370,"y":3140,"wires":[["6ca8d878.deda8"]]},{"id":"6ca8d878.deda8","type":"change","z":"bf9e1e33.030598","name":"simulate http request result","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"target\":\"iccid\",\t \"target_value\":\"8931080019084156190\",\t \"capacity\":{\t \"data\":481036337152,\t \"sms_in\":0,\t \"sms_out\":0,\t \"voice_in\":0,\t \"voice_out\":0\t },\t \"consumption\":[\t {\t \"offer\":{\t \"data\":941168640,\t \"sms_in\":0,\t \"sms_out\":0,\t \"voice_in\":0,\t \"voice_out\":0\t }\t },\t {\t \"counter\":{\t \"data\":0,\t \"sms_in\":0,\t \"sms_out\":0,\t \"voice_in\":0,\t \"voice_out\":0\t }\t }\t]\t}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":3140,"wires":[["287c634c.4a8bd4"]]},{"id":"287c634c.4a8bd4","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"parts.type","pt":"msg","to":"array","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":3200,"wires":[["c6c76181.bb3fb"]]},{"id":"c6c76181.bb3fb","type":"join","z":"bf9e1e33.030598","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":490,"y":3200,"wires":[["7a042c8f.2597bc","e8559536.1f9218"]]},{"id":"7a042c8f.2597bc","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($$.payload[*].consumption[0].offer.data)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":3240,"wires":[["e8559536.1f9218"]]},{"id":"e8559536.1f9218","type":"debug","z":"bf9e1e33.030598","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":3160,"wires":[]}]

```

[edit] updated previous example above this, post 9, as join was not of type array.

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 21:40 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/16 "2022-06-06T21:40:24Z")

</div>

it doesn't work but my problem may be that some request answers {empty}

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2022 21:47 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/17 "2022-06-06T21:47:17Z")

</div>

Again I am working virtually blind here.

Supply some data so we can see.  
can we see a debug of the joined data.  
values like `{}` in the result should make no difference, it is a valid json and should provide a valid response. just an empty object, which the JSONata expression would just ignore.

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 22:16 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/18 "2022-06-06T22:16:08Z")

</div>

here multiple message request and 1 message empty

```auto
{}

```

```auto
{"target":"iccid","target_value":"8931080019084155952","capacity":{"data":481036337152,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0},"consumption":[{"offer":{"data":361486336,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0}},{"counter":{"data":0,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0}}]}

```

```auto
{"target":"iccid","target_value":"8931080019084155945","capacity":{"data":481036337152,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0},"consumption":[{"offer":{"data":1457929216,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0}},{"counter":{"data":0,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0}}]}

```

```auto
{"target":"iccid","target_value":"8931080019084156158","capacity":{"data":481036337152,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0},"consumption":[{"offer":{"data":1318604800,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0}},{"counter":{"data":0,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0}}]}

```

```auto
{"target":"iccid","target_value":"8931080019084155663","capacity":{"data":481036337152,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0},"consumption":[{"offer":{"data":1255768064,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0}},{"counter":{"data":0,"sms_in":0,"sms_out":0,"voice_in":0,"voice_out":0}}]}

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2022 22:23 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/19 "2022-06-06T22:23:08Z")

</div>

I want to see the debug after the join node not before.

```auto
[{"id":"d2e85cf7.f2e8a8","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":3140,"wires":[["ba1c10c7.906dc8"]]},{"id":"ba1c10c7.906dc8","type":"http request","z":"bf9e1e33.030598","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/token","tls":"","persist":false,"proxy":"","authType":"basic","x":320,"y":3300,"wires":[["a461bb9d.4a1a38"]]},{"id":"a461bb9d.4a1a38","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"token","pt":"msg","to":"payload.access_token","tot":"msg"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $$.token","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":3300,"wires":[["9e99d67f.a12ca8"]]},{"id":"9e99d67f.a12ca8","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"8931080019084156174\n8931080019084156175","output":"str","x":270,"y":3360,"wires":[["ecf6006f.93e248"]]},{"id":"ecf6006f.93e248","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":410,"y":3360,"wires":[["10b8aa4d.f13f9e"]]},{"id":"10b8aa4d.f13f9e","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"\"https://api.matooma.com/v1/consumptions/total/\" & $$.payload & \"?start=2022-06-01&end=2022-06-06\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":3360,"wires":[["69ad6af1.a018cc"]]},{"id":"69ad6af1.a018cc","type":"http request","z":"bf9e1e33.030598","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/v1/consumptions/total/8931080019084156174?start=2022-06-01&end=2022-06-06","tls":"","persist":false,"proxy":"","authType":"","x":360,"y":3420,"wires":[["dddbb4a6.a57f48"]]},{"id":"dddbb4a6.a57f48","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"parts.type","pt":"msg","to":"array","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":3460,"wires":[["fca18795.18f68"]]},{"id":"fca18795.18f68","type":"join","z":"bf9e1e33.030598","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":490,"y":3460,"wires":[["cd414862.210cd8","6fc7cc82.695a34"]]},{"id":"cd414862.210cd8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($$.payload[*].consumption[0].offer.data)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":3480,"wires":[[]]},{"id":"6fc7cc82.695a34","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":3420,"wires":[]}]

```

use this example, edit the template and user/password in first http node

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [6 June 2022 22:51 UTC](https://discourse.nodered.org/t/automatic-token-http-request/63516/20 "2022-06-06T22:51:04Z")

</div>

thank you, I check 150 cards , the result is so long 😁 your code is ok !

my full code !

```auto
[{"id":"ba1c10c7.906dc8","type":"http request","z":"be3c6730.befb08","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/token","tls":"","persist":false,"proxy":"","authType":"basic","x":470,"y":280,"wires":[["a461bb9d.4a1a38"]]},{"id":"a461bb9d.4a1a38","type":"change","z":"be3c6730.befb08","name":"","rules":[{"t":"set","p":"token","pt":"msg","to":"payload.access_token","tot":"msg"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $$.token","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":280,"wires":[["9e99d67f.a12ca8"]]},{"id":"9e99d67f.a12ca8","type":"template","z":"be3c6730.befb08","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"8931080019084145730\n8931080019084155432\n8931080019084145110\n8931080019084155416\n8931080019084155424\n8931080019084145037\n8931080019084145151\n8931080019084145136\n8931080019084156182\n8931080019084156174\n8931080019084156166\n8931080119109159656\n8931080119109159649\n8931080119109159631\n8931080119109159623\n8931080119109159615\n8931080119109159748\n8931080019084145052\n8931080019084145177\n8931080019084145243\n8931080019084145219\n8931080019084145193\n8931080019084145144\n8931080019084145029\n8931080019084145201\n8931080019084145235\n8931080019084145250\n8931080119109159664\n8931080119109159672\n8931080119109159680\n8931080119109159698\n8931080119109159706\n8931080119109159714\n8931080119109159755\n8931080119109159763\n8931080119109159771\n8931080119109159789\n8931080119109159805\n8931080119109159797\n8931089218082631086\n8931089218082631003\n8931089218082631094\n8931089218082631136\n8931089218082631102\n8931089218082630971\n8931089218082631011\n8931089218082631045\n8931089218082631052\n8931089218082631144\n8931089218082631151\n8931088717106667779\n8931088918023803840\n8931088717106667787\n8931088717106667795\n8931088717106667803\n8931088717106667811\n8931088717106667829\n8931088717106667845\n8931088717106667852\n8931088918023803816\n8931088918023803824\n8931080019084156125\n8931080019084155671\n8931080019084145185\n8931080019084155556\n8931080019084145094\n8931080019084145805\n8931080019084145797\n8931080019084145060\n8931080019084146001\n8931080019084155440\n8931080019084145839\n8931080019084155564\n8931080019084155580\n8931080019084155572\n8931080019084155598\n8931080019084155606\n8931080019084155622\n8931080019084155614\n8931080019084145821\n8931080019084145763\n8931080019084155630\n8931080019084145714\n8931080019084145706\n8931080019084155648\n8931080019084155655\n8931080019084145045\n8931080019084155952\n8931080019084156133\n8931080019084145813\n8931080019084145789\n8931080019084145847\n8931080019084155945\n8931080019084156141\n8931080019084155937\n8931080019084155911\n8931080019084156158\n8931080019084155663\n8931080019084156190\n","output":"str","x":420,"y":340,"wires":[["ecf6006f.93e248"]]},{"id":"ecf6006f.93e248","type":"split","z":"be3c6730.befb08","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":560,"y":340,"wires":[["3debe7ed.39d978"]]},{"id":"69ad6af1.a018cc","type":"http request","z":"be3c6730.befb08","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":510,"y":400,"wires":[["dddbb4a6.a57f48"]]},{"id":"dddbb4a6.a57f48","type":"change","z":"be3c6730.befb08","name":"","rules":[{"t":"set","p":"parts.type","pt":"msg","to":"array","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":520,"wires":[["fca18795.18f68"]]},{"id":"fca18795.18f68","type":"join","z":"be3c6730.befb08","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":590,"y":520,"wires":[["cd414862.210cd8"]]},{"id":"cd414862.210cd8","type":"change","z":"be3c6730.befb08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($$.payload[*].consumption[0].offer.data)*0.000000001","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":520,"wires":[["138eb22f.35b12e"]]},{"id":"3debe7ed.39d978","type":"change","z":"be3c6730.befb08","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"card","tot":"msg"},{"t":"set","p":"url","pt":"msg","to":"\"https://api.matooma.com/v1/consumptions/total/\" & $$.card & \"?start=2022-06-01&end=2022-06-06\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":340,"wires":[["69ad6af1.a018cc"]]},{"id":"138eb22f.35b12e","type":"debug","z":"be3c6730.befb08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":660,"wires":[]},{"id":"e38b2d03.b9a36","type":"inject","z":"be3c6730.befb08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":200,"y":80,"wires":[["3f3bf7df.5f27a8"]]},{"id":"98c5d646.e47e38","type":"http request","z":"be3c6730.befb08","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://api.matooma.com/token","tls":"","persist":false,"proxy":"","authType":"basic","x":230,"y":160,"wires":[["48b17868.b6cbc8"]]},{"id":"48b17868.b6cbc8","type":"change","z":"be3c6730.befb08","name":"","rules":[{"t":"set","p":"token","pt":"msg","to":"payload.access_token","tot":"msg"},{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $$.token","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":160,"wires":[["ba1c10c7.906dc8"]]},{"id":"3f3bf7df.5f27a8","type":"moment","z":"be3c6730.befb08","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Paris","adjAmount":0,"adjType":"days","adjDir":"add","format":"","locale":"fr-FR","output":"","outputType":"msg","outTz":"Europe/Paris","x":420,"y":80,"wires":[["59be9723.f7fcf8"]]},{"id":"f72dd901.57ad08","type":"string","z":"be3c6730.befb08","name":"Month","methods":[{"name":"between","params":[{"type":"str","value":"-"},{"type":"str","value":"-"}]}],"prop":"payload","propout":"month","object":"msg","objectout":"msg","x":750,"y":100,"wires":[["98c5d646.e47e38"]]},{"id":"59be9723.f7fcf8","type":"string","z":"be3c6730.befb08","name":"Date","methods":[{"name":"delRightMost","params":[{"type":"str","value":"T"}]}],"prop":"payload","propout":"date","object":"msg","objectout":"msg","x":610,"y":80,"wires":[["f72dd901.57ad08","81bd645e.db3cd8"]]},{"id":"81bd645e.db3cd8","type":"debug","z":"be3c6730.befb08","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"date","targetType":"msg","statusVal":"","statusType":"auto","x":740,"y":60,"wires":[]}]

```

[Next page](https://discourse.nodered.org/t/automatic-token-http-request/63516.md?page=2)
