API request with headers

I need to add an API key to my request but it returns an error. Do you know why I can’t use Headers?

var url = "https://api.iopool.com/v1/pools";
var headers = new Headers();

headers.append('x-api-key', 'myKey);

fetch(url, headers)
  .then(response => response.json())
  .then(data => console.log(data));

:x: Script Error
:warning: ReferenceError: Headers is not defined
at API Iopool.js:2:15
at processTicksAndRejections (node:internal/process/task_queues:96:5)

fetch(url, {
  headers : {
    'x-api-key': myKey

See last example here.

1 Like

Yes thank you ! There was one missing } :wink:

fetch(url, { headers : { 'x-api-key': apiKey }})
  .then(response => response.json())
  .then(data => console.log(data));

I am also trying to setup a script from my IoPool. Could you share your full script ? Mine is… not so efficient :slight_smile: