diff --git a/README.md b/README.md index 66ddf1f..f385040 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tap_hubspot/__init__.py b/tap_hubspot/__init__.py index df673ee..b2c095f 100644 --- a/tap_hubspot/__init__.py +++ b/tap_hubspot/__init__.py @@ -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): @@ -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'] = { @@ -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)) @@ -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'), diff --git a/tap_hubspot/schemas/tickets.json b/tap_hubspot/schemas/tickets.json new file mode 100644 index 0000000..de8b1ab --- /dev/null +++ b/tap_hubspot/schemas/tickets.json @@ -0,0 +1,11 @@ +{ + "type": "object", + "properties": { + "portalId": { + "type": ["null", "integer"] + }, + "objectId": { + "type": ["null", "integer"] + } + } +}