1

I am try to do a technical test for an interview and have hit a snag with fetching some data from an API. The error message im getting is this:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Here is my request:

function handleErrors(response) {
  if (!response.ok) {
    throw Error(response.statusText);
  }
  return response;
}

fetch('https://rss.itunes.apple.com/api/v1/us/apple-music/top-albums/all/100/non-explicit.json', {
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Content-Type": "application/json"
    }
  })
    .then(handleErrors)
    .then((response) => response.json())
    .catch((e) => {
      throw Error(e);
    });

After googling the issue the majority of answers seem to suggest you need to add: Access-control: Allow-Origin to the resource to enable CORS. I obviously don't have access to do that on iTunes API so I am wondering if there is another way around it.

The get request works fine in postman and returns me the data that I need so i'm wondering if it's one of my request headers thats not being set properly?

Apparently other people have managed to complete the test so i'm quite sure there is something wrong with my request.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
red house 87
  • 1,837
  • 9
  • 50
  • 99
  • Does [How to parse an RSS feed using JavaScript (External Domain)?](https://stackoverflow.com/q/51647764/3688864) help? – Shoejep Nov 14 '20 at 08:30

0 Answers0