APIs & Integrations

khandekyn
Participant

ruby client get_by_id yields "User no implicit conversion of Symbol into Integer"

SOLVE

the current ruby client seems to be generated from a swagger description.

 

fetching company details with get_by_id seems broken though. i'm not managing to get it working. listing all companies works fine for your info. 

 

i keep hitting this error "no implicit conversion of Symbol into Integer" . i wen't looking in the source but i don't seem to find the source. the code is not trivial to read as it's generated code.

 

if anyone knows how to get company details with the latest ruby gem code for a given id, please share 🙂 

 

 

0 Upvotes
1 Accepted solution
ChrisMagtoto
Solution
Member

ruby client get_by_id yields "User no implicit conversion of Symbol into Integer"

SOLVE

Hey, I just created my ruby environment and tested this which returned the data for a the specified company id.

api_response = api_client.crm.companies.basic_api.get_by_id(company_id: 7559743199)

PLEASE rotate your access token as you revealed it in your reply which I used to retrieve a sample and test my ruby code.

View solution in original post

0 Upvotes
5 Replies 5
ChrisMagtoto
Member

ruby client get_by_id yields "User no implicit conversion of Symbol into Integer"

SOLVE

Are you passing the id as an integer or a string?

Try passing the id as a string:
id = "{id}"

0 Upvotes
khandekyn
Participant

ruby client get_by_id yields "User no implicit conversion of Symbol into Integer"

SOLVE
i actually tried all possible variants

123
“123”
id: “123”
id: 123
{id: 123}
{id: “123”}


see below for actual outputs.
from that output it seems te system really expects just 1 argument (which i can’t read in the code) and it needs to be a primitive string or int, because the code generation tries to load an inexistent class in the other cases.

i also tried for several ruby versions: 3.0, 3.2 … same results

regards
koen



```
irb(main):001> c = Hubspot::Client.new(access_token: ENV["HUBSPOT_ACCESS_TOKEN"])
=> #<:client:0x000000010761a780>"pat-eu1-8e5f2c79-11e9-4bc1-9678-7708c19ab0b2"}>
irb(main):002> c.crm.companies.basic_api.get_by_id(1)
/Users/koenhandekyn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/hubspot-api-client-17.2.0/lib/hubspot/discovery/base_api_client.rb:135:in `[]': no implicit conversion of Symbol into Integer (TypeError)

params_with_defaults[:opts] ||= {}
^^^^^^^^^^^^^
irb(main):003> c.crm.companies.basic_api.get_by_id("1")
/Users/koenhandekyn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/hubspot-api-client-17.2.0/lib/hubspot/discovery/base_api_client.rb:135:in `[]': no implicit conversion of Symbol into Integer (TypeError)

params_with_defaults[:opts] ||= {}
^^^^^^^^^^^^^
irb(main):004> c.crm.companies.basic_api.get_by_id(id: 1)
<>:38:in `require': cannot load such file -- hubspot/codegen/crm/companies/models/company_id (LoadError)
irb(main):005> c.crm.companies.basic_api.get_by_id(id: "1")
<>:38:in `require': cannot load such file -- hubspot/codegen/crm/companies/models/company_id (LoadError)
irb(main):006> c.crm.companies.basic_api.get_by_id({id: "1"})
<>:38:in `require': cannot load such file -- hubspot/codegen/crm/companies/models/company_id (LoadError)
irb(main):007> c.crm.companies.basic_api.get_by_id({id: 1})
<>:38:in `require': cannot load such file -- hubspot/codegen/crm/companies/models/company_id (LoadError)
irb(main):008> c.crm.companies.basic_api.get_by_id(1, opts: {})
/Users/koenhandekyn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/hubspot-api-client-17.2.0/lib/hubspot/discovery/base_api_client.rb:133:in `block (2 levels) in define_api_methods': wrong number of arguments (given 2, expected 0..1) (ArgumentError)
irb(main):009> c.crm.companies.basic_api.get_by_id(1, {})
/Users/koenhandekyn/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/hubspot-api-client-17.2.0/lib/hubspot/discovery/base_api_client.rb:133:in `block (2 levels) in define_api_methods': wrong number of arguments (given 2, expected 0..1) (ArgumentError)
```
0 Upvotes
ChrisMagtoto
Member

ruby client get_by_id yields "User no implicit conversion of Symbol into Integer"

SOLVE

This is Ruby right? If yes, then base on the documentation this is the correct syntax:

api_client.crm.companies.basic_api.get_crm_v3_objects_companies_company_id(company_id: "123", archived: false)

0 Upvotes
khandekyn
Participant

ruby client get_by_id yields "User no implicit conversion of Symbol into Integer"

SOLVE
thanks for the tip but just tried but getting an undefined method error
i’m calling it on the basic_api object

undefined method `get_crm_v3_objects_companies_company_id' for #<:discovery::crm::companies::basicapi:0x0000000106fff7d8>"pat-eu1-8e5f2c79-11e9-4bc1-9678-7708c19ab0b2"}, @codegen_api_path="hubspot/codegen/crm/companies/basic_api", @codegen_module_name="Hubspot::Crm::Companies", @codegen_module_path="hubspot/codegen/crm/companies", @config=#<:crm::companies::configuration:0x0000000106f1c820>
0 Upvotes
ChrisMagtoto
Solution
Member

ruby client get_by_id yields "User no implicit conversion of Symbol into Integer"

SOLVE

Hey, I just created my ruby environment and tested this which returned the data for a the specified company id.

api_response = api_client.crm.companies.basic_api.get_by_id(company_id: 7559743199)

PLEASE rotate your access token as you revealed it in your reply which I used to retrieve a sample and test my ruby code.

0 Upvotes