Events backend - Order confirmed not firing?

Hi,

I wanted to push the confirmed ticket data to another database through the newly released events api. But my events backend code is not firing.

Tried to just get the event ID as a starting case, but even that is not logging in to the database.

Is there any issue with the same? https://www.wix.com/corvid/reference/wix-events-backend.Events.html#onOrderConfirmed

Added this in the events.js backend file. And ran this on a live website.

import wixData from 'wix-data';
import wixEventsBackend from 'wix-events-backend';
import wixEvents from 'wix-events'; 

export function wixEvents_onOrderConfirmed(event) {
 let eventId = event.eventId; 

 let toInsert = {
 "log":    eventId
  };
 

wixData.insert("foo", toInsert) //
  .then( (results) => {
 let item = results; //see item below
    } )
    .catch( (err) => {
 let errorMsg = err;
    } );

  }

Let me know your opinions. Thanks.

1 Like

Get this error from the backend for the code below. Any suggestions?

root": {

“insertId”: “…41B9yvYx8BEfPJbVeaLJmz”
“timestamp”: “2020-05-25T12:16:02.909Z”

“labels”: { “siteUrl”: “https://jaosh8.wixsite.com/samplewixwebsite
“revision”: “213”
“namespace”: “Corvid”
“tenantId”: “bbf09b25-aa18-4060-ab03-6c866d2a7548”
“viewMode”: “Site”
}

“sourceLocation”: { “file”: “backend/events.js”
“line”: 6
“column”: 1
}

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

“jsonPayload”: { “message”: “[“Error loading web module backend/events.js: Cannot find module ‘wix-events’\nRequire stack:\n- /user-code/backend/events.js\n- /user-code/stubmodule-that-does-the-require.js\n- /elementory/node_modules/scoped-require/index.js\n- /elementory/create-app.js\n- /elementory/cloud-grid-runner.js”]”
}
“severity”: “ERROR”
“receiveTimestamp”: “2020-05-25T12:16:02.933Z”
}

The code was

// Place this code in the events.js file
// of your site's Backend section.
import wixData from 'wix-data';
import wixEvents from 'wix-events';
import wixEventsBackend from 'wix-events-backend';


export function wixEvents_onEventCreated(event) {
 let eventId = event.eventId;
 let title = event.title;
  console.log("event created");
}

You do not need to import wixEvents or wixEventsBackend . Just remove them and it will work.

import wixData from 'wix-data';

export function wixEvents_onOrderConfirmed(event) {
    let eventId = event.eventId;
    let toInsert = {
        "title": eventId
    };
    wixData.insert("foo", toInsert)
    .then( (results) => {
         let item = results;
    })
    .catch( (err) => {
         let errorMsg = err;
    });
}

Thanks for that. It should be made clear in the API library I feel.