WooCommerce-REST-API-Client-Library icon indicating copy to clipboard operation
WooCommerce-REST-API-Client-Library copied to clipboard

HTTP Headers & Pagination

Open jaythegeek opened this issue 9 years ago • 1 comments

I cannot for the life of me access any of the HTTP Headers. If I activate the debugging I can see them at the end of the returned data. I cannot access them in anyway, I cannot return them on their own. I have looked through the class-wc-api-client-http-request file to see if there is an error. I then tried using $headers and various other ways of accessing the data. I have scoured the Internet for help and suggestions. I am fairly savvy with code but cannot figure this out. If someone has an example of how to access specifically the X-WC-TotalPages data for pagination I would be immensely grateful!

jaythegeek avatar Apr 11 '16 16:04 jaythegeek

Hey Memerance

I have updated the WC_API_Client_HTTP_Request class to return the two header responses for total objects and total pages. I added these two lines to the class file:

$parsed_response->num_pages = $this->response->headers['X-WC-TotalPages']; $parsed_response->num_objects = $this->response->headers['X-WC-Total'];

The response now includes this data and I can act on it within my script. Hope this helps.

bradyounger avatar May 26 '16 22:05 bradyounger