Skip to content

Commit

Permalink
Added support for Tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Jan 28, 2022
1 parent d21b873 commit 38d1921
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This tap:
- [Keywords](http://developers.hubspot.com/docs/methods/keywords/get_keywords)
- [Owners](http://developers.hubspot.com/docs/methods/owners/get_owners)
- [Subscription Changes](http://developers.hubspot.com/docs/methods/email/get_subscriptions_timeline)
- [Tickets](https://legacydocs.hubspot.com/docs/methods/tickets/tickets-overview)
- [Workflows](http://developers.hubspot.com/docs/methods/workflows/v3/get_workflows)
- Outputs the schema for each resource
- Incrementally pulls data based on the input state
Expand Down
28 changes: 27 additions & 1 deletion tap_hubspot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class StateFields:
"forms": "/forms/v2/forms",
"workflows": "/automation/v3/workflows",
"owners": "/owners/v2/owners",

"tickets_properties": "/properties/v2/tickets/properties",
"tickets_all": "/crm-objects/v1/objects/tickets/paged",
"tickets_detail": "/crm-objects/v1/objects/tickets/{ticket_id}",
}

def get_start(state, tap_stream_id, bookmark_key):
Expand Down Expand Up @@ -173,7 +177,7 @@ def load_associated_company_schema():

def load_schema(entity_name, move_props_to_toplevel=True):
schema = utils.load_json(get_abs_path('schemas/{}.json'.format(entity_name)))
if entity_name in ["contacts", "companies", "deals"]:
if entity_name in ["contacts", "companies", "deals", "tickets"]:
custom_schema = get_custom_schema(entity_name)

schema['properties']['properties'] = {
Expand Down Expand Up @@ -662,6 +666,27 @@ def sync_deals(STATE, ctx):
singer.write_state(STATE)
return STATE

def sync_tickets(STATE, ctx):
catalog = ctx.get_catalog_from_id(singer.get_currently_syncing(STATE))
mdata = metadata.to_map(catalog.get('metadata'))
schema = load_schema("tickets")
singer.write_schema("tickets", schema, ["objectId"], catalog.get('stream_alias'))
LOGGER.info("sync_tickets(NO bookmarks)")
url = get_url("tickets_all")
# Include all custom properties present in the schema
params = {
'properties': list(schema['properties']['properties']['properties'].keys())
}

with Transformer(UNIX_MILLISECONDS_INTEGER_DATETIME_PARSING) as bumble_bee:
for row in gen_request(STATE, 'tickets', url, params, "objects", "hasMore", ["offset"], ["offset"]):
#record = request(get_url("campaigns_detail", campaign_id=row['id'])).json()
record = bumble_bee.transform(lift_properties_and_versions(row), schema, mdata)
singer.write_record("tickets", record, catalog.get('stream_alias'), time_extracted=utils.now())

return STATE


#NB> no suitable bookmark is available: https://developers.hubspot.com/docs/methods/email/get_campaigns_by_id
def sync_campaigns(STATE, ctx):
catalog = ctx.get_catalog_from_id(singer.get_currently_syncing(STATE))
Expand Down Expand Up @@ -951,6 +976,7 @@ class Stream(object):
Stream('email_events', sync_email_events, ['id'], 'startTimestamp', 'INCREMENTAL'),

# Do these last as they are full table
Stream('tickets', sync_tickets, ["objectId"], None, 'FULL_TABLE'),
Stream('forms', sync_forms, ['guid'], 'updatedAt', 'FULL_TABLE'),
Stream('workflows', sync_workflows, ['id'], 'updatedAt', 'FULL_TABLE'),
Stream('owners', sync_owners, ["ownerId"], 'updatedAt', 'FULL_TABLE'),
Expand Down
11 changes: 11 additions & 0 deletions tap_hubspot/schemas/tickets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "object",
"properties": {
"portalId": {
"type": ["null", "integer"]
},
"objectId": {
"type": ["null", "integer"]
}
}
}

0 comments on commit 38d1921

Please sign in to comment.