python-intercom icon indicating copy to clipboard operation
python-intercom copied to clipboard

client.companies.users(...) returns a list of intercom.company.Company

Open jarcoal opened this issue 7 years ago • 5 comments

Is this the intended behavior? Seems to cause issues when trying to save the user data back to Intercom.

jarcoal avatar Feb 07 '18 00:02 jarcoal

Hey @jarcoal 👋 companies.users(<company_id>) should be returning a collection that will contain all of the users belonging to a specific company:

>>> intercom.companies.users(company_id)
<intercom.collection_proxy.CollectionProxy object at 0x7f582fc78128>
>>> for user in intercom.companies.users(company_id):
...   print(user.name)
...
Steven Hyde
Michael Kelso
>>>

What arguments are you passing when experiencing this and what's the object that you're being presented with?

tanasegabriel avatar Mar 01 '18 17:03 tanasegabriel

Try checking user.__class__. For me it's returning companies, not users, even though the data within is the user's data. In my code I've had to extract the user ID and re-wrap it in a User model.

jarcoal avatar Mar 01 '18 17:03 jarcoal

Ah, got it - you're referring to each of the users returned. Yep, that's how this is defined in here.

I do understand now how this can cause issues while trying to update all of the users belonging to a company like this:

>>> for user in intercom.companies.users(company_id):
...   user.custom_attributes["newCDA"] = "yup"
...   intercom.users.save(user)
...
<intercom.company.Company object at 0x7f109be4d710>

☝️ That will actually update the company rather than the user - nice catch here!

tanasegabriel avatar Mar 01 '18 18:03 tanasegabriel

Exactly, it tries to send the save request to the wrong URL. Thanks for looking into that!

jarcoal avatar Mar 01 '18 18:03 jarcoal

I am facing with the same behavior in v3.1.0. Will there be a new version for this fix soon?

mehmetgencolatug avatar May 08 '21 21:05 mehmetgencolatug