• Resolved vesper1205

    (@vesper1205)


    Hi,
    I’m trying to get a list of all the products using the rest api for WooCommerce. In Postman I get a response. However when I use JavaScript to get the information, I get the ‘401 unauthorized’ error. I’m using HTTP.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Hi there,

    Try sending the authorisation header with (basic auth requires SSL):

    jQuery.ajax({
        url: "https://yoursite.com/wp-json/wc/v3/products",
        type: "GET",
        headers: {
            "Authorization": "Basic (insert base64 credentials here)",
        },
    })
    .done(function(data, textStatus, jqXHR) {
        console.log("HTTP Request Succeeded: " + jqXHR.status);
        console.log(data);
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
        console.log("HTTP Request Failed");
    })
    .always(function() {
        /* ... */
    });

    This code is to illustrate the concept and is not tested.

    Kind regards,

    • This reply was modified 5 years ago by con.
    Luminus Alabi

    (@luminus)

    Automattic Happiness Engineer

    Hi @vesper1205,

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Woocommerce rest api unauthorized using JavaScript’ is closed to new replies.