Skip to content

Commit 56cf884

Browse files
authored
Fix issues with v3 API. (#140)
1 parent d601b53 commit 56cf884

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

hubspot3/owners.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class OwnersClient(BaseClient):
1717

1818
def _get_path(self, subpath):
1919
"""get the full api url for the given subpath on this client"""
20-
return f"crm/{OWNERS_API_VERSION}/owners"
20+
return f"crm/{OWNERS_API_VERSION}/{subpath}"
2121

2222
def get_owners(self, **options):
2323
"""Only returns the list of owners, does not include additional metadata"""
@@ -26,10 +26,14 @@ def get_owners(self, **options):
2626
more = True
2727
while more:
2828
data = self._call("owners", **opts)
29-
owners.extend(data["results"][: opts["limit"]])
30-
opts["limit"] -= len(data["results"])
31-
if opts["limit"] < 1:
32-
more = False
29+
new_owners = data["results"]
30+
if "limit" in opts:
31+
new_owners = new_owners[: opts["limit"]]
32+
opts["limit"] -= len(data["results"])
33+
if opts["limit"] < 1:
34+
more = False
35+
36+
owners.extend(new_owners)
3337
if "paging" in data:
3438
opts["after"] = data["paging"]["next"]["after"]
3539
else:
@@ -39,34 +43,33 @@ def get_owners(self, **options):
3943
def get_owner_name_by_id(self, owner_id: str, **options) -> str:
4044
"""Given an id of an owner, return their name"""
4145
owner_name = "value_missing"
42-
owners = self._call(f"owners/{owner_id}", **options)
43-
if owners["results"]:
44-
owner = owners["results"][0]
46+
owner = self._call(f"owners/{owner_id}", **options)
47+
if owner:
4548
owner_name = f"{owner['firstName']} {owner['lastName']}"
4649
return owner_name
4750

4851
def get_owner_email_by_id(self, owner_id: str, **options) -> str:
4952
"""given an id of an owner, return their email"""
5053
owner_email = "value_missing"
51-
owners = self._call(f"owners/{owner_id}", **options)
52-
if owners["results"]:
53-
owner_email = owners["results"][0]["email"]
54+
owner = self._call(f"owners/{owner_id}", **options)
55+
if owner:
56+
owner_email = owner["email"]
5457
return owner_email
5558

5659
def get_owner_by_id(self, owner_id, **options):
5760
"""Retrieve an owner by its id."""
58-
owners = self._call(f"owners/{owner_id}", **options)
59-
if owners["results"]:
60-
return owners["results"][0]
61+
owner = self._call(f"owners/{owner_id}", **options)
62+
if owner:
63+
return owner
6164
return None
6265

6366
def get_owner_by_email(self, owner_email: str, **options):
6467
"""
6568
Retrieve an owner by its email.
6669
"""
6770
owners = self.get_owners(method="GET", params={"email": owner_email}, **options)
68-
if owners["results"]:
69-
return owners["results"][0]
71+
if owners:
72+
return owners[0]
7073
return None
7174

7275
def link_owner_to_company(self, owner_id, company_id):

0 commit comments

Comments
 (0)