Error saving on IPFS

Hi, I have and error saving data on IPFS using Moralis.EvmApi.ipfs.uploadFolder.
I send data from javascript using axios.post to my backend in node.js
This is my abi:

[
  {
    path: 'metadata.json',
    content: {
      PlotID: '0xca060fe0631114c2392bbf43b75b10a3006b2562588b58cb8b4abb7b9895b9fd',
      PlotX: '5',
      PlotY: '7',
      LocationX: '500',
      LocationY: '700',
      imageHash: 'Qmar3TbD4SJCVomEHYADm8gjtmM4Zz2C9DJvRLhse9KQLH',
      imageIpfs: 'https://ipfs.moralis.io:2053/ipfs/Qmar3TbD4SJCVomEHYADm8gjtmM4Zz2C9DJvRLhse9KQLH/0xca060fe0631114c2392bbf43b75b10a3006b2562588b58cb8b4abb7b9895b9fd.png'
    }
  }
]

and this is what I get

C:\myproject\Api\node_modules\express\lib\response.js:1150
: JSON.stringify(value);
^

TypeError: Converting circular structure to JSON
ā€“> starting at object with constructor ā€˜ClientRequestā€™
| property ā€˜socketā€™ -> object with constructor ā€˜TLSSocketā€™
ā€” property ā€˜_httpMessageā€™ closes the circle
at JSON.stringify ()
at stringify (C:\myproject\Api\node_modules\express\lib\response.js:1150:12)
at ServerResponse.json (C:\myproject\Api\node_modules\express\lib\response.js:271:14)
at ServerResponse.send (C:\myproject\Api\node_modules\express\lib\response.js:162:21)
at exports.savePlotToIPFS (C:\myproject\Api\moralis\moralis.controller.js:304:21)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

It worked days ago, then suddenly stopped

Any suggestion???
Thanks

Usually you could get an error like this one when you have an object instead of a string as parameter for a function

Ok, but this is a snippet from documentation

const abi = [
    {
      path: "YOUR_FILE_PATH",
      content: "YOUR_JSON_OR_BASE64",
    },
  ];

If I try using btoa(JSON.stringify(MYJSON)) I get same error

you can try it directly in docs interface:

In docs interface it works, if I use window.btoa(JSON.stringify(MYJSON))

In my code no, this is the abi I pass to Moralis function

[
  {
    path: 'metadata.json',
    content: 'eyJQbG90SUQiOiIweDUzNTk0MTU4NDNlMjcwOTBkOWFlZTU1NjU3MTNmYjE5ZDhiNGM3M2Y4M2E5YjBkMWNjY2M3ZjBkZDQ1OThhMWIiLCJQbG90WCI6IjExIiwiUGxvdFkiOiI0IiwiTG9jYXRpb25YIjoiMTEwMCIsIkxvY2F0aW9uWSI6IjQwMCIsImltYWdlSGFzaCI6IlFtTmpSY2l0OWNkOVBQU1pjZjhISkZqRVB1RVFkWGhjS0g2WFlZbmVnNHY1bmQiLCJpbWFnZUlwZnMiOiJodHRwczovL2lwZnMubW9yYWxpcy5pbzoyMDUzL2lwZnMvUW1OalJjaXQ5Y2Q5UFBTWmNmOEhKRmpFUHVFUWRYaGNLSDZYWVluZWc0djVuZC8weDUzNTk0MTU4NDNlMjcwOTBkOWFlZTU1NjU3MTNmYjE5ZDhiNGM3M2Y4M2E5YjBkMWNjY2M3ZjBkZDQ1OThhMWIucG5nIn0='
  }
]

Try with only a string maybe?
Can you add some logging to see what you send in that request?

Trying to send just a string (ā€œsā€) converted in base64, so window.btoa(ā€œsā€) in the content I get this error

{ā€œresā€:ā€œKOā€,ā€œmsgā€:{ā€œnameā€:ā€œMoralis SDK Errorā€,ā€œisMoralisErrorā€:true,ā€œcodeā€:ā€œC0005ā€}}

what part of this input you are trying to convert it to base64?

The content is a json like that some message above stringified and converted in base64
Something like this

