Invoke API from Timer

I have a Timer setup as below. Is this the correct way to invoke a Cloud Code API from the Cloud Code Timer?

If I use the Invoke API function using the frontend JS API then it works fine, however it will not call from the Timer function

Backendless.ServerCode.addTimer({
  name: 'doMyTask',
  startDate: 1649746493042,
  frequency: {
    schedule: 'custom',
    repeat: {'every':60}
  },

  /**
  * @param {Object} req
  * @param {String} req.context Application Version Id
  */
  execute(req){
    Backendless.APIServices.invoke('someClass', 'someFunction')
    .then(function(d){
      console.log("DONE")
    })
  }

Hello @Tony_Goodchild!

You are doing everything correctly, but you need to use async/await to make it work:


Backendless.ServerCode.addTimer({
  name: 'doMyTask',
  startDate: 1649746493042,
  frequency: {
    schedule: 'custom',
    repeat: {'every':60}
  },

  /**
  * @param {Object} req
  * @param {String} req.context Application Version Id
  */
  async execute(req) {
    await Backendless.APIServices.invoke('someClass', 'someFunction')
      .then(res => console.log(res))
      
    console.log('DONE')
  }
});

Regarads,
Alexander

Thanks @Alexander

1 Like