Action on event created in Wix events

Hello,

I start with Wix but I discover that it’s really very complete!

I’m trying to do a little integration, I just want to post on an third party application the information of a wix event when it’s created.

Following what I understood from the documentation, I created an events.js file in backend folder with test http post.

But nothing happens when I create an event in dashboard. I tried my code on an OnClick button and it works.

So I guess I haven’t quite figured out how to trigger this code when an event is created.

events.js (backend)

export function wixEvents_onEventCreated(event) {
let eventId = event.eventId;
let title = event.title;
fetch( “https://url…” , {
“method” : “post” ,
“headers” : {
“Content-Type” : “application/x-www-form-urlencoded”
},
“body” : “somekey=somevalue”
} )
.then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject( “Fetch did not succeed” );
}
} )
.then( (json) => console.log(json.someKey) )
. catch (err => console.log(err));
}

Best regards,

David.

I just tried this code to see what’s going on in the console.

export function wixEvents_onEventCreated(event) {
let eventId = event.eventId;
let title = event.title;
console.log( “Event Fired” );

}

export function wixEvents_onEventUpdated(event) {
let eventId = event.eventId;
let title = event.title;
console.log( “Event Fired” );

}

Console :

“root”: {

“insertId”: “…4ZTlCcMDGAZ7GSzSxfKqy6”
“timestamp”: “2020-05-25T12:24:35.009Z”

“labels”: { “siteUrl”: “https://disordermultigamin.wixsite.com/disorder
“revision”: “182”
“namespace”: “Corvid”
“tenantId”: “5f55e4d0-b861-4297-bfa5-b1a1b35b29fd”
“viewMode”: “Site”
}

“sourceLocation”: {}

“operation”: { “id”: “1590409474.533102915975619613286”
“producer”: “backend”
}

“jsonPayload”: { “message”: “[“Cannot read property ‘lat’ of undefined”]”
}
“severity”: “ERROR”
“receiveTimestamp”: “2020-05-25T12:24:35.012Z”
}