[SOLVED] Moralis.Cloud.httpRequest sends undefined request body

I am calling Moralis.Cloud.httpRequest in my cloud function

Moralis.Cloud.define("myCloudFunc", async (request) => {
		method: 'POST',
		url: 'https://f38c-49-96-33-106.jp.ngrok.io',
		body: {
			title: 'Vote for Pedro',
			body: 'If you vote for Pedro, your wildest dreams will come true'

Ngrok redirects the post call that includes a body to my local dev server whose code looks like

const app = express()

app.post('/', (req, res) => {
  res.send({'success': true})

The console output for req.body from my local server is undefined

How can I solve this?

try also the second example from https://docs.moralis.io/moralis-dapp/cloud-code/httprequest#sending-a-post-request

where you set the headers

Setting the headers doesn’t change. Request’s body is still undefined.

can you test it with postman to see that the server works as expected?

can you also log the entire req object?

Thank you very much!
It turns out I need to include
in the server backend.

1 Like

I have similar issue with “https://min-api.cryptocompare.com/data/price?fsym=btc&tsyms=usd
It returns a valid result when I visit directly in the browser.

Don’t know if there’s a way to solve it since the API is an external service.

This works on my end.

Moralis.Cloud.define('nobledsmarts', async (request) => {
  return Moralis.Cloud.httpRequest({
    url: 'https://min-api.cryptocompare.com/data/price?fsym=btc&tsyms=usd',
  }).then((httpResponse) => httpResponse.data);

Yeah, working now. I was initially calling the API within my code, I called it now as a function and it seems to do the trick.
Thanks :+1: