Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Chris Grazioli
Chris Grazioli
31,225 Points

I'm trying to do the extra credit for Node.js Retrieving Data - Solution section of the Node course.

@Andrew Chalkley I'm trying to do the extra credit part of the node.js course. I decided to get a BTC/USD quote from the gdax api - https://api.gdax.com/products/BTC-USD/ticker

I don't need a key or any auth for the public section, not unlike the treehouse example. I believe the endpoint returns JSON since the trade_id is quoted:

{"trade_id":39710034,"price":"8168.04000000","size":"0.54430000","bid":"8168.03","ask":"8168.04","volume":"19043.68798076","time":"2018-03-16T13:10:13.305000Z"}

But my app gives me a User- Agent error??? cg@DESKTOP-6G081A7 MINGW64 ~/documents $ node app.js { message: 'User-Agent header is required.' }

what am I doing wrong, or what and how do I set the User-Agent Header... isn't that done automatically in the browser

2 Answers

Chris Grazioli
Chris Grazioli
31,225 Points
//app.js
const https = require('https');

//https://api.gdax.com/products/BTC-USD/ticker
//https://teamtreehouse.com/chrisgrazioli.json
function get(){
  const request = https.get('https://api.gdax.com/products/BTC-USD/ticker', response =>{
    let body='';
    response.on('data', chunk=>{
      body += chunk.toString();
    }).on('end', ()=>{
      let quote = JSON.parse(body);
      //console.log(quote.points.JavaScript);
      console.log(quote);
;    });
  });
};

get();
Chris Grazioli
Chris Grazioli
31,225 Points

Andrew Chalkley Any ideas on what might be going on here?