1

I've deployed my Node.js Koa API app on Heroku. I'm making a call to a USAJOB.gov API and it works on my localhost. However, on Heroku I get this error:

You don't have permission to access "http://data.usajobs.gov/$(SERVE_403)/api/search?" on this server.

Here is my Koa router snippet:

router.get('/jobs', async (ctx) => {
  const { keyword, location } = ctx.query;
  const url = `https://data.usajobs.gov/api/search? 
    Keyword=${keyword}&LocationName=${location}`;
  const host = 'data.usajobs.gov';
  const userAgent = '<redacted>';
  const authKey = '<redacted>';
  const headers = {
    Host: host,
    'User-Agent': userAgent,
    'Authorization-Key': authKey,
  };

  await fetch(url, {
  headers,
  method: 'GET',
  });
}
Uy Hoang
  • 191
  • 1
  • 3
  • 8

1 Answers1

2

So it turns out that whether or not cross-site Access-Control requests should be made using credentials was what was the issue. I wasn't able to figure out how to configure that with node-fetch but once I read the the solution (link below), switched to axios, configured withCredentials: true, and added headers: { 'X-Requested-With': 'XMLHttpRequest' }, then it all worked.

Source: axios delete method gives 403

Uy Hoang
  • 191
  • 1
  • 3
  • 8