Can somebody explain how the Product Search API works?

Hubspot’s docs do a terrible job explaining how to use the Seach API for products. In their example they have filterGroups, filters, value, and values - but no explanations that I can find on what those do/what values should go in them.

import hubspot
from pprint import pprint
from hubspot.crm.products import PublicObjectSearchRequest, ApiException

client = hubspot.Client.create(access_token="YOUR_ACCESS_TOKEN")

public_object_search_request = PublicObjectSearchRequest(filter_groups=[{"filters":[{"value":"string","values":["string"],"propertyName":"string","operator":"EQ"}]}], sorts=["string"], query="string", properties=["string"], limit=0, after=0)
try:
 api_response = client.crm.products.search_api.do_search(public_object_search_request=public_object_search_request)
 pprint(api_response)
except ApiException as e:
 print("Exception when calling search_api->do_search: %s\n" % e)

I assume “value” would be the value you want to search for (like the name of a product), but then what do you put in values? I tried just doing value but got an error “…problem: value and values are mutually exclusive”

import hubspot
from pprint import pprint
from hubspot.crm.products import PublicObjectSearchRequest, ApiException

client = hubspot.Client.create(access_token="YOUR_ACCESS_TOKEN")

public_object_search_request = PublicObjectSearchRequest(filter_groups=[{"filters":[{"value":"E60-82-007-04-01","values":[],"propertyName":"name","operator":"EQ"}]}], sorts=["name"], properties=["id"], limit=0, after=0)
try:
 api_response = client.crm.products.search_api.do_search(public_object_search_request=public_object_search_request)
 pprint(api_response)
except ApiException as e:
 print("Exception when calling search_api->do_search: %s\n" % e)

hey @eibach-cv

yes it’s working perfect check the code below using php curl

getProductID();

function getProductID()

{

$curl = curl_init();

curl_setopt_array($curl, array(

CURLOPT_URL => ‘https://api.hubapi.com/crm/v3/objects/products/search?hapikey=’ . HUBSPOT_API,

CURLOPT_RETURNTRANSFER => true,

CURLOPT_ENCODING => ‘’,

CURLOPT_MAXREDIRS => 10,

CURLOPT_TIMEOUT => 0,

CURLOPT_FOLLOWLOCATION => true,

CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

CURLOPT_CUSTOMREQUEST => ‘POST’,

CURLOPT_POSTFIELDS =>'{

"filters": \[

    {

        "value": "property\_value",

        "propertyName": "hs\_sku",

        "operator": "EQ"

    }

]

}',

CURLOPT_HTTPHEADER => array(

'authorization: Bearer YOUR\_ACCESS\_TOKEN',

'Content-Type: application/json'

),

));

$response = curl_exec($curl);

curl_close($curl);

}

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

For python users, I was able to get the Search API working for Products with this

public_object_search_request = PublicObjectSearchRequest(filter_groups=[{"filters":[{"value":"Product SKU HERE","propertyName":"hs_sku","operator":"EQ"}]}], sorts=["name"], properties=["hs_object_id"], limit=1, after=0)
 try:
	api_response = client.crm.products.search_api.do_search(public_object_search_request=public_object_search_request)