Job Scheduler has different permission

Hi,
When I setup the jobs.config file to run the function read out the data from “Forum/Posts” ', it doesn’t work due to the permission deny.
I used site monitor and it shows the followings.
‘Error: Permission denied: Insufficient permissions.’
I’ve also tried to run the exact same function in review and site mode. Both of them work well. The test function is as following:

export function testPermission(){
 let options = {
 "suppressAuth": true,
 "suppressHooks": true
    };
  console.log(options);
  wixData.query("Forum/Posts")
  .find(options)
  .then((results) => {
    console.log(results.items[0]);
  });
}

My schedule function is:

// /backend/jobs.config
{
“jobs”: [
{
“functionLocation”: “/tools.jsw”,
“functionName”: “testPermission”,
“description”: “Testing”,
“executionConfig”: {
“time”: “21:54”
}
}
]
}

I suspect it is due to the different mechanism of the job scheduler?
I’m new to wix coding. Does anyone have any idea about how to solve this problem?
Many thanks in advance.

Hello.

It seems the issue is due to the way you are passing options to your query. Try passing the query options as shown below and remove it from it find():

wixData.query("Forum/Posts", options)

Good luck!

Hi Sam, thanks for your reply. I’ve tried this, but it still didn’t work. In addition, I suppose the query function doesn’t accept the ‘options’ argument? https://www.wix.com/corvid/reference/wix-data.html#query
By the way, the only thing I confused was that why the same code works on Review Mode and Site Mode but doesn’t work in Job Schedular.

Did you try it without the suppressAuth? I just ran a job without suppressAuth for a database with admin permissions and it seemed to work ok.

Interestingly I’ve tried it before, but didn’t work. Now it works. Thanks for your mention again.