Extracting token metadata from token_uri

Web3Api.account.getNFTsForContract has been returning null metadata for the past 4/5 days. In the meantime, I’m trying to extract the metadata json object from the IPFS token_uri.
Chain: 0x4, Server subdomain: z62iwqedukzn
This is the cloud function I’m using:

Moralis.Cloud.define("get_token_uri", async (url) => {
        return await Moralis.Cloud.httpRequest({
            url: url,
            headers: {
                method: "GET",
                accept: "application/json",
            },
        })
            .then((httpResponse) => httpResponse.data)
            .catch((error) => logger.info(error));
    });
let tokenList;
    function getData() {
        tokenList = data.result.map(async (token) => {
            let metadata = await Moralis.Cloud.run(
                "get_token_uri",
                token.token_uri
            );
            return { id: token.token_id, metadata };
        });
    }

But here, metadata is returning undefined. How can I actually get the metadata from the token_uri?
ssf

You could add some logging to see what is happening, like logger.info(url) in your cloud function. And also some logging in case of error.
You can also try this example: NFTOwners beforesave function failing after update

1 Like
Moralis.Cloud.define("get_token_uri",(url) => {
  return Moralis.Cloud.httpRequest({
    "url": url,
    "headers": {
        'method': 'GET',
        'accept': 'application/json'
       }
   }).then(function(httpResponse){
    return httpResponse.data;
  },function(httpResponse){
    logger.info("error");
    logger.info(httpResponse);
  });
 });

I tried that example, it’s still returning undefined and this is what I’m getting in the logs:

  • 2021-11-20T14:39:56.304Z - Ran cloud function get_token_uri for user sgRjBIlPwHlNIloeP4T2CGaG with: Input: {} Result: undefined
  • 2021-11-20T14:39:56.303Z -
  • 2021-11-20T14:39:56.302Z - error

I think that you are not reading or/and sending the url parameter the right way

Yeah the value doesn’t seem to be getting passed on properly but I checked the uri parameter and
token.token_uri
does contain the actual uri. So I don’t get why it isn’t getting passed on to the cloud function.

Also is there any ETA for when the metadata property will start generating normally again? It was working perfectly fine until the last 4/5 days.

The syntax may be different to pass a parameter to a cloud function, and also to read it in a cloud function.

I don’t expect to get it fixed this weekend.

Yeah I needed to send the uri in an object. It’s working now.

1 Like