Using HTTP Cloud Functions as URI endpoint for NFT metadata

Hello,

I would like to use Moralis Cloud Function as an endpoint for my NFT metadata. This needs to return a precisely formatted JSON.

My cloud function look like this:

Moralis.Cloud.define("tokenURI", async (request) => {
  const nftObject = Moralis.Object.extend("newNFTProposals");
  const query = new Moralis.Query(nftObject);
  query.equalTo("nftID", request.params.param1);
  const result = await query.first();
  const parsedResult = JSON.parse(JSON.stringify(result));
  const metadata ={
    "name": parsedResult.name,
    "description": parsedResult.description,
    "image": parsedResult.ipfs,
  };
  return metadata;
});

This almost works, except HTTP requests to the Cloud Functions returns as follows:

{ "result": { "name": "ARTIS", "description": "ArtisLife Network Token", "image": "https://ipfs.moralis.io:2053/ipfs/QmXY8MdL2kLDp7PgVEPMv5cD1XTinzpqDEpXHtK84yW8nk" } }

The desired result is:

{"name":"ARTIS","description":"ArtisLife Network Token","image":"https://ipfs.moralis.io:2053/ipfs/QmXY8MdL2kLDp7PgVEPMv5cD1XTinzpqDEpXHtK84yW8nk"}

Is there a way I can bypass the “result” object and return the metadata directly?

Thank you,
Adrian

The format is fixed like that for HTTP requests. I don’t think we can change that as of now.

Thank you for your reply. I will use a wrapper function from Google Cloud to accomplish this for now.

If considered in the future, you can have a separate type of Cloud Function that returns the raw result and not the result object.

For now, the Google Cloud workaround will be just fine. :+1:

Thanks.

2 Likes