NFTs Error after http requst - help!

I updated server version to 0.0.272 . I am still getting same errors. So code is written right but i need to wait ?

If you run a simple could function like

Moralis.Cloud.define("fetchX", async (request) => {
  return "x";
});

then it works fine for you?

yes it does
image

ok, and if you run “fetchJSON” with a simple url?

It works with some and for some not. Address that has 32 nfts for 29 nfts it was worknig for others not.
Example of working url:

And an example that doesn’t work?


URL: https://api.opensea.io/api/v2/metadata/matic/0x2953399124F0cBB46d2CbACD8A89cF0599974963/0xc73a2bd5ca07bc427fe7140a6720c84ec8daf7a5000000000000280000000064
Maybe it is because of api.opnsea.io ?

maybe, I get {"success": false} when accessing that link from opensea

1 Like

I get the same too. Now that i am looking at failing urls they are mostly (or all) from api.opensea.io and from polygon
@cryptokid

Also if i dont do cloud function but just a normal fetch those opensea urls are working. but some others are blocked by cors that with cloud function are working

This one works for you with normal fetch:
https://api.opensea.io/api/v2/metadata/matic/0x2953399124F0cBB46d2CbACD8A89cF0599974963/0xc73a2bd5ca07bc427fe7140a6720c84ec8daf7a5000000000000280000000064?

Right now it is very late for me so i will try it in 8h when i wake up

It doesn’t. Here is one other url that also doesnt work on fetch neither with httprequest:


URL: https://api.zed.run/api/v1/horses/metadata/62377
And this one is also api.
But if i fetch this url in my function (without trying httprequest) it works - i get img name, …:

async function getSearchNFTs(){

    try{

        let address = await callAPI(document.getElementById('addressInput').value);

        console.log("in nfts, " + address);

        const nfts = await allNFTs(address);

        //Loop over the array

        if(nfts.length == 0){

            alert("Address invalid or it doesn't exist - try different one!")

            $("#searchResults").empty();

            $("#addressOrDomain").html("Address does not exsist, please try with another one!");

            $("#numOfNFTs").html("Address does not exsist, please try with another one!");

            $("#searchResults").html("<strong>Address does not have any NFTs, please try with other Address.</strong>");

            $("#searchResultsDiv").show();

            $("#searchAccordion").show();

        }else{

            $("#searchResults").empty();

            $("#numOfNFTs").val("");

            $("#addressOrDomain").val("");

            nfts.forEach( e => {

                console.log(e);

                let url = e.token_uri;

                console.log(url)

                fetch(url)

                .then(response => response.json())

                .then(data => {

                    console.log(data)

                    let currentDiv = document.getElementById("searchResults");

                    let content = `

                    <div class="card" style="width: 18rem;">

                        <img src="${data.image}" class="card-img-top" id="img" alt="${data.name}">

                        <div class="card-body">

                            <h4 class="card-title">${data.name}</h4><hr>

                            <span class="card-text"><strong>Collection:</strong><span class="data">${e.name}</span><br>

                            <span class="card-text"><strong>Blockchain:</strong><span class="data">${e.chain}</span><br>

                            <span class="card-text"><strong>NFT Type:</strong><span class="data">${e.contract_type}</span></span>

                        </div>

                    </div>

                    `                    

                    currentDiv.innerHTML += content;

                })

            })

            $("#addressOrDomain").html(address + ".");

            $("#numOfNFTs").html((nfts.length -1) + " NFTs.");

            $("#searchResultsDiv").show();

            $("#searchAccordion").show();

        }

    }catch (err) {

        console.log(err);

    }

}

0xff9ffdcfade903f9e8d9bc0b8f530948c05d097d - address i am testing with. It has a lot of those horses which are fetched with function above but not with cloud function httprequest.

https://docs.moralis.io/moralis-server/web3-sdk/token#gettokenidmetadata doesn’t work well for you?

Didnt tried it yet. It should work since i get all nfts in array. Will try it after school.

I still get the same error:

Maybe the problem is in opensea / zedrun or any other api.

For me this URL returns Status Code: 404 and {"success": false} when I put it in the browser. This would mean that it doesn’t work.

You can try https://docs.moralis.io/moralis-server/web3-sdk/token#gettokenidmetadata, maybe it has all the data that you want to fetch.

Yes this gets me all the metadata and info i want but still doesnt work for some:


@cryptokid

What parameters did you use when calling that function?

I dont know they are all inside a loop. But it wokrs for some and for some not.
Looks like it isnt possible to get nft metadata from all nfts.