Last active
March 24, 2022 18:08
-
-
Save krummja/88461a86fda5ddd59fc3ef01d6387569 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from typing import * | |
import requests | |
import os | |
from hubspot3 import Hubspot3 | |
from pprint import pprint | |
if TYPE_CHECKING: | |
pass | |
API_KEY = os.environ.get("HUBSPOT") | |
client = Hubspot3(api_key = API_KEY) | |
def get_contact_data(vid: int = -1, last_name: str = "") -> Dict[str, Any] | None: | |
payload = {} | |
if vid < 0 and last_name != "": | |
print("Searching by contact last name ...") | |
contact = client.contacts.search(last_name) | |
props = contact[0]['properties'] | |
vid = props['vid'] | |
elif vid > 0: | |
print("Searching by contact VID ...") | |
contact = client.contacts.get_by_id(str(vid)) | |
props = contact['properties'] | |
last_name = props['lastname']['value'] | |
else: | |
print("No usable info provided. Aborting.") | |
return | |
print(f"Found contact with last name {last_name} with VID {vid}.") | |
payload["vid"] = vid | |
payload["name"] = f"{props['firstname']['value']} {props['lastname']['value']}" | |
payload["status"] = props["hs_lead_status"]['value'] | |
payload["email"] = props["email"]['value'] | |
payload["message"] = "This has been a test of the National Emergency Broadcast System." | |
pprint(payload) | |
return payload | |
def post_to_zapier(payload: Dict[str, Any]): | |
webhook: str = "https://hooks.zapier.com/hooks/catch/12160131/bsxqh5p/" | |
result = requests.post(webhook, data = payload) | |
print(result.status_code) | |
if __name__ == '__main__': | |
payload = get_contact_data(vid = 101) | |
post_to_zapier(payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment