title: How to convert JSON API images from an API to base64 for display on webpage?
body: <p>I am looking to parse the following page and extract every photo. I am looking to add a picture to the card <a href="http://api.openparliament.ca/politicians/" rel="nofollow noreferrer">http://api.openparliament.ca/politicians/</a>. </p>
  
  <p>I have been following this guide for reference: <a href="https://www.taniarascia.com/how-to-connect-to-an-api-with-javascript/" rel="nofollow noreferrer">https://www.taniarascia.com/how-to-connect-to-an-api-with-javascript/</a> However when it runs, the pictures fail to appear. What am I doing wrong?</p>
  
  <pre><code>(function() {
  const app = document.getElementById('root');
  const container = document.createElement('div');
  container.setAttribute('class', 'container');
  
  app.appendChild(container);
  
  var request = new XMLHttpRequest();
  request.open('GET', 'http://api.openparliament.ca/politicians/?format=json', true);
  request.onreadystatechange = function() {
      if (request.readyState === 4) { 
          if (request.status === 200) {
          var data = JSON.parse(this.response);
          data.objects.forEach(politician =&gt; {
              const card = document.createElement('div');
              card.setAttribute('class', 'card');
  
              const h1 = document.createElement('h1');
              h1.textContent = politician.name;              
  
              const p1 = document.createElement('p');
              p1.textContent = `${politician.current_riding.name.en}, ${politician.current_riding.province}`
              const p2 = document.createElement('p');
              p2.textContent = politician.current_party.short_name.en
  
              const img = document.createElement('img');
              img.src = politician.image
  
              container.appendChild(card);
              card.appendChild(h1);
              card.appendChild(img);                
              card.appendChild(p1);
              card.appendChild(p2);
          });
      } else {
          console.log('error');
      }
  }
  }   
  request.send();
  }());
  </code></pre>