woocommerce / woocommerce-rest-api-js-lib

New JavaScript library for WooCommerce REST API
https://www.npmjs.com/package/@woocommerce/woocommerce-rest-api
MIT License
286 stars 75 forks source link

Critical: Response Body Is Empty #72

Closed markschellhas closed 4 years ago

markschellhas commented 4 years ago

Appears empty when using the orders call. As you see, I get Satus, Headers (incl. vlaues "x-wp-total" and "x-wp-totalpages") but response.data is totally empty.

I've tried this "orders" endpoint using Postman and a straight axios implementation, both with Basic Auth and with keys as query params in the url, but on the /orders endpoint I'm always getting data empty.

NOTE: We've had this issue since 16 June. Then when I swapped out my axios implementation to using this module instead (woocommerce-rest-api) it worked for a couple of requests yesterday evening. But now it doesn't at all!

Are there API request limits? Please help as our app is down as a result of this.

Request

const api = new WooCommerceRestApi({
            url: url,
            consumerKey: consumerKey,
            consumerSecret: consumerSecret,
            version: "wc/v3"
        });

        api.get("orders", {
            after: today,
            before: endOfToday
        })
            .then((response: any) => {
                // Successful request
                console.log("Response:", response);
                console.log("Response Status:", response.status);
                console.log("Response Headers:", response.headers);
                console.log("Response Data:", response.data);
                console.log("Total of pages:", response.headers['x-wp-totalpages']);
                console.log("Total of items:", response.headers['x-wp-total']);
                resolve(response.data);
            })
            .catch((error: any) => {
                // Invalid request, for 4xx and 5xx statuses
                console.log("Response Status:", error.response.status);
                console.log("Response Headers:", error.response.headers);
                console.log("Response Data:", error.response.data);
                reject(error);
            });

Response

Response Status: 200
>  Response Headers: {
>    connection: 'close',
>    'x-powered-by': 'PHP/7.2.31',
>    'content-type': 'application/json; charset=UTF-8',
>    'x-robots-tag': 'noindex',
>    'x-content-type-options': 'nosniff',
>    'access-control-expose-headers': 'X-WP-Total, X-WP-TotalPages',
>    'access-control-allow-headers': 'Authorization, Content-Type',
>    expires: 'Wed, 11 Jan 1984 05:00:00 GMT',
>    'cache-control': 'no-transform, no-cache, no-store, must-revalidate',
>    'x-wp-total': '34',
>    'x-wp-totalpages': '4',
>    link: '<https://not-real-domain.com/wp-json/wc/v3/orders?after=2020-06-17T00%3A00%3A00.000Z&before=2020-06-17T23%3A59%3A59.999Z&status%5B0%5D=any&dp=0&page=2>; rel="next"',
>    allow: 'GET, POST',
>    'content-length': '0',
>    date: 'Fri, 10 Jul 2020 05:44:59 GMT',
>    server: 'LiteSpeed',
>    vary: 'User-Agent,User-Agent',
>    'alt-svc': 'quic=":443"; ma=2592000; v="43,46", h3-Q043=":443"; ma=2592000, h3-Q046=":443"; ma=2592000, h3-Q050=":443"; ma=2592000, h3-25=":443"; ma=2592000, h3-27=":443"; ma=2592000'
>  }
>  Response Data: 
>  Total of pages: 4
>  Total of items: 34
climba03003 commented 4 years ago

I think the issue is related to your wordpress site instead of this module. This module is only the wrapper of axios.

markschellhas commented 4 years ago

@climba03003 Is there a way to know or find out? Can there be better error responses? If there was a wordpress site issue, meaning that WooCommerce isn't reachable via API, the response body wouldn't be returning a valid response (empty array), but an error (500 for example). Also all the other endpoints are working, so this seems strange that only the 'orders' endpoint has an issue (if it's a WP issue)?

Better error responses would really be helpful.

climba03003 commented 4 years ago

All of the result are comes from wordpress site ( even error message ). If the response is empty, you should check if any plugin have modify the woocommerce endpoint result. You should disable all the other plugin ( except woocommerce ) to see if the response still empty.

markschellhas commented 4 years ago

@climba03003 Thanks for the response, even though this is what I was hoping I would not have to do :) I'll close this issue now.