Skip to content

Instantly share code, notes, and snippets.

@ajmorris
Created September 7, 2012 04:01
Show Gist options
  • Save ajmorris/3662973 to your computer and use it in GitHub Desktop.
Save ajmorris/3662973 to your computer and use it in GitHub Desktop.
Python
# Close hubspot
if 'hubspotutk' in request.COOKIES:
hs_userToken = request.COOKIES['hubspotutk']
hs_date = datetime.date.today().strftime("%m/%d/%Y")
hs_client_contact = requests.get('http://api.hubapi.com/contacts/v1/contact/utk/{0}/profile?hapikey={1}'.format(hs_userToken, HUBSPOT_API_KEY))
if hs_client_contact.status_code == 200:
hs_response = json.loads(hs_client_contact.text)
hs_client_id = hs_response['vid']
hs_data = {'properties': {'lifecyclestage': 'customer', 'closedate': hs_date}}
hs_client_close = requests.post('http://api.hubapi.com/contacts/v1/contact/vid/{0}/profile?hapikey={1}'.format(hs_client_id, HUBSPOT_API_KEY), data=hs_data)
if hs_client_contact.status_code == 404:
hs_email = request.session['get_started']['email']
hs_client_email = requests.get('http://api.hubapi.com/contacts/v1/contacts/email/{0}/profile?hapikey={1}'.format(hs_email, HUBSPOT_API_KEY))
hs_response = json.loads(hs_client_email.text)
hs_client_id = hs_response['vid']
hs_data = {'properties': {'lifecyclestage': 'customer', 'closedate': hs_date}}
hs_client_close = requests.post('http://api.hubapi.com/contacts/v1/contact/vid/{0}/profile?hapikey={1}'.format(hs_client_id, HUBSPOT_API_KEY), data=hs_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment