I’m getting this error, but not sure why:
2022 - 09 - 01 T22: 09: 01.146 Z - afterSave failed for AuctionCreated for user:
Input: {
“log_index”: 238,
“transaction_hash”: “0xd0b76e0b490ba96611c6598db62907701c80d253665a7647289b5281bf84027e”,
“createdAt”: “2022-09-01T22:05:11.907Z”,
“updatedAt”: “2022-09-01T22:09:01.116Z”,
“address”: “0x55e0f7a3bb39a28bd7bcc458e04b3cf00ad3219e”,
“block_hash”: “0xd624f6684b4e65ede6367a018454ad1997f0d3bc82aa30877a1ff814eccb0359”,
“block_number”: 15455394,
“block_timestamp”: {
“__type”: “Date”,
“iso”: “2022-09-01T22:04:39.000Z”
},
“confirmed”: true,
“endTime”: “1662070779”,
“endTime_decimal”: {
“__type”: “NumberDecimal”,
“value”: “1662070779”
},
“nounId”: “5519”,
“nounId_decimal”: {
“__type”: “NumberDecimal”,
“value”: “5519”
},
“startTime”: “1662069879”,
“startTime_decimal”: {
“__type”: “NumberDecimal”,
“value”: “1662069879”
},
“transaction_index”: 131,
“objectId”: “d4A4GTwbYsnw1Fhf4yQ1drUP”
}
Error: {
“message”: “data is not defined”,
“code”: 141
}
This is the cloud function (based on the one from the Moralis video tutorial):
const logger = Moralis.Cloud.getLogger();
logger.info("Hello World");
Moralis.Cloud.afterSave("AuctionCreated", async (request) => {
const confirmed = request.object.get("confirmed");
const nounId = request.object.get("nounId");
let msg = `New Auction Started for Lilnoun ${nounId}`;
if(confirmed){
let data = {
app_id: "***********************************",
contents: {"en": "Notification"},
included_segments: ["Subs Email"],
name: "Email",
email_body: msg,
email_subject: "New Auction"
}
}
Moralis.Cloud.httpRequest({
method: "POST",
url: "https://onesignal.com/api/v1/notifications",
body: data,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic **************************************************'
}
})
})
Server:
https://witiy4l01xiz.usemoralis.com:2053/serverPreformatted text