Skip to content

Commit b0b4444

Browse files
committedJul 4, 2024
feat(notes): handle missing association cols
1 parent 4f0d9c8 commit b0b4444

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed
 

‎hubspot/notes.ipynb

+19-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
"\n",
3838
"\n",
3939
"ACCESS_TOKEN = os.environ[\"HUBSPOT_ACCESS_TOKEN\"]\n",
40+
"PAGE_SIZE = 10\n",
41+
"\n",
42+
"PROPERTIES = [\"hs_created_by\", \"hs_createdate\", \"hs_note_body\"]\n",
43+
"ASSOCIATION_TYPES = [\"companies\", \"contacts\", \"vendors\"]\n",
44+
"ASSOCIATION_COLUMNS = [f\"associations.{assoc}.results\" for assoc in ASSOCIATION_TYPES]\n",
4045
"\n",
4146
"hubspot = HubSpot(access_token=ACCESS_TOKEN)"
4247
]
@@ -58,20 +63,29 @@
5863
"metadata": {},
5964
"outputs": [],
6065
"source": [
61-
"notes_props = [\"hs_created_by\", \"hs_createdate\", \"hs_note_body\"]\n",
62-
"notes_assoc = [\"companies\", \"contacts\", \"vendors\"]\n",
66+
"response = hubspot.crm.objects.notes.basic_api.get_page(limit=PAGE_SIZE, properties=PROPERTIES, associations=ASSOCIATION_TYPES)\n",
6367
"\n",
64-
"response = hubspot.crm.objects.notes.basic_api.get_page(limit=10, properties=notes_props, associations=notes_assoc)\n",
68+
"notes = hubspot_to_df(response)"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": null,
74+
"metadata": {},
75+
"outputs": [],
76+
"source": [
77+
"# add any missing association columns\n",
78+
"missing_assoc = [col for col in ASSOCIATION_COLUMNS if col not in notes.columns]\n",
79+
"notes = notes.reindex(columns=notes.columns.tolist() + missing_assoc)\n",
6580
"\n",
66-
"notes = hubspot_to_df(response)\n",
6781
"# drop notes without a body\n",
6882
"notes = notes.dropna(subset=[\"properties.hs_note_body\"])\n",
6983
"\n",
7084
"# drop notes without a creator\n",
7185
"notes = notes.dropna(subset=[\"properties.hs_created_by\"])\n",
7286
"\n",
7387
"# drop notes without any of the association types (e.g. all are NA)\n",
74-
"notes = notes.dropna(subset=[\"associations.contacts.results\", \"associations.companies.results\"], how=\"all\")"
88+
"notes = notes.dropna(subset=ASSOCIATION_COLUMNS, how=\"all\")"
7589
]
7690
},
7791
{

0 commit comments

Comments
 (0)
Please sign in to comment.