Can anyone help me with this JSON API?

Hello Everyone,

I'm trying to extract data from a single station (unique by "station_id") from this JSON API

but because of syntax and my inexperience, I've failed so many attempts to create a node.
I only was able to get a reply with all the stations, which is useless to me.

I'm attaching the node I did. Many thanks to anyone that will help me.

[{"id":"3efa2f6c5eba45bc","type":"ha-api","z":"f9b5be42.917d48","name":"API Citibike","server":"20f70dbb.a59b52","version":1,"debugenabled":false,"protocol":"http","method":"get","path":"https://gbfs.citibikenyc.com/gbfs/en/station_status.json","data":"{\"data/stations.station_id\":\"79\"}","dataType":"jsonata","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":470,"y":280,"wires":[["cd1c0e4fa78ae79c"]]},{"id":"2fbaeade593a1e45","type":"inject","z":"f9b5be42.917d48","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":190,"y":280,"wires":[["3efa2f6c5eba45bc"]]},{"id":"cd1c0e4fa78ae79c","type":"debug","z":"f9b5be42.917d48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":680,"y":260,"wires":[]},{"id":"20f70dbb.a59b52","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Here's an example with the http request node and javascript's find method
dont know if you find it useful in creating your node

[{"id":"2fbaeade593a1e45","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":300,"y":940,"wires":[["ec18945612b57b9e"]]},{"id":"cd1c0e4fa78ae79c","type":"debug","z":"5847b7aa62131d37","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":940,"wires":[]},{"id":"ec18945612b57b9e","type":"http request","z":"5847b7aa62131d37","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://gbfs.citibikenyc.com/gbfs/en/station_status.json","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":490,"y":940,"wires":[["4e32b19bd744ec88"]]},{"id":"4e32b19bd744ec88","type":"function","z":"5847b7aa62131d37","name":"filter","func":"let stations = msg.payload.data.stations\nlet myStation = \"239\"  // change for your station id\n\nmsg.payload = stations.find(el => el.station_id === myStation)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":940,"wires":[["cd1c0e4fa78ae79c"]]}]
1 Like

Thank you, that works perfectly!

many many thanks, I've learned something new.

1 Like

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