Search code examples
salesforcesalesforce-commerce-cloud

SFCC OCAPI ProductSearch API - Returning ALL Products


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.


Solution

  • 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.