HubSpot / hubspot-api-ruby

HubSpot API Ruby Client Libraries for V3 version of the API
Apache License 2.0
113 stars 56 forks source link

#to_i called on Hash in Crm::Lists::CollectionResponseLong #324

Open WillRogers727 opened 4 months ago

WillRogers727 commented 4 months ago

I'm getting an error using the gem when trying to use the lists membership API.

The specific call I'm using when I get this error is api_client.crm.lists.memberships_api.get_page(list_id: list_id) (The ID points to a list of companies)

This returns the error:

NoMethodError: undefined method 'to_i' for an instance of Hash

which comes from lib/hubspot/codegen/crm/lists/models/collection_response_long.rb:161

It looks like it's passing the _deserialize method the type :Integer for the values in the results array, when in fact these are hashes:

{:results=>
  [{:recordId=>"8408223219", :membershipTimestamp=>"2024-01-23T14:25:53.413Z"},
   {:recordId=>"9761188042", :membershipTimestamp=>"2024-01-25T15:09:03.463Z"},
   {:recordId=>"9761188073", :membershipTimestamp=>"2024-01-25T15:10:34.354Z"},
   {:recordId=>"9761188282", :membershipTimestamp=>"2024-01-25T15:11:04.134Z"},
   {:recordId=>"9761188298", :membershipTimestamp=>"2024-01-25T15:11:28.765Z"},
   {:recordId=>"9762715614", :membershipTimestamp=>"2024-01-25T15:09:17.499Z"}],
 :total=>6}

More specifically, the method is called on the line lib/hubspot/codegen/crm/lists/models/collection_response_long.rb:137

self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })

where $1 is Integer

This has ultimately come from the Hubspot::Crm::Lists::CollectionResponseLong#openapi_types method:

  def self.openapi_types
      {
        :'paging' => :'Paging',
        :'results' => :'Array<Integer>'
      }
  end

Updating this method like this seems to fix the issue:

def self.openapi_types
      {
        :'paging' => :'Paging',
        :'results' => :'Array<Hash<String, String>>',
      }
end

Though I'm not sure if there are any edge cases this might break.

Let me know if you need any other info to replicate this.

Thanks!

michaelscruz commented 3 weeks ago

+1