[SOLVED] Trying to use web3api with a server url instead of api url

Hey

Our company is testing Moralis out for the game we releasing soon.

However we encoutering issues doing the tests. We setup a server correctly however while testing it looks like the server have CORS blocked - which is odd since i’d never be hosting the website in the same place the Moralis server is.

This is my request headers:

Accept: application/json, text/plain, */*
Access-Control-Allow-Origin: *
Referer: http://localhost:8080/
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
X-API-Key: <secret api key>

Error:

Access to XMLHttpRequest at 'https://ndhgwzieszb8.usemoralis.com:2053/server/0x7Ac410F4E36873022b57821D7a8EB3D7513C045a/nft' from origin 'http://localhost:8080' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.
xhr.js:187          GET https://ndhgwzieszb8.usemoralis.com:2053/server/0x7Ac410F4E36873022b57821D7a8EB3D7513C045a/nft net::ERR_FAILED

I have CORS enabled in my browser and in the website via meta tags - also adding Access-Control-Allow-Origin header but it seems not working. Is there something being missed here ?

Thanks !

if you want to use web3api, then there is a different way to use web3api

you can start by looking on this page and trying some endpoints there directly
https://admin.moralis.io/web3Api

Sorry i don’t understand how that would help solving CORS, would you care to elaborate ?

From that page it works because it’s the same domain im assuming, it won’t work for when testing because it’s different domains.

can you explain what are you trying to do there?

what is the code that you run?

what is the expected output from that url?

I’m trying to do a GET request to the Moralis server api that lists NFT’s. The request is on the initial post including all relevant data as headers.

The expected output from that URL can be seen in the api swagger you just linked to me :slight_smile:

Example using swagger api you provided:

{
  "total": 1,
  "page": 0,
  "page_size": 500,
  "cursor": "",
  "result": [],
  "status": "SYNCED"
}

However, when doing the same post request from other domains, the request is being blocked by CORS.

ok, try to read my previous response, this is not how you use web3api

you will have to use the url that we see in swagger interface to make those GET requests, not the server url, you have there a CURL example that also includes the url

Ok now i understood. Id suggest you mentioning the URL was wrong as opposed to referring to “web3api” because this has nothing to do with web3 from a user perspective as we are simply calling an external API.

The URL provided by the video tutorials (https://ndhgwzieszb8.usemoralis.com:2053/server) is actually not the one i should be using but https://deep-index.moralis.io/api/v2 instead.

That solved the issue. Thanks.

web3api is not same thing as web3