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 Node.js Basics Building a Command Line Application Requesting data with https

Kelby Nylander
seal-mask
.a{fill-rule:evenodd;}techdegree
Kelby Nylander
Full Stack JavaScript Techdegree Student 9,455 Points

getting a 401 statusCode with an unauthorized message

const https = require("https");
function getProfile() {
    // Connect to the API URL (https://teamtreehouse.com/csalgado.json)
    const request = https.get(
        "https://teamtreehouse.com/csalgado.json",
        (response) => {
            console.dir(response.statusCode);
        }
    );
    // Read the data
    // Parse the data
    // Print the data
}
getProfile();

I followed the video along and wrote the code but I am getting a 401 status code saying unauthorized. I even tried to change the user to my profile name and got the same message. Am I doing something wrong in my code or is something else going on?

Kelby Nylander
seal-mask
.a{fill-rule:evenodd;}techdegree
Kelby Nylander
Full Stack JavaScript Techdegree Student 9,455 Points

I solved this issue on my own and wanted to share in case anyone else has the same issue. The file path for the URL is incomplete and should be "https://teamtreehouse.com/profiles/csalgado.json" once I changed the URL it worked as expected.

Sean Gibson
Sean Gibson
38,363 Points

Kelby Nylander thanks for pointing out the simple solution. That probably saved me a significant amount of time. Thanks again!

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hi Kelby Nylander,

Thanks a lot for bringing this to our attention! The routes have recently changed and redirects are in place to visit your actual profile page but have not yet been implemented to do the same on the JSON responses. We've filed a ticket to our IT team to fix this issue.

Sorry for any inconvenience this has caused.