I get a 401 message woocommerce_rest_cannot_view

63 Views Asked by At

Using Postman with Bearer authorization and using the following URL:

 https://website.nl/wp-json/wc/v3/orders

I get this error message:

{
    "code": "woocommerce_rest_cannot_view",
    "message": "Je kunt gegevensbronnen niet weergeven.",
    "data": {
        "status": 401
    }
}

This is the code I want to use:

function fetchOrderData(orderNumber) {
    return new Promise(function(resolve, reject) {
        var apiUrl = 'https://website.nl/wp-json/wc/v3/orders?order_number=' + orderNumber;
        fetch(apiUrl, {
            headers: {
                'Authorization': 'Bearer token'
            }
        })
        .then(response => {
            if (!response.ok) {
                throw new Error('Failed to fetch order details');
            }
            return response.json();
        })
        .then(orderDetails => {
            if (orderDetails && orderDetails.length > 0) {
                var customerInfo = orderDetails[0].billing;
                resolve(customerInfo);
            } else {
                reject(new Error('Order not found'));
            }
        })
        .catch(error => {
            console.error('Error fetching order data:', error);
            reject(error);
        });
    });
}

The user is the 'shopmanager' with the Bearer authorization. No specific settings set in Woocommerce. I make use of a nginx server.

I checked many things like: Bearer Token, token permissions, API Endpoint URL, API version, plugin conflicts, etc.

How can i solve the 401 error? Looking forward for the solution.

0

There are 0 best solutions below