• Resolved cheatingdanger

    (@cheatingdanger)


    I am trying to fetch product information via an API call. I have 270 products and I get 270 fetched (in 3 pages 100, 100 and 70). But I have duplicate items. 8 products appear twice in the list. As a result 8 items are missing from the expected list. I have the correct number returned but with duplications some info is missing. It is like the duplication is using up the slots where the missing products should belong. I am wondering if this is a pagination issue? Anyone come across something like this?

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

    (@conschneider)

    Engineer

    Hi there,

    I am wondering if this is a pagination issue? Anyone come across something like this?

    This does not ring a bell so I am gonna leave the thread open to see if anybody has seen this before.

    But I have duplicate items. 8 products appear twice in the list. As a result 8 items are missing from the expected list.

    If you expect 270 products and your answer has 270 products. How do you know there are duplicates? Are 8 products being returned twice while another 8 products are completely missing from the list?

    Kind regards,

    Thread Starter cheatingdanger

    (@cheatingdanger)

    Hi Con a11n
    
    We have 270 products on the website. Each with a unique product id. They are viewable on the site with stock levels and price values. Normal, straight forward everything as you would expect. If I perform a product export as csv all 270 products show up as expected.
    
    If I run an API GET call I received products which are output to a spreadsheet. The spreadsheet has 270 lines/products. I was doing VLOOKUP’s on the ID's and 8 products were missing values. I ran a search and those product ID's had no match they don't appear in the retrieved data. I could not understand how I got the right number of items (270) but 8 products were not included. I then searched duplicates and found 8 products appearing in the list twice. I keep getting this result. 
    
    I can see no relation between which products are duplicated or the ones that are missing. They are not next to each other in the list, they are not neighbours in product ID. They not falling over the page break or due to some offset setting as far as I can tell.
    Plugin Support con

    (@conschneider)

    Engineer

    Hi @cheatingdanger,

    If I run an API GET call I received products which are output to a spreadsheet. The spreadsheet has 270 lines/products. I was doing VLOOKUP’s on the ID’s and 8 products were missing values. I ran a search and those product ID’s had no match they don’t appear in the retrieved data. I could not understand how I got the right number of items (270) but 8 products were not included. I then searched duplicates and found 8 products appearing in the list twice. I keep getting this result.

    Gotcha, that additional info helps. Let’s try some poking around.

    * Pick 2-3 of the products that are not included and being pushed by duplicates.

    Can you find them when doing this request: https://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-a-product ?

    * Pick 2-3 of the products that are showing up as duplicates.
    * Open phpmyadmin and search for the product IDs. Do you get more than one result?

    Kind regards,

    Thread Starter cheatingdanger

    (@cheatingdanger)

    * Pick 2-3 of the products that are not included and being pushed by duplicates.

    Can you find them when doing this request: https://woocommerce.github.io/woocommerce-rest-api-docs/#retrieve-a-product ?

    I am able to find them this way. The correct product is fetched and clearly exists.

    * Pick 2-3 of the products that are showing up as duplicates.
    * Open phpmyadmin and search for the product IDs. Do you get more than one result?

    Under wp_posts and wp_postmeta I could not find any duplication. A search sometimes found 4 hits but browsing the results would show 1 of the results to have the matching product id in the “ID column” with the expected product name in “post title”. The other matches were not duplications but tags or category matches.

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    Thanks for replying to those questions.

    It sounds like something happens when data is passed via API to your spreadsheet. By the way, how do you output the product list to a spreadsheet? What tool are you using?

    It would be a good idea to use a free tool called Postman to list all products (https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-products) and check if you encounter the same problem. If you’re not familiar with Postman there is a tutorial here.

    Best.

    Thread Starter cheatingdanger

    (@cheatingdanger)

    Thank you for this response. I have been playing with postman and can retrieve all products and can’t find duplication. Based on this I don’t think my problem is with WooCommerce or the database. I appreciate the help provided, I am going to fiddle with the other links in the chain. The info is being pulled into Google Sheets and formatted into columns.

    // sheet information
        var header = ['ID', 
                      'Name', 
                      'SKU', 
                      'Price', 
                      'StockQty'];
        var items = [header];

    It is baffling to me that 97% is working as expected and 3% is being weird. Thanks for the help I will have to investigate the other end.

    Mirko P.

    (@rainfallnixfig)

    Sounds like a plan. Thank you for letting us know that you will work on this and dig a little deeper into what is happening to the data pulled into Google Sheets.

    If you have a minute, we’d love if you could leave a review on WooCommerce ??

    https://www.ads-software.com/support/plugin/woocommerce/reviews/

    All the best.

    vanengelen

    (@vanengelen)

    Hello,

    I have the same problem. Except in my case it is actually the API returning duplicates. The id and the sku are identical.
    In the back end of the websop, the product is showing only once. It looks like it has something to do with the pagination. As far as i can see, duplicates are never on the same page. In my case i have the last product on page 2 is repeated as the first product on page 3. The last product on page 3 is repeated as the 2de product on page 4.
    The duplicated products in the API are identical except for the related_ids. They differ in order and items.
    When i export an xml-file containing all the products it only contains one of the duplicates. It also contains the missing products from the API-calls.
    I have tried different page-sizes, but that doesn’t seem to resolve the problem.

    Thanks,

    Hi there @vanengelen ??

    I have the same problem. Except in my case it is actually the API returning duplicates. The id and the sku are identical.

    Thank you for reaching out. For assistance with customization or development with your site, we recommend that you seek help from:

    * A local web developer
    * Codeable.io
    * WooExperts
    * Stackexchange

    If you are comfortable coding yourself and have questions, I would also recommend that you consider:

    * WooCommerce developer Portal
    * WooCommerce Slack Community
    * Advanced WooCommerce Facebook group

    I hope that helps you to figure it out.

    Kindly keep in mind we are not developers and only offer support for existing functionality.

    Please see our Support Policy: https://www.woocommerce.com/support-policy/

    Feel free to get back to us if you have further questions. Thanks!

    • This reply was modified 1 year, 12 months ago by anastas10s. Reason: typo

    We had the same issue with returning several duplicate products and missing exact the same number of other products.

    We resolved issue with adding explicit sort order in URL:

    /wp-json/wc/v3/products?per_page=100&page=1&orderby=id&order=asc
    Saif

    (@babylon1999)

    Hello @hoggarh ,

    I understand you have the same problem but we need to handle each request individually in forums

    Please open your own thread and make sure to include as much information as you can.

    Thank you!

    • This reply was modified 1 year, 8 months ago by Saif. Reason: Sorry, tagged the wrong person. ??
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘API Call Returns Duplicate Products’ is closed to new replies.