• Resolved greghains

    (@greghains)


    Hi.

    Whilst I have seen the method to retrieve “?per_page” and “page=” options, I am unable to see how many products are in my store through the API. I know from the dashboard there are 455 but cannot see this via the API.

    I’m happy to run loops to choose a smaller and smaller page size until I no longer get errors but this is not a clean solution.
    Is there a filter/option that I can use to get this information?

    Any help appreciated.
    Thanks,
    Greg

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • con

    (@conschneider)

    Engineer

    Hi there,

    I would either create a custom endpoint that has a small count function as callback for this or maybe make use of the legacy API:

    https://docs.woocommerce.com/document/woocommerce-rest-api/#section-4 + https://woocommerce.github.io/woocommerce-rest-api-docs/v3.html#view-products-count

    Kind regards,

    Thread Starter greghains

    (@greghains)

    Hi Con,

    Thankyou very much for this information – it works just fine.

    What will happen when the Legacy API is switched off? Will there be an equivalent in the current version API? is that on the roadmap, or is there an equivalent one I can use now?

    Cheers,
    Greg

    con

    (@conschneider)

    Engineer

    Hi Greg,

    Thankyou very much for this information – it works just fine.

    Sweet. 👍

    What will happen when the Legacy API is switched off? Will there be an equivalent in the current version API? is that on the roadmap, or is there an equivalent one I can use now?

    Switching off the legacy API will also switch off the endpoint and count function. I haven’t done research on why or where the endpoint has dissipated. I only know that there is no equivalent in the current API.
    I think you will need a custom endpoint if the Legacy API is switched off.

    Kind regards,

    Thread Starter greghains

    (@greghains)

    Hi Con,

    Thanks for the update again.
    I did see on some page that the initial response from the server when making the API call to the products area will have some information in it that includes the count in the text – and this is with the new API. Do you think I can find that article again!? lol.
    Also, not necessarily a question for here, but the custom endpoint you refer to in order to achieve this is a WooCommerce-side right? Is this something a free-lance developer can add to WooCommerce, or would WooCommerce themselves have to?
    Thats how I understand it anyway.

    Cheers,
    Greg

    Plugin Support Damianne P (a11n)

    (@drwpcom)

    Hi @greghains,

    Also, not necessarily a question for here, but the custom endpoint you refer to in order to achieve this is a WooCommerce-side right? Is this something a free-lance developer can add to WooCommerce, or would WooCommerce themselves have to?

    This is something that a free-lance developer would be able to help with. We have a list of services that you can reach out to on our Customizations page.

    Hey @greghains

    Not sure if you’ve managed to do it now but I’ve just encountered the same problem.

    the initial response from the server when making the API call to the products area will have some information in it that includes the count in the text

    The response header does contain the total product count and the total number of pages, presumably based on the per_page you specify. Don’t know what you’re using but I’m using the api through node and the below extracts the product count and page count from the initial response.

    var response = await wooApi.get("products", { 'per_page': 100 });
    var productCount = response.headers['x-wp-total'];
    var pageCount = response.headers['x-wp-totalpages'];
    
    console.log(<code>products: ${productCount}, pages: ${pageCount}</code>);
Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘WooCommerce API – Product Count’ is closed to new replies.