<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Deal Search API Ignoring Filter Groups (Ruby) in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/469734#M45484</link>
    <description>&lt;P&gt;When using the example for `Post /crm/v3/objects/deals/search` from the docs at&amp;nbsp;&lt;A href="https://developers.hubspot.com/docs/api/crm/deals" target="_blank" rel="noopener"&gt;https://developers.hubspot.com/docs/api/crm/deals&lt;/A&gt;&amp;nbsp;I can test call and get the expected results. However, when pasting into my own code, my response always includes all deals with none of the specified filtering.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using Ruby, but I experimented with the cURL and Python options too. cURL returns the expected response, but the Python option required some edits to the sample code (the import statement was incomplete.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, I'm wondering if the docs are generating an incomplete sample code, but running the complete code behind the scenes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code the docs are showing me to use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;require 'hubspot-api-client'

Hubspot.configure do |config|
  config.api_key['hapikey'] = 'YOUR_HUBSPOT_API_KEY'
end

public_object_search_request = Hubspot::Crm::Deals::PublicObjectSearchRequest.new(filter_groups: [{"filters":[{"value":"true","propertyName":"ready_to_bill","operator":"EQ"}]}], sorts: ["descending"], properties: [["dealname","ready_to_bill"]], limit: 1, after: 0)
begin
  api_response = Hubspot::Crm::Deals::SearchApi.new.do_search(public_object_search_request: public_object_search_request, auth_names: "hapikey")
  puts api_response
rescue Hubspot::Crm::Deals::ApiError =&amp;gt; e
  error_message = JSON.parse(e.response_body)['message']
  puts error_message
end&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone experienced this and come up with a fix? Would it be better to open an issue on the code in GitHub? I'm not able to tell if it's the sample code, or the ruby-api-client that's the problem.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jul 2021 15:29:46 GMT</pubDate>
    <dc:creator>LeeStetson</dc:creator>
    <dc:date>2021-07-30T15:29:46Z</dc:date>
    <item>
      <title>Deal Search API Ignoring Filter Groups (Ruby)</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/469734#M45484</link>
      <description>&lt;P&gt;When using the example for `Post /crm/v3/objects/deals/search` from the docs at&amp;nbsp;&lt;A href="https://developers.hubspot.com/docs/api/crm/deals" target="_blank" rel="noopener"&gt;https://developers.hubspot.com/docs/api/crm/deals&lt;/A&gt;&amp;nbsp;I can test call and get the expected results. However, when pasting into my own code, my response always includes all deals with none of the specified filtering.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using Ruby, but I experimented with the cURL and Python options too. cURL returns the expected response, but the Python option required some edits to the sample code (the import statement was incomplete.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, I'm wondering if the docs are generating an incomplete sample code, but running the complete code behind the scenes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code the docs are showing me to use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;require 'hubspot-api-client'

Hubspot.configure do |config|
  config.api_key['hapikey'] = 'YOUR_HUBSPOT_API_KEY'
end

public_object_search_request = Hubspot::Crm::Deals::PublicObjectSearchRequest.new(filter_groups: [{"filters":[{"value":"true","propertyName":"ready_to_bill","operator":"EQ"}]}], sorts: ["descending"], properties: [["dealname","ready_to_bill"]], limit: 1, after: 0)
begin
  api_response = Hubspot::Crm::Deals::SearchApi.new.do_search(public_object_search_request: public_object_search_request, auth_names: "hapikey")
  puts api_response
rescue Hubspot::Crm::Deals::ApiError =&amp;gt; e
  error_message = JSON.parse(e.response_body)['message']
  puts error_message
