SFCC OCAPI ProductSearch API - Returning ALL Products

723 views Asked by At

I am attempting to retrieve products from SFCC, using the following API:

https://developer.salesforce.com/docs/commerce/b2c-commerce/references/ocapi-data-api?meta=Search%2BProducts

However, this API only appears to return 25 records, or up to 200 records if you include the "count":200 attribute. Is there any way to return ALL products at once?

This is my request payload I'm sending:

{
  "query": {"term_query": {
            "fields": ["c_optionsID"],
            "operator": "is_not_null"
        }},
  "select": "(hits.(c_optionsID,c_exitProduct))",
  "sorts": [
    {
      "field": "creation_date",
      "sort_order": "asc"
    }
  ]

}

This request returns only 25 records. I assume it may be technically possible to run the API search multiple times, and increment the "start" attribute by 25 each time, however this seems like an inefficient way to do it.

2

There are 2 answers

0
callum202 On BEST ANSWER

I was able to find a way to do this. I am able to use the 'Get Product Inventory Records' API endpoint:

https://{{Domain}}/s/-/dw/data/v23_2/inventory_lists/{{InventoryListID}}/product_inventory_records?select=(data.(stock_level, perpetual_flag,product_id))&count=30000

This endpoint returns all products for a specified Inventory List, and doesn't appear to have a limit on the number of records returned. It's not exactly the same as querying the product master, as it assumes that each product belongs to this inventory list, but it works for my purposes.

0
Maher Nabil On

There is no direct way to return all products which is logical since some catalogs contain hundreds of thousands of products. Instead, you can use the SCAPI:

https://developer.salesforce.com/docs/commerce/commerce-api/references/products?meta=searchProducts

The API has a limit of 200 and an offset value to paginate the total hits.