Skip to content

Commit

Permalink
add marketing campaigns stream (#105)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Hassan Syyid <[email protected]>
  • Loading branch information
keyn4 and hsyyid authored Dec 16, 2024
1 parent b05ed25 commit 1daaa09
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
7 changes: 6 additions & 1 deletion tap_hubspot_beta/client_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class hubspotV3Stream(hubspotStream):

records_jsonpath = "$.results[*]"
next_page_token_jsonpath = "$.paging.next.after"
marketing_streams = ["campaigns"]

def get_next_page_token(
self, response: requests.Response, previous_token: Optional[Any]
Expand All @@ -206,13 +207,17 @@ def get_url_params(
params.update(self.additional_prarams)
if self.properties_url:
params["properties"] = ",".join(self.selected_properties)
if self.name in self.marketing_streams:
default_properties = ["id", "createdAt", "updatedAt"]
properties = [prop for prop in self.selected_properties if prop not in default_properties]
params["properties"] = ",".join(properties)
if next_page_token:
params["after"] = next_page_token
return params

def post_process(self, row: dict, context: Optional[dict]) -> dict:
"""As needed, append or transform raw data to match expected structure."""
if self.properties_url:
if self.properties_url or self.name in self.marketing_streams:
for name, value in row["properties"].items():
row[name] = value
del row["properties"]
Expand Down
29 changes: 28 additions & 1 deletion tap_hubspot_beta/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,33 @@ class QuotesStream(ObjectSearchV3):
properties_url = "properties/v2/quotes/properties"


class CampaignsStream(hubspotV3Stream):
"""Campaigns Stream"""

name = "campaigns"
path = "marketing/v3/campaigns"

schema = th.PropertiesList(
th.Property("id", th.StringType),
th.Property("hs_name", th.StringType),
th.Property("hs_start_date", th.DateTimeType),
th.Property("hs_end_date", th.DateTimeType),
th.Property("hs_notes", th.StringType),
th.Property("hs_audience", th.StringType),
th.Property("hs_goal", th.StringType),
th.Property("hs_currency_code", th.StringType),
th.Property("hs_campaign_status", th.StringType),
th.Property("hs_owner", th.StringType),
th.Property("hs_color_hex", th.StringType),
th.Property("hs_created_by_user_id", th.StringType),
th.Property("hs_object_id", th.StringType),
th.Property("hs_budget_items_sum_amount", th.StringType),
th.Property("hs_spend_items_sum_amount", th.StringType),
th.Property("createdAt", th.DateTimeType),
th.Property("updatedAt", th.DateTimeType),
).to_dict()


class AssociationQuotesDealsStream(AssociationDealsStream):
"""Association Quotes -> Deals Stream"""

Expand Down Expand Up @@ -1689,4 +1716,4 @@ class AssociationTasksDealsStream(AssociationTasksStream):
"""Association Tasks -> Deals Stream"""

name = "associations_tasks_deals"
path = "crm/v4/associations/tasks/deals/batch/read"
path = "crm/v4/associations/tasks/deals/batch/read"
2 changes: 2 additions & 0 deletions tap_hubspot_beta/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
AssociationTasksCompaniesStream,
AssociationTasksContactsStream,
AssociationTasksDealsStream,
CampaignsStream
)

STREAM_TYPES = [
Expand Down Expand Up @@ -135,6 +136,7 @@
AssociationTasksCompaniesStream,
AssociationTasksContactsStream,
AssociationTasksDealsStream,
CampaignsStream
]


Expand Down

0 comments on commit 1daaa09

Please sign in to comment.