'Why does this private API call not work when called via Node.js?

I'm trying to replicate a private network call on this website programmatically via Node.js, by going into Chrome Dev Tools > Network tab > Copy > Copy as Node.js fetch, but it returns this HTML, saying access is denied.

My question is, why is the request successful when it is called officially via the website, but not via Node.js? Is there a way to get around this?

Here is my code:

import fetch from 'node-fetch';

const res = await fetch("https://api.opensea.io/graphql/", {
  "headers": {
    "accept": "*/*",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "en-US,en;q=0.9",
    "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "x-api-key": "<API_KEY>",
    "x-build-id": "af5847cff28dea69d3df70effe0e3d719326c0e9",
    "x-signed-query": "a30d9c6dc5cee1500ea03fd7eceef335312518b426d858ca8d2aafa6422eb240",
    "cache-control": "no-cache",
    "content-length": "4864",
    "content-type": "application/json",
    "cookie": "<COOKIES>",
    "Referer": "https://opensea.io/",
    "pragma": "no-cache",
    "origin": "https://opensea.io",
    "Referrer-Policy": "strict-origin",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36",
  },
  "body": "<QUERY>",
  "method": "POST"
});

console.log(await res.text());


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source