Skip to content

hapipy documentation

adrianmott edited this page Nov 16, 2011 · 14 revisions

What is it?

hapipy is a Python wrapper for the HubSpot APIs. You can find more information about HubSpot's APIs here: http://docs.hubapi.com. The hapipy wrapper is meant to make it easier for external developers to use the HubSpot APIs by giving easy access to data that gets returned to you after an API call gets made.

The following documentation will describe the different calls that you can make via the hapipy wrapper and includes some sample code for how to make these calls and deal with the responses. Please keep in mind that we'll be working hard to improve and add to this wrapper as we add to and iterate on our APIs so if a method that you're looking for isn't here today, please check back soon!

Description of Wrapper Files

The base hapi.py includes all of the methods that you can call to use the wrapper. As I mentioned above, we're in progress with this and will continue to develop out different methods for all of our APIs going forward. The other files to note are the objects files which include all of the classes and define the data that you can access with each call you make. For the leads methods please refer to "lead_objects.py", for blog please refer to "blog_objects.py", for lead nurturing...well you get the idea.

Description of Methods and Example Implementation

hapipy Leads Methods

Please refer to the the 'lead_objects.py' file in the repository for reference to the fields that are available to you on each Lead object.

  • get_lead: Lets you search for a specific lead by its GUID and returns a lead object. For more information on this operation, please [click here.] (http://docs.hubapi.com/wiki/Searching_Leads)
    Required Parameters: Lead GUID
    Example Call:
    hs_client = HubSpotLeadsClient("demo")
    lead = hs_client.get_lead("8a706adf3282b1e3013282b27b180011")
    print lead.guid

  • search_leads: Lets you search for leads by name, email address and company. For more information on this operation, please [click here.] (http://docs.hubapi.com/wiki/Searching_Leads)
    Required Parameters: Search Parameter
    Example Call:
    hs_client = HubSpotLeadsClient("demo")
    leads = hs_client.search_leads("Maxey")
    for lead in leads:
    print lead.guid

  • update_lead: Lets you update a lead's information within HubSpot. This is useful for updating after a lead re-converts. It can also be useful to change a lead's grade (the "score" field).
    This method will let you return any lead field like the previous methods listed above. If the update of your lead fails however, it will return a bit of JSON code to you with the HTTP status and message (reason the failure occurred).
    For more information on this operation, please [click here.] (http://docs.hubapi.com/wiki/Updating_Leads)
    Required Parameters: Lead Guid, Update data (in key:value pair format as shown below in the method call)
    Example Call:
    hs_client = HubSpotLeadsClient("demo")
    new_lead = hs_client.update_lead("8a706adf3240e8c7013240ea3d7c01b4", {"email":"[email protected]"})
    print new_lead.email

  • offset_leads: Enables you to specify an "offset" on your call to the Leads API. This is useful for paginating leads, as the maximum amount of leads that can be returned to you in one API call is 100. Offset lets you start your leads call at lead "offset". For more information on this operation, please [click here.] (http://docs.hubapi.com/wiki/Searching_Leads)
    Required Parameters: offset value
    Example Call:
    hs_client = HubSpotLeadsClient("demo")
    leads = hs_client.offset_leads("100")
    for lead in leads:
    print lead.guid

  • register_webhook: Lets you register a HubSpot Leads API webhook.
    Required Parameters: endpoint URL
    Example Call:
    hs_client = HubSpotLeadsClient("demo")
    webhook = hs_client.register_webhook("https://examplesite.com/webhook/endpoint/")

  • close_lead: Enables you to close a lead in HubSpot. This operation will convert a lead from its current lead status to a customer status and will be reflected as such in HubSpot's analytics. If you call this method without a "close time", the lead will be closed using the current time as the close time. For more information on this operation, please [click here.] (http://docs.hubapi.com/wiki/Updating_Leads)
    Required Parameters: Lead Guid, Close Time (optional) represented in unix time (milliseconds since the epoch). Example Call:
    hs_client = HubSpotLeadsClient("demo")
    new_lead = hs_client.close_lead("731d51afde694045a523ca83c15a06ec", "353894400000")
    print new_lead.is_customer

hapipy Lead Nurturing Methods

Please refer to the 'lead_nurturing_objects.py' file in the repository for reference to the fields that are available to you on each Lead Nurturing object.

  • get_campaigns: This method enables you to get all ACTIVE campaigns for a given portal that have been created. For more information on this method, please [click here.] (http://docs.hubapi.com/wiki/Lead_Nurturing_API#Get_Campaign_Details)
    Required Parameters: None
    Example Call:
    hs_client = HubSpotLeadNurtureClient("demo")
    new_cams = hs_client.get_campaigns()
    for lns in new_cams:
    print lns.guid

  • get_leads: This method enables you to get all leads who are enrolled in a particular lead nurturing campaign. For more information on this method, please [click here.] (http://docs.hubapi.com/wiki/Lead_Nurturing_API#Get_Leads_in_a_Campaign)
    Required Parameters: Campaign Guid
    Example Call:
    hs_client = HubSpotLeadNurtureClient("demo")
    new_cams = hs_client.get_leads("4159b174-8aeb-4746-abdc-9dfe013d47dc")
    for lns in new_cams:
    print lns.leadGuid

  • get_history: This action will give you the Lead Nurturing history of the specified lead. For more information on this method, please [click here.] (http://docs.hubapi.com/wiki/Lead_Nurturing_API#Get_Campaign_History_for_a_Lead)
    Required Parameters: Lead Guid
    Example Call:
    hs_client = HubSpotLeadNurtureClient("demo")
    new_cams = hs_client.get_leads("8a706adf32691328013269138e9a0008")
    for lns in new_cams:
    print lns.leadGuid

  • enroll_lead: This action will enroll a specified lead into a specified HubSpot lead nurturing campaign. It doesn't return anything but a simple string with some messaging as to the call made For reference and more information on this method, please [click here.] (http://docs.hubapi.com/wiki/Lead_Nurturing_API#Enroll_a_Lead_in_a_Campaign)
    Required Parameters: Campaign Guid, Lead Guid
    Example Call:
    hs_client = HubSpotLeadNurtureClient("demo")
    new_cams = hs_client.enroll_lead("4159b174-8aeb-4746-abdc-9dfe013d47dc", "8a706adf32691328013269138e9a0008")
    print new_cams

  • unenroll_lead: This action will remove a specified lead from a specified HubSpot lead nurturing campaign. It doesn't return anything but a simple string with some messaging as to the call made For reference and more information on this method, please [click here.] (http://docs.hubapi.com/wiki/Lead_Nurturing_API#Remove_a_Lead_from_a_Campaign)
    Required Parameters: Campaign Guid, Lead Guid
    Example Call:
    hs_client = HubSpotLeadNurtureClient("demo")
    new_cams = hs_client.enroll_lead("4159b174-8aeb-4746-abdc-9dfe013d47dc", "8a706adf32691328013269138e9a0008")
    print new_cams

hapipy Blog Methods

Please see http://docs.hubapi.com/wiki/Blog_API for the main Blog API documentation. Then read the [blog API client] (https://github.com/HubSpot/hapipy/blob/master/hapi/blog.py) and [unit tests] (https://github.com/HubSpot/hapipy/blob/master/hapi/test/test_blog.py) to see code examples.

hapipy Prospects Methods

Please see http://docs.hubapi.com/wiki/Prospects_API for the main Prospects API documentation. Then read the [prospects API client] (https://github.com/HubSpot/hapipy/blob/master/hapi/prospects.py) and [unit tests] (https://github.com/HubSpot/hapipy/blob/master/hapi/test/test_prospects.py) to see code examples.

hapipy Events Methods

Please see http://docs.hubapi.com/wiki/Events_API for the main Settings API documentation. Then read the [events API client] (https://github.com/HubSpot/hapipy/blob/master/hapi/events.py) and [unit tests] (https://github.com/HubSpot/hapipy/blob/master/hapi/test/test_events.py) to see code examples.

hapipy Settings Methods

Please see http://docs.hubapi.com/wiki/Settings_API for the main Settings API documentation. Then read the [prospects API client] (https://github.com/HubSpot/hapipy/blob/master/hapi/settings.py) and [unit tests] (https://github.com/HubSpot/hapipy/blob/master/hapi/test/test_settings.py) to see code examples.

Clone this wiki locally