const data = {
    path: 'metadata.json',
    content: {
      PlotID: '0xca060fe0631114c2392bbf43b75b10a3006b2562588b58cb8b4abb7b9895b9fd',
      PlotX: '5',
      PlotY: '7',
      LocationX: '500',
      LocationY: '700',
      imageHash: 'Qmar3TbD4SJCVomEHYADm8gjtmM4Zz2C9DJvRLhse9KQLH',
      imageIpfs: 'https://ipfs.moralis.io:2053/ipfs/Qmar3TbD4SJCVomEHYADm8gjtmM4Zz2C9DJvRLhse9KQLH/0xca060fe0631114c2392bbf43b75b10a3006b2562588b58cb8b4abb7b9895b9fd.png'
    }
  }

content: window.btoa(JSON.stringify(data))

The thing I canā€™t figure it out is that if I call my node function that call Moralis ipfs uploaf function with Insomnia (software like postman) it works, within my frontend javascript no

How you can see within the content thereā€™s an ipfs.moralis link so this function works, but somehow this call doesnā€™t work

it looks like this is the part that should e converted be string and than to base64

Yes, sorry, my previous message was wrong, I convert into string and then base64 that json you wrote above that is the content value

Can you share a complete code that doesnā€™t work?

Yes, this is the code
Frontend

//here I initialize the json and pass to a function
		const metadata = {
			"PlotID": plotID.toString(),
			"PlotX": land.tile.x.toString(),
			"PlotY": land.tile.y.toString(),
			"LocationX": land.absPosition.x.toString(),
			"LocationY": land.absPosition.y.toString(),
			"imageHash": land.imageHash.toString(),
			"imageIpfs": land.imageIpfs.toString()
		}

		const metadataFile = await savePlotDataToIPFS(metadata);


//function
async function savePlotDataToIPFS(metadata) {
	const params = {
		ppath: "metadata.json",
		pcontent: window.btoa(JSON.stringify(metadata))
	}

	const res = await handleApiPost('moralis/save-plot', params);

	if (res.res == "OK")
		return res.msg;
	else
		return null;
}


//function
const handleApiPost = async (endpoint, params) => {
	const result = await axios.post(`${serverUrl}/${endpoint}`, params, {
		headers: {
			'Content-Type': 'application/json',
		},
	});

	return result.data;
};

Here is my Backend

exports.savePlotToIPFS = async (req, res) => {

  //check the req body
  if (!req.body) {
    res.status(400).send({
      res: "KO",
      msg: "No data"
    });
    return;
  }
   const abi = [
     {
       path: req.body.ppath.toString(),
       content: req.body.pcontent.toString()
     },
   ];

  try {
    const response = await Moralis.EvmApi.ipfs.uploadFolder({
         abi
    });

    res.status(200).send({
      res: "OK",
      msg: {
        "ipfs": response.jsonResponse[0].path,
        "hash": response.jsonResponse[0].path.split('/')[4]
      }
    });

  } catch(err){
    res.status(400).send({
      res: "KO",
      msg: err
    });
  }
}

Thatā€™s all

Try to add some logging here to see that is the value for that abi

Here you may have to send the parameters as a string

Using JSON.stringify same errorā€¦

try to add some logging with console.log for the parameters

Now I get error in authentication function Moralis.Auth.requestMessage

this is the payload

{
    "address": "0x4e6b9ae717c34d8f0047f1c40e6459fa6b25d381",
    "chain": "0x1",
    "network": "evm",
    "DOMAIN": "dc3.space",
    "STATEMENT": "Please sign this message to confirm your identity.",
    "URI": "https://dc3.space/dc3land",
    "EXPIRATION_TIME": "2024-01-01T00:00:00.000Z",
    "TIMEOUT": 30
}

and this is the issue

{
ā€œresā€: ā€œKOā€,
ā€œmsgā€: {
ā€œnameā€: ā€œMoralis SDK Errorā€,
ā€œisMoralisErrorā€: true,
ā€œcodeā€: ā€œC0005ā€
}
}

Iā€™ve updated Moralis version to 2.18.0

Is there something wrong with your SDK?

the same syntax worked before?

there keys have to be in uppercase?

This is the payload to my node function that calls Moralis.Auth.requestMessage

const result = await Moralis.Auth.requestMessage({
      address: paddress,
      chain,
      network,
      domain: req.body.DOMAIN,
      statement: req.body.STATEMENT,
      uri: req.body.URI,
      expirationTime: req.body.EXPIRATION_TIME,
      timeout: req.body.TIMEOUT,
    });

Yes, same syntax worked before