Friday 12 January 2018

Need help pulling API data with snekfetch

This is my first time using Node JS, Discord JS, and API.. Hoping someone might be able to help me out. My console is returning the "id" correct, but the entry is showing "undefined"I'm trying to search the API for "MarketName" and match it with id.example: id = "BTC-:+parameter"search for LTCid = BTC-LTCsearch API for "MarketName: BTC-LTC" or "BTC-LTC" or whatever will work. Then returning only the data for that object.Hope that makes sense, and thanks..const api = "http://ift.tt/1xBrJdL"; const snekfetch = require("snekfetch"); module.exports.run = async (bot, message, args) => { snekfetch.get(api).then(r => { let body = r.body; let id = "BTC-"+args[0]; if(!id) return message.channel.send("Provide a ticker"); if(!isNaN(id)) return message.channel.send("Not a valid ticker"); let entry = Object.entries(body).find(post => post.id === id); console.log(id); console.log(entry); if(!entry) return message.channel.send("This entry does not exist"); }); }

Submitted January 13, 2018 at 02:24AM by b0red88

No comments:

Post a Comment