Trent Ungard
Trent Ungard
10,347 Points

301 error on Treehouse API calls using HTTPS

Hello everyone,

I'm experiencing a bizarre error. When I make a request to${username}.json over https, I get a 301 response saying the resource has been moved. I know that this isn't the case, because putting the url for my profile into my browser returns the JSON. I'm using a template literal so it's not an issue with the string I've pasted above, as I've console.logged my url to be sure. I also have another program that uses https to make calls to the treehouse API and it's working fine.

I found other topics from 2015 about when treehouse transitioned from http to https for the API, but as I mentioned, I'm definitely using HTTPS. Hopefully this is just something simple that I'm overlooking but it's driving me crazy. Any help would be appreciated. This is using the node .get method. Thank you!

const https = require('https');
const username = 'trentungard';
const url = `${username}.json`;

const getJSON = () => {
        https.get(url, (res) => {
            if(res.statusCode === 200){
                // some code
            } else {
                // some other code
    } catch(res) {


1 Answer

Trent Ungard
Trent Ungard
10,347 Points

Amazing! Thank you so much1