FAQ: Requests I - XHR Post Requests III

This community-built FAQ covers the “XHR Post Requests III” exercise from the lesson “Requests I”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise XHR Post Requests III

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I notice that in helperFunctions.js the function renderRawResponse checks for the value of res.errors and dispays an error message if it’s truthy. Where does the res.errors property come from?


OK, I self-helped.

The reason res.errors is available is because the response is JSON, which is an object, so I can access the value by specifying the key as a property of the object.

For example, if the response was…

{ name: "Terry Gilliam" }

…I could get "Terry Gilliam" via res.name.


Hello all, i put the url in and press shorten, but nothing shows, why? every step is green.


I ran your code, and it works perfectly with my API key. If you haven’t replaced the value of apiKey with your actual key from rebrandly.com, you’ll need to do that. Don’t post it here. API keys are private. If you’ve already tried your code with a valid API key, post a reply, and I’ll have another look, but I don’t see any issues with your code. Good luck!

Thanks, may i know what should be shown on screen if it works? Thanks!

Hello i tried again still no show…

1 Like

I think if you just remove the angle brackets < > from around your api key value, you’ll have it. Keep the quotation marks, but delete the brackets. :slightly_smiling_face:


what a stupid mistake! thank you so much!

and thanks for reminding me keeping api key secret, otherwise i would be spreading around the world :joy:


How does the main,js access the renderResponse fuction in helperFuntion.js here as its not exported in this excercisei

If you look in the index.html file for the exercise, you see these two lines of code near the end of the file just inside the closing body tag:

  <script src="public/main.js"></script>
  <script src="public/helperFunctions.js">

Because both files are linked to the html file, the functions inside of helperFunctions.js are accessible to the functions in main.js.
Check out this thread: Code using function from another file without import / export


is there an alternative to rebrandly? The site doesn’t generate an API key for me - clicking the button does nothing and i’ve tried on several browsers.


Thank you! I had the same ‘problem’ today.

1 Like

I just followed this lesson today, and had the same issue. In my case, I had created my OWN const for the API key. However, there was already a const for the API key defined that said ‘’, or something along those lines. Make sure there aren’t two copies like I had, press “run code” again (this updates the output area), put in your URL, and try again.

This lesson is truly disappointing. I learned nothing. It’s just about copying stuff. Barely anything is explained. A lot of concepts are just thrown at you…


I wish more was explained. I’m trying to piece it together by looking at documentation, but a little more explanation would help direct me instead of fumbling around.


I’m having difficulty to sign up with rebrandly. My account is suspended even its fresh account. Anybody have same case?

if we assigned const xhr = new XMLHttpRequest wouldn’t (xhr.readyState === XMLHttpRequest.DONE) be the same as (xhr.readyState === xhr.DONE)? If not, why?


I have another question.
in XHR GET Requests III step 5 theres .word method that I cant find, were is it?

 // Creates an empty array to contain the HTML strings
  let wordList = [];
  // Loops through the response and caps off at 10
  for(let i = 0; i < Math.min(res.length, 10); i++){
    // creating a list of words

Theres one similar in step 9: .shortUrl ?

const renderResponse = (res) => {
  // Displays either message depending on results
    responseField.innerHTML = "<p>Sorry, couldn't format your URL.</p><p>Try again.</p>";
  } else {  
    responseField.innerHTML = `<p>Your shortened url is: </p><p> ${res.shortUrl} </p>`;

thankfull for answers

Hi all,
Even though I’ve completed the exercise correctly, the application doesn’t do anything after clicking ‘shorten’.
By the I’m having the same issue with the exercise ‘XHR GET Requests IV’.
Absolutely no clue as to what I’m doing wrong.
(since API keys appear to be secret, I replaced it here with XXX)

I’m quite at loss here…

Thanks :slight_smile: !

// Information to reach API

const apiKey = ‘XXX’;

const url = ‘https://api.rebrandly.com/v1/links’;

// Some page elements

const inputField = document.querySelector(’#input’);

const shortenButton = document.querySelector(’#shorten’);

const responseField = document.querySelector(’#responseField’);

// AJAX functions

const shortenUrl = () => {

const urlToShorten = inputField.value;

const data = JSON.stringify({destination: urlToShorten});

const xhr = new XMLHttpRequest;

xhr.responseType = ‘json’;

xhr.onreadystatechange = () => {

if (xhr.readyState === XMLHttpRequest.DONE) {





xhr.setRequestHeader(‘Content-type’, ‘application/json’);

xhr.setRequestHeader(‘apikey’, apiKey);