Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/extraction of all data from associations in hubspot #594

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions sources/hubspot/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ def pagination(
return None


def extract_association_data(
_obj: Dict[str, Any],
data: Dict[str, Any],
association: str,
headers: Dict[str, Any]
) -> List[Dict[str, Any]]:
values = []

while data is not None:
for r in data["results"]:
values.append(
{
"value": _obj["hs_object_id"],
f"{association}_id": r["id"],
}
)
data = pagination(data, headers)
return values


def extract_property_history(objects: List[Dict[str, Any]]) -> Iterator[Dict[str, Any]]:
for item in objects:
history = item.get("propertiesWithHistory")
Expand Down Expand Up @@ -156,13 +176,11 @@ def fetch_data(
_obj["id"] = _result["id"]
if "associations" in _result:
for association in _result["associations"]:
__values = [
{
"value": _obj["hs_object_id"],
f"{association}_id": __r["id"],
}
for __r in _result["associations"][association]["results"]
]
__data = _result["associations"][association]

__values = extract_association_data(
_obj, __data, association, headers
)

# remove duplicates from list of dicts
__values = [
Expand Down