TheStingPilot
TheStingPilot

Reputation: 64

WooCommerce REST API does not show all the products

I have a webshop with products in 4 languages. When I try to receive the full list of products, I do not see all the products. Only the products in the Dutch language (the 'main' language) and not the products that are not published yet.

The code:

  Clear-Host
  $ConsumerKey            = "ck_blablahalblah"
  $CustomerKey            = "cs_somethingelse"
  $URL                    = "https://www.mywebshopurl.nl"
  $Products               = "/wp-json/wc/v3/products"
  $URL                    = "$($url)$($Products)"
  $Headers                = @{Authorization = "Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $ConsumerKey, $CustomerKey))) }
  [Int]$Page              = 1
  [Int]$PerPage           = 10
  $ArrayWithProducts      = @()
  Do
   {
    Write-Host "Reading products from page: $Page"
    $AllProducts       = Invoke-RestMethod -Method Get -Uri "$($URL)?page=$Page&per_page=$PerPage&status=any&orderby=id&order=asc&catalog_visibility=any" -Headers $Headers
    Write-Host "  -->> Counted $($AllProducts.Count) products on page $Page."
  
    If (-not $AllProducts) {Break}
    $ArrayWithProducts += $AllProducts

    $Page++
   } While ($True)
    
   Write-Host "There are total $($ArrayWithProducts.Count) products discovered by the REST API."

I only see 149 products. That are 147 published products and 2 draft products. But I do not see:

  1. All the items that already have been imported but not published yet. The status is 'Draft'.
  2. All the with WPML translated products.

As a reference I already checked WooCommerce Rest API not returning Products and woocommerce rest api - did not show product list. I also checked https://woocommerce.github.io/woocommerce-rest-api-docs/?javascript#product-properties.

What can I do to solve points one and two.

Feedback is appreciated and with kind regards, TheStingPilot

Upvotes: 0

Views: 34

Answers (0)

Related Questions