Webhooks to watch contract address and send updates to discord - [partially solved]

Hi - working my way to something more sophisticated - currently I have:

a moralis server on polygon testnet -
moralis dashboard -

cloud function -

Moralis.Cloud.define("Sendnotifications", async (request) =>{
    const logger = Moralis.Cloud.getLogger();

      
    const res = await Moralis.Cloud.httpRequest({
    'method': 'POST',
    url: 'https://discord.com/api/webhooks/WEBHOOKURLREDACTED',
    headers: {
      'Content-Type': 'application/json;charset=utf-8'
    },
      
    params: {
    'content': "beep"
  } 
    
  })
    
    
    logger.info(res);
    
    });

Rather than sending a tx, just using postman to send a message to moralis server through moralis api


Getting a few diff errors, been playing around with the code - either i get

“cant send empty message”

“bad request”

or i can make it work by changing method from POST to GET but this doesnt make sense, and the output runs but it only gives me “{}” and “undefined” in the logs.

If anyone has any tips or sees something your help would be appreciated.

https://docs.moralis.io/moralis-server/cloud-code/httprequest#sending-a-post-request

maybe you have to use that body syntax for a post request

1 Like

Hi :wave: ty for the feedback, the code shown is the just the current iteration but tried it the way you/docs suggested and still get the same output {}

didn’t see that ;charset=utf-8 used before, maybe it is fine

It should work to send a POST request

an example that I think that worked in the past for me:

Moralis.Cloud.define("http_test", async (request) => {
  const logger = Moralis.Cloud.getLogger();
  
  return Moralis.Cloud.httpRequest({
    method:"POST",
    url: "adfasdf",
    
    followRedirects: true,
    body: {
        asdfadfadf: "asfadsfasdf"
      },
    headers: {
       'Content-Type': 'application/json',
       }

  }).then(function(httpResponse) {
    logger.info('Reply...' + JSON.stringify(httpResponse));
    return httpResponse;
  }, function(httpResponse) {
    logger.error('Error...' + JSON.stringify(httpResponse));
    return httpResponse;
  });
})
  
1 Like

Working :stuck_out_tongue: thanks fam!