Store Orders - Read not permitted

Hi,
i cant access Store Orders data in code from Admin page
i’m getting this error on the logs

“Permission denied: {“message”:“Read not permitted”,“details”:{}}.”

it work in the past with the same code
one day it stop working

as i know Admin should have access to this collection

Thanks

Log out and log back in or try restarting whatever device you are on.

i tried from other PC and same error

You have access to the collection as an admin, but when you use this code, the action performer is the end-user (the one who enter your website) not you. You can overcome this issue by querying the orders collection from the backend and return the query result to the frontend code.

Hi,
i cant query the orders collection also from the backend
i got this error message:

“[“Unhandled rejection Error: Permission denied: {"message":"Read not permitted","details":{}}.\n at errorWithCode (/elementory/g/backend/wix/node_modules/@wix/wix-dis-client/node_modules/@wix/wix-data-core/lib/errors.js:318:15)\n at wixDataError (/elementory/g/backend/wix/node_modules/@wix/wix-dis-client/node_modules/@wix/wix-data-core/lib/errors.js:278:10)\n at createError (/elementory/g/backend/wix/node_modules/@wix/wix-dis-client/src/utils/error-utils.js:40:10)\n at rejectWithError (/elementory/g/backend/wix/node_modules/@wix/wix-dis-client/src/utils/error-utils.js:29:25)\n at mapError (/elementory/g/backend/wix/node_modules/@wix/wix-dis-client/src/utils/error-utils.js:14:14)”]”

Can you show me the code that you’re using on both the backend and the front

@ahmadnasriya sure,
this is my test code:

Backend:

export function testOrder1() {
wixData.query("Stores/Orders")
.find()
.then( (storeresults) => {
let order=storeresults.items[0];
console.log("storeresults: " , order);
})
}

Frontend:

import { testOrder1 } from 'backend/jobs';
export function testOrder_click() {
testOrder1()
}

First of all, you’re not returning the results from the backend to the frontend, so calling the function on the frontend will trigger the function but won’t gets you any results from it.

Also, on your backend code, you’re only logging the first order to the console, not all of them, moreover, you’re NOT using the SupressAuth option to bypass the permissions and that’s why you’re getting a permission error.

@ahmadnasriya its just for testing, this why i’m not return the data
my real code its big, so i created test function

i added the suppressAuth false and still not working
same error

export function testOrder1() {
let options = {"suppressAuth": false};
wixData.query("Stores/Orders",options)
.find()
.then( (storeresults) => {
let order=storeresults.items[0];
console.log("storeresults: " , order);
})
}

@naimibaby Just change the SupressAuth value to true and you’re good to go.

Don’t forget to also include a return word before the query in order to return that query to the frontend code when you call the function.

Also, on your results, you’ll only get the first order, to get all the orders, just remove the [0] from your result section.

Also, I did notice that you’re using the options object in the wrong way, you should pass the options object o the .find() function and not the query itself, doing so will get you a syntax error as well as a permission error, so remove it from the query and only pass it to the .find() function like this .find(options).then( (results) => { }).

Follow all my notes and it should work.

@ahmadnasriya Works!!!
Thanks you Ahmad

@naimibaby You’re welcome my friend, I’ll be happy to help :blush:

Hi,
I run it from the Admin Page:

export function button_Click(event) {
var options = {"suppressAuth": true};
 wixData.query("Stores/Orders")
              .eq("number", Number(item.title))
              .find(options)
              .then( (storeresults) => {
//your code
})
}

What admin page?

The query doesnt allow to apply filtering, so if I use eq, hasSome, contains etc. The query fails, this happens in the backend code, with the authoty already supress. Is it a bug?