Deal Search API Ignoring Filter Groups (Ruby)

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.

For example, all of my HubSpot API calls get sent to one of these methods:

 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}&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}&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}&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}&hapikey=#{@hubspot_api_key}", body)
 JSON(response.body)
 end

so if I want to fetch the deals for a particular company, here’s what I call:

 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

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.

Hope this helps!