jpetrucciani / hubspot3

python3.6+ hubspot client based on hapipy, but modified to use the newer endpoints and non-legacy python
MIT License
146 stars 72 forks source link

Add a Users API client #114

Closed sangaline closed 2 years ago

sangaline commented 3 years ago

Hubspot recently added a Users API for managing user accounts. This pull request adds a new UsersClient class that adds support for each of the available API methods. This API notably requires OAuth permission scopes, and requests will fail without them. The returned errors are fairly clear about the issue when that happens. For example, here's the error when changing a user role requires access to the billing scope:

HubspotBadRequest:                                                                                                     
Error validating request.                                                                                              

---- request ----                                                                                                                                                                                                                              
PUT api.hubapi.com/settings/v3/users/example@example.com?idProperty=EMAIL, [timeout=<class 'int'>]             

---- body ----                                                                                                                                                                                                                                 
<class 'NoneType'>                                                                                                                                                                                                                             

---- headers ----                                                                                                      
<class 'dict'>                                                                                                                                                                                                                                 

---- result ----                                                                                                                                                                                                                               
<class 'int'>                                                                                                          

---- body -----                                                                                                        
{"status":"error","message":"Error validating request.","correlationId":"848ea612-ba12-4f6d-aab6-4476d827089b","errors":[{"message":"App must have the billing-write scope to modify roles for paid seats."},{"message":"This role is unavailable and can't be assigned to a user. This can happen when an account upgrades or downgrades their plan."}],"category":"VALIDATION_ERROR"}

---- headers -----                                                                                                                                                                                                                             
<class 'http.client.HTTPMessage'>                                                                                      

---- reason ----                                                                                                       
Bad Request                                                                                                                                                                                                                                    

---- trigger error ----                                                                                                
<class 'NoneType'> 

The prospector CI check is failing because pylint is erroneously identifying various types from the typing module as unsubscriptable. This isn't unique to the new users submodule, the same thing is happening with the unchanged companies, contacts, crm_associations, deals, lines, properties, and utils submodules.

jpetrucciani commented 2 years ago

This is now included in the new release on pip in version 3.2.51! Thanks again for your contribution 😄