I have the following code in a backend module:
export async function getUserInvoices ( currentContactId ) {
wixData . query ( “Billing/Invoices” )
. find ()
. then ( ( results ) => {
console . log ( count: ${ results.length }
);
console . log ( data: ${ JSON . stringify ( results )}
);
return results;
});
}
When I run the function from the backend test harness, it returns all 3 results I can see in the database view.
count: 3
data: {“items”:[{“_id”:“xxxxxxxx-xxxx-40f3-934c-5165e3e580dc”,“version”:38,“status”:“Paid”,“number”:“1100003”,“title”:“”,“currencyCode”:“GBP”,“customer”:{“contactId”:“xxxxxxx-xxxx-4f52-8084-6f6b7d26f998”,“email”:“xxxxxxxx@outlookcom”,“address”:null,“phone”:null,“fullName”:“xxxxx xxxxx”},“wasSent”:true,“total”:1,“paid”:1,“issueDate”:“2021-11-29T00:00:00.000Z”,“dueDate”:“2021-11-29T00:00:00.000Z”,“lastSeenDate”:“2021-11-30T12:37:05.530Z”},{“_id”:“xxxxxxxx-xxxx-437c-86ba-xxxxc8e0xxxx”,“version”:35,“status”:“Paid”,“number”:“0000002”,“currencyCode”:“GBP”,“customer”:{“contactId”:“xxxxxxxx-xxxx-xxxx-b85e-xxxx9537xxxx”,“email”:“xxxx.xxxx@googlemailcom”,“address”:null,“phone”:null,“fullName”:“xxxx xxxx”},“wasSent”:true,“total”:1,“paid”:1,“issueDate”:“2021-11-14T17:13:26.689Z”,“dueDate”:“2021-11-14T17:13:26.689Z”,“lastSeenDate”:“2021-12-07T21:01:51.641Z”,“source”:“xxxxxxxx-xxxx-xxxx-f115-39571d94dfcd”},{“_id”:“xxxxxxxx-xxxx-xxxx-8154-81367ada3399”,“version”:23,“status”:“Paid”,“number”:“0000001”,“currencyCode”:“GBP”,“customer”:{“contactId”:“xxxxxxxx-e6e9-xxxx-xxxx-eb9d953714ba”,“email”:“xxxx.xxxx@googlemailcom”,“address”:null,“phone”:null,“fullName”:“xxxx xxxx”},“wasSent”:true,“total”:1,“paid”:1,“issueDate”:“2021-11-11T17:40:09.161Z”,“dueDate”:“2021-11-11T17:40:09.161Z”,“lastSeenDate”:“2021-11-14T15:03:06.971Z”,“source”:“xxxxxxxx-xxxx-ff05-f115-xxxx1d94xxxx”}],“length”:3,“totalCount”:“3”,“query”:{“invalidArguments”:,“filterTree”:{},“provider”:{},“collectionName”:“Billing/Invoices”,“limitNumber”:50,“skipNumber”:0,“included”:}}
Great, it works.
But if I try to call the same function properly (from a frontend page), like this:
import { getUserInvoices } from ‘backend/Invoices’;
getUserInvoices ( contactId ). then ( function ( invoices ) {
console . log ( invoices );
});
…then I get empty results back when using backend logging, like this:
count: 0
data: {“items”:,“length”:0,“totalCount”:“0”,“query”:{“invalidArguments”:,“filterTree”:{},“provider”:{},“collectionName”:“Billing/Invoices”,“limitNumber”:50,“skipNumber”:0,“included”:}}
I’m comfortable with JS but new to Wix. What’s happening here?
Edit: I’ve confirmed that I can retrieve Members/PublicData records at runtime but not Billing/Invoices records. Are there explicit rules on what can and cannot be accessed?