end&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone experienced this and come up with a fix? Would it be better to open an issue on the code in GitHub? I'm not able to tell if it's the sample code, or the ruby-api-client that's the problem.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 15:29:46 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/469734#M45484</guid>
      <dc:creator>LeeStetson</dc:creator>
      <dc:date>2021-07-30T15:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Deal Search API Ignoring Filter Groups (Ruby)</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/469844#M45491</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/62148"&gt;@altjx&lt;/a&gt; , &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/81433"&gt;@GaryElliott&lt;/a&gt;&amp;nbsp; any thoughts here?&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/220328"&gt;@LeeStetson&lt;/a&gt; , feel free to add an issue to the repo if there is indeed an issue &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 17:48:41 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/469844#M45491</guid>
      <dc:creator>dennisedson</dc:creator>
      <dc:date>2021-07-30T17:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Deal Search API Ignoring Filter Groups (Ruby)</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/472997#M45630</link>
      <description>&lt;P&gt;Honestly I gave up on the HubSpot API Client gem for Ruby. I built my own wrapper around the types of calls that I would be making to HubSpot API through GET, POST, PATCH, and PUT requests.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, all of my HubSpot API calls get sent to one of these methods:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;  def get_request(url)
    url.gsub!('https://api.hubapi.com/crm/v3/', '') if url.include? 'https://api.hubapi.com/crm/v3/'
    response = @web.get_request("https://api.hubapi.com/crm/v3/#{url}&amp;amp;hapikey=#{@hubspot_api_key}")
    JSON(response.body)
  end

  def put_request(url)
    url.gsub!('https://api.hubapi.com/crm/v3/', '') if url.include? 'https://api.hubapi.com/crm/v3/'
    response = @web.put_request("https://api.hubapi.com/crm/v3/#{url}&amp;amp;hapikey=#{@hubspot_api_key}")
    JSON(response.body)
  end

  def post_request(url, body)
    url.gsub!('https://api.hubapi.com/crm/v3/', '') if url.include? 'https://api.hubapi.com/crm/v3/'
    response = @web.post_request("https://api.hubapi.com/crm/v3/#{url}&amp;amp;hapikey=#{@hubspot_api_key}", body)
    JSON(response.body)
  end

  def patch_request(url, body)
    url.gsub!('https://api.hubapi.com/crm/v3/', '') if url.include? 'https://api.hubapi.com/crm/v3/'
    response = @web.patch_request("https://api.hubapi.com/crm/v3/#{url}&amp;amp;hapikey=#{@hubspot_api_key}", body)
    JSON(response.body)
  end&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so if I want to fetch the deals for a particular company, here's what I call:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;  def find_existing_deal(company)
    response = {}
    deals = get_request("objects/companies/#{company.hubspot_id}/associations/deals?limit=500")
    unless deals['results'].empty?
      # Find the deal that has a DealType of XYZ
      deals['results'].each do |result|
        deal_id = result['id']

        # Retrieve deal details
        get_response = get_request("objects/deals/#{deal_id}?properties=dealtype")
        if get_response['properties']['dealtype'].blank?
          SlackBot.new.send_message(
            "Error updating HubSpot! #{company.name} does not have a dealType assigned to their deal. Please update this deal manually.", '#sales'
          )
          SlackBot.new.send_message(
            "You can access this deal at the following URL: https://app.hubspot.com/contacts/4512633/deal/#{deal_id}", '#sales'
          )
          exit(0)
        end
        next unless ['New Business','Existing Business'].any? do |a|
                      a.include? get_response['properties']['dealtype']
                    end

        response = get_response
        break
      end
    end

    response
  end&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;may not necessarily be the cleanest, but I've been able to get this implemented pretty much all over app avoiding the api-client and its limitations or confusions.&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 02:03:22 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/472997#M45630</guid>
      <dc:creator>altjx</dc:creator>
      <dc:date>2021-08-05T02:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: Deal Search API Ignoring Filter Groups (Ruby)</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/473768#M45690</link>
      <description>&lt;P&gt;Thanks! I removed the api-client dependency myself and implemented something similar to what you've shared.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll probably still open an issue in Github, but it's really not important right now since I'm only working on a script with a fairly small scope.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 19:21:35 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/473768#M45690</guid>
      <dc:creator>LeeStetson</dc:creator>
      <dc:date>2021-08-05T19:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Deal Search API Ignoring Filter Groups (Ruby)</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/476023#M45793</link>
      <description>&lt;P&gt;The issue was found in the 'hubspot-api-client' gem:&lt;/P&gt;&lt;P&gt;The search API method accepts filterGroups parameter,&lt;/P&gt;&lt;P&gt;however PublicObjectSearchRequest class accepts it only and exactly like this: filter_groups, which is ignored in backend (search API method).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example of non-working ruby code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;request = Hubspot::Crm::Contacts::PublicObjectSearchRequest.new(
  filterGroups: [ { 'filters': [ {
                   'value': 'someemail@example.com',
                   'propertyName': 'email',
                   'operator': 'EQ'
   } ] } ], sorts: ['id'], properties: ['id'], limit: 1, after: 0)

Hubspot::Crm::Contacts::SearchApi.new.do_search(public_object_search_request: request, auth_names: 'hapikey')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Returns error:&lt;/P&gt;&lt;P class="p1"&gt;&lt;FONT face="andale mono,times"&gt;&lt;SPAN class="s1"&gt;ArgumentError: `filterGroups` is not a valid attribute in `Hubspot::Crm::Contacts::PublicObjectSearchRequest`. Please check the name to make sure it's valid. List of attributes: [:filter_groups, :sorts, :query, :properties, :limit, :after]&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another non-working example (implemented exactly as it is in the documentation, pay attention to &lt;STRONG&gt;filter_groups&lt;/STRONG&gt; parameter):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;request = Hubspot::Crm::Contacts::PublicObjectSearchRequest.new(
  filter_groups: [ { 'filters': [ {
                   'value': 'someemail@example.com',
                   'propertyName': 'email',
                   'operator': 'EQ'
   } ] } ], sorts: ['id'], properties: ['id'], limit: 1, after: 0)

Hubspot::Crm::Contacts::SearchApi.new.do_search(public_object_search_request: request, auth_names: 'hapikey')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Returns all existing contacts (ignoring search filter).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current solution is to write your own layer for requests (&lt;FONT face="andale mono,times"&gt;gem 'rest-client'&lt;/FONT&gt; works well for that)&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 16:50:44 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Deal-Search-API-Ignoring-Filter-Groups-Ruby/m-p/476023#M45793</guid>
      <dc:creator>AGlyatsevich</dc:creator>
      <dc:date>2021-08-09T16:50:44Z</dc:date>
    </item>
  </channel>
</rss>

