Can't get this API node to work. help!

Hello,

I tried to connect to an api to return me the USD value of some crypto.
I would like to use the API provided by https://www.livecoinwatch.com, and I've followed their instruction as per Live Coin Watch API Documentation

I've created several nodes but I can't get this thing to work.
Of course I've used my actual API key, for the sake of posting I've replaced it with <MY-API>

can you please take a look and tell me what I am doing wrong?
Thank you.

[{"id":"e1db25fcf55f9b7b","type":"inject","z":"f9b5be42.917d48","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":250,"y":1100,"wires":[["9f52a5e5ee9f9186"]]},{"id":"b1472595dc5c674a","type":"debug","z":"f9b5be42.917d48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":1060,"wires":[]},{"id":"550ad075e2642c7e","type":"ha-api","z":"f9b5be42.917d48","name":"Livecoinwatch with data as headers","server":"20f70dbb.a59b52","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"https://api.livecoinwatch.com/exchanges/list","data":"{\t   'headers': (\t       {\t           'content-type': 'application/json',\t           'x-api-key': '<MY-API>'\t       }\t   ),\t   'body': (\t       {\t           'currency': 'USD',\t           'code': 'ETH',\t           'meta': true\t}\t   )\t}","dataType":"jsonata","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":590,"y":1060,"wires":[["b1472595dc5c674a"]]},{"id":"9f52a5e5ee9f9186","type":"function","z":"f9b5be42.917d48","name":"Send headers + body","func":"msg.headers = {}\nmsg.headers['content-type'] = 'application/json';\nmsg.headers['x-api-key'] = '<MY-API>';\nmsg.body = {};\nmsg.body['currency'] = 'USD';\nmsg.body['code']= 'ETH';\nmsg.body['meta']= true;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":1100,"wires":[["8247c36801658cb2"]]},{"id":"d06e64e2cf268127","type":"inject","z":"f9b5be42.917d48","name":"with headers","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"headers","v":"{\t   'content-type' : \"application/json\",\t   'x-api-key' : \"<MY-API>\"\t}\t","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":270,"y":1060,"wires":[["550ad075e2642c7e"]]},{"id":"3389aa70cc81fae1","type":"ha-api","z":"f9b5be42.917d48","name":"Livecoinwatch with data as headers","server":"20f70dbb.a59b52","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"https://api.livecoinwatch.com/coins/single","data":"{\t   'headers': {\t           'content-type': 'application/json',\t           'x-api-key': '<MY-API>'\t       },\t   'body': {\t           'currency': 'ETH',\t           'code': 'gemini',\t           'meta': true\t}\t}","dataType":"jsonata","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":590,"y":1020,"wires":[["b1472595dc5c674a"]]},{"id":"654a0f6f659189c5","type":"inject","z":"f9b5be42.917d48","name":"no headers","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":260,"y":1020,"wires":[["3389aa70cc81fae1"]]},{"id":"8247c36801658cb2","type":"ha-api","z":"f9b5be42.917d48","name":"Livecoinwatch no data","server":"20f70dbb.a59b52","version":1,"debugenabled":false,"protocol":"http","method":"post","path":"https://api.livecoinwatch.com/coins/single","data":"{}","dataType":"jsonata","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":640,"y":1100,"wires":[["b1472595dc5c674a"]]},{"id":"20f70dbb.a59b52","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

No Idea with the node you're using, but you should be able to use the built in http request node.
e.g.

[{"id":"e1db25fcf55f9b7b","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":90,"y":1200,"wires":[["9f52a5e5ee9f9186"]]},{"id":"9f52a5e5ee9f9186","type":"function","z":"c791cbc0.84f648","name":"Send headers + body","func":"msg.headers = {}\nmsg.headers['content-type'] = 'application/json';\nmsg.headers['x-api-key'] = '<MY-API>';\nmsg.payload = `{\n    \"currency\": \"USD\",\n    \"code\": \"ETH\",\n    \"meta\": true\n}`;\nmsg.url = \"https://api.livecoinwatch.com/coins/single\";\nmsg.method = \"POST\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":1200,"wires":[["a5ac8be8.c67ea8"]]},{"id":"a5ac8be8.c67ea8","type":"http request","z":"c791cbc0.84f648","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":310,"y":1260,"wires":[["b1472595dc5c674a"]]},{"id":"b1472595dc5c674a","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":1160,"wires":[]}]
2 Likes

that works. thank you so much.

Still wondering what that API node is for. I can't get it to work.

It's a home assistant node, so I have no idea as i don't use HA
But this may help explain it for you
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/API.html#config

1 Like

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