I want to acces to the last order info message: 'Permission denied: Forbidden' details: applicationError: description: Forbidden code: PERMISSION_DENIED data: {}

Anyone know how i can acces to the id and the buyer name in my site via Velo ? I have been searching for 2 days now and i cant find a thing

this back end was almost working but not i dont have acces??

import { orders } from "wix-ecom-backend";
import { elevate } from "wix-auth"; 

// Fonction pour récupérer la dernière commande
export async function getLatestOrder() {
    try {
        // Élever les permissions pour avoir accès aux commandes
        await elevate();

        // Récupérer la dernière commande du site
        const query = await orders.queryOrders()
            .descending("createdDate")  // Trier par date de création (descendant)
            .limit(1)  // Limiter à la dernière commande
            .find();

        // Vérification si une commande a été trouvée
        if (query.items.length === 0) {
            return { error: "Aucune commande trouvée." };
        }

        const latestOrder = query.items[0];

        // Retourner les informations pertinentes de la commande
        return {
            orderId: latestOrder._id,
            buyerName: latestOrder.buyerInfo.firstName + " " + latestOrder.buyerInfo.lastName,
            buyerEmail: latestOrder.buyerInfo.email,
            paymentStatus: latestOrder.paymentStatus,  // Exemple de statut de paiement
            totalPrice: latestOrder.priceSummary.totalPrice.formattedAmount  // Exemple de prix total
        };
    } catch (error) {
        // Capturer et retourner les erreurs si quelque chose échoue
        return { error: error.message };
    }
}

Hi, @Joe_Beaupre !!

For now, I have some doubts about how elevate() is being used. :smiling_face_with_sunglasses: Isn’t it supposed to be used by passing a function inside it? Try referring to the link below! :raised_hands: