Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,358 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.