Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

403 error with axios but works on postman and browser

I get Nfts on magic eden with this third party api. http://api-mainnet.magiceden.io/rpc/getGlobalActivitiesByQuery?q=%7B%22%24match%22%3A%7B%22txType%22%3A%22initializeEscrow%22%2C%22blockTime%22%3A%7B%22%24gt%22%3A1643468983%7D%7D%2C%22%24sort%22%3A%7B%22blockTime%22%3A-1%7D%7D

It responses with results on postman and browser but causes 403 error with axios in node.js.

How can I get data in node.js?

 const res = await axios.get(
    'http://api-mainnet.magiceden.io/rpc/getGlobalActivitiesByQuery?q=%7B%22%24match%22%3A%7B%22txType%22%3A%22initializeEscrow%22%2C%22blockTime%22%3A%7B%22%24gt%22%3A1643468983%7D%7D%2C%22%24sort%22%3A%7B%22blockTime%22%3A-1%7D%7D',  
    { 
      headers : {
        "Content-Type": "application/json",
        "Access-Control-Allow-Credentials": "*"
      }
    }
  );
  return res.data;
like image 666
David Nasaw Avatar asked Sep 20 '25 10:09

David Nasaw


1 Answers

Using a proxy here won't help as they have Cloudflare protection set up against bots/scripts and it requires cookies to be present: screenshot 1, screenshot 2

You should get in touch with their support and ask for the API key (they have a public API v2 coming soon), and then use it in Authorization: Bearer <token>

Few things to note here: Their API v2 is still in works and lacks some basic features. Using their current v1 API does not require having an API key (that's what their support personnel said) but it does have bot protection against scripted attacks.

I'm hesitant to go with the API v2 since it lacks even the most basic stuff and I don't expect it to come out anytime soon. Personally, I'm looking to get in touch with people who managed to integrate the v1 into their applications, to see what necessary steps they followed in order to be able to do it.

If you managed to find some new info on that regard let me know. I'll also edit this comment in case I find out how to set up the v1 connection properly.

EDIT: managed to get it working by using the https://github.com/puppeteer/puppeteer library. Started a small headless instance of Chrome and I hit the ME API with that browser like so: screenshot 3

like image 76
Josip Volarević Avatar answered Sep 22 '25 07:09

Josip Volarević



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!