#Can a cron triggered function have a default method and set of query params?

4 messages · Page 1 of 1 (latest)

crimson whale
#

I want a function to be triggered by cron every 24 hours. But I want to give it some query params and change the method to POST. The params don't have to be dynamic but are necessary for the function. Is this possible?

harsh kiln
# crimson whale I want a function to be triggered by cron every 24 hours. But I want to give it ...

Hmm not this specifically, but you can check the cause of execution and then either duplicate your code, find smart way to re-use it, or override values coming into the function. For example, that could look like

export default async ({ req, res, log, error }) => {
  if(req.headers['x-appwrite-trigger'] === 'schedule') {
    req.method = 'DELETE';
    req.path = '/my-custom-path';
    // ...
  }

  // Your code ...
}
#

Personally I wouldn't recommend to go with code snippet above, feels like a hack. I would recommend to extract data from req above the if, and inside, override your variables.

low lodge