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(
            return { id: token.token_id, metadata };

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

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'
    return httpResponse.data;

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
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

Could you write what that looked like? I’m just starting today with the NFT programming tutorial and there is no metadata, so having this to look at when I get to the same point might be really helpful, thank you!

Instead of passing the token_uri directly to the cloud function, I made the uri a property of a param object and then passed the param object to the cloud function. As shown here: https://docs.moralis.io/moralis-server/cloud-code/cloud-functions#calling-cloud-functions