|
37 | 37 | "\n",
|
38 | 38 | "\n",
|
39 | 39 | "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", |
40 | 45 | "\n",
|
41 | 46 | "hubspot = HubSpot(access_token=ACCESS_TOKEN)"
|
42 | 47 | ]
|
|
58 | 63 | "metadata": {},
|
59 | 64 | "outputs": [],
|
60 | 65 | "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", |
63 | 67 | "\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", |
65 | 80 | "\n",
|
66 |
| - "notes = hubspot_to_df(response)\n", |
67 | 81 | "# drop notes without a body\n",
|
68 | 82 | "notes = notes.dropna(subset=[\"properties.hs_note_body\"])\n",
|
69 | 83 | "\n",
|
70 | 84 | "# drop notes without a creator\n",
|
71 | 85 | "notes = notes.dropna(subset=[\"properties.hs_created_by\"])\n",
|
72 | 86 | "\n",
|
73 | 87 | "# 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\")" |
75 | 89 | ]
|
76 | 90 | },
|
77 | 91 | {
|
|
0 commit comments