Python API

Hubspot

class RPA.Hubspot.Hubspot(hubspot_apikey: Optional[str] = None, hubspot_access_token: Optional[str] = None)

Hubspot is a library for accessing HubSpot using REST API. It extends hubspot-api-client.

Current features of this library focus on retrieving CRM object data from HubSpot via API. For additional information, see Understanding the CRM.

Using Date Times When Searching

When using date times with the Hubspot API, you must provide them as Unix-style epoch timestamps (with milliseconds), which can be obtained using the DateTime library’s Convert Date with the argument result_format=epoch. The resulting timestamp string will be a float, but the API only accepts integers, so you must multiply the resulting timestamp by 1,000 and then round it to the nearest integar to include in API calls (i.e., the resulting integer sent to the API must have 13 digits as of March 18, 2022).

Robot framework example usage:

*** Settings ***
Library     DateTime
Library     RPA.Hubspot
Task Setup  Authorize Hubspot

*** Tasks ***
Search with date
    ${yesterday}=    Get current date    increment=-24h   result_format=epoch
    ${yesterday_hs_ts}=    Evaluate    round(${yesterday} * 1000)
    ${deals}=    Search for objects    DEALS
    ...    hs_lastmodifieddate    GTE    ${yesterday_hs_ts}

Python example usage

from robot.libraries.DateTime import get_current_date, subtract_time_from_date
from RPA.Hubspot import Hubspot
from RPA.Robocorp.Vault import Vault

secrets = Vault().get_secret("hubspot")

hs = Hubspot(hubspot_apikey=secrets["api_key"])
yesterday = round(
    subtract_time_from_date(get_current_date(), "24h", result_format="epoch") * 1000
)
deals = hs.search_for_objects("DEALS", "hs_lastmodifieddate", "GTE", yesterday)
print(deals)

Batch Inputs

When retrieving information, the library automatically batches requests that are provided as lists, see Get object keyword for an example, but when wishing to create or update many objects, the library provides a batching system.

In order to start a batch, you must first call the Create new batch keyword. This initializes a new batch to accept inputs. If a batch already exists when you call this keyword, it will be lost and a new blank one will be started.

Once the batch has been initialized, you can add inputs one at a time with Add input to batch or many at a time with Extend batch with inputs.

In order to finally send the batch to HubSpot, you must call Execute batch. The final keyword will return the created or updated objects from HubSpot. New object IDs can be obtained from the id property, see the SimplePublicObject reference.

Robot framework example:

*** Settings ***
Library         RPA.Hubspot
Library         RPA.Robocorp.Vault
Task Setup      Authorize Hubspot

*** Tasks ***
Create objects via batch
    Create new batch
    Add input to batch    name=Nokia    country=Finland
    Add input to batch    name=Google    country=USA
    ${new_companies}=    Execute batch
    Log    The first new company added has the new id ${{$new_companies[0].id}}

*** Keywords ***
Authorize Hubspot
    ${secrets}=    Get secret    hubspot
    Auth with api key    ${secrets}[API_KEY]

Python example:

NOTE: When executing a batch input in Python, you can directly import the BatchInputFactory class to use to create your batch input before executing the batch.

from RPA.Hubspot import Hubspot, BatchInputFactory, BatchMode
from RPA.Robocorp.Vault import RobocorpVault


vault = RobocorpVault()
secrets = vault.get_secret("hubspot")

hs = Hubspot(secrets["API_KEY"])

batch = BatchInputFactory(BatchMode.UPDATE, "company")
batch.extend_inputs(
    [
        {"name": "Nokia's New Name", "city": "Espoo"},
        {"name": "Alphabet", "city": "Mountain View"},
    ],
    ["1001", "1002"],
)
hs.batch_input = batch
updated_companies = hs.execute_batch()
print(
    "Companies have been updated:\\n" +
    "\\n".join([str(c) for c in updated_companies])
)

Information Caching

This library loads custom object schemas and pipelines into memory the first time when keywords using them are called. These cached versions are recalled unless the use_cache is set to False, where available.

Custom Object Types

All keywords that request a parameter of object_type can accept custom object type names as long as they are properly configured in HubSpot. The system will lookup the custom object ID using the provided name against the configured name or one of the configured labels (e.g., “singular” and “plural” types of the name).

HubSpot Object Reference

This section describes the types of objects returned by this Library and their associated attributes. These attributes can be accessed via dot-notation as described in the Attribute Access section below.

Attribute Access

Keywords return native Python Hubspot objects, rather than common Robot Framework types. These types have sets of defined attributes allowing for dot-notation access of object properties. Properties (e.g., those configured in Hubspot settings for each object) will be accessible in a Python dictionary attached to the properties attribute of the returned object. See the Attribute Definitions section for details of that associated attributes for all types returned by this library.

Example usage retrieving the city property of a Company object:

Robot framework example:

*** Settings ***
Library         RPA.Hubspot
Library         RPA.Robocorp.Vault

Task Setup      Authorize Hubspot

*** Variables ***
${ACCOUNT_NOKIA}    6818764598

*** Tasks ***
Obtain city information from Hubspot
    ${account}=    Get object    COMPANY    ${ACCOUNT_NOKIA}
    Log    The city for account number ${ACCOUNT_NOKIA} is ${account.properties}[city]

*** Keywords ***
Authorize Hubspot
    ${secrets}=    Get secret    hubspot
    Auth with api key    ${secrets}[API_KEY]

Python example:

from RPA.Hubspot import Hubspot
from RPA.Robocorp.Vault import RobocorpVault

vault = RobocorpVault()
secrets = vault.get_secret("hubspot")

hs = Hubspot(secrets["API_KEY"])
nokia_account_id = "6818764598"
account = hs.get_object("COMPANY", nokia_account_id)
print(f"The city for account number {nokia_account_id} is {account.properties['city']}")

Attribute Definitions

This library can return various types of objects, whose attributes are only accessible via dot-notation. The below reference describes the attributes available on these objects.

SimplePublicObject

An object in HubSpot. The object itself does not describe what type it represents.

idstr

The HubSpot ID of the object.

propertiesDict[str, str]

A dictionary representing all returned properties associated to this object. Properties must be accessed as via standard dictionary subscription, e.g., properties["name"].

created_atdatetime

The timestamp when this object was created in HubSpot.

updated_atdatetime

The last modified timestamp for this object.

archivedbool

Whether this object is archived.

archived_atdatetime

The timestamp when this object was archived.

SimplePublicObjectWithAssociations

An object in HubSpot including associations to other objects. The object itself does not describe what type it represents.

idstr

The HubSpot ID of the object.

propertiesDict[str, str]

A dictionary representing all returned properties associated to this object. Properties must be accessed as via standard dictionary subscription, e.g., properties["name"].

created_atdatetime

The timestamp when this object was created in HubSpot.

updated_atdatetime

The last modified timestamp for this object.

archivedbool

Whether this object is archived.

archived_atdatetime

The timestamp when this object was archived.

associationsDict[str, CollectionResponseAssociatedId]

A dictionary whose key will be the requested association type, e.g., companies and associated value will be a container object with all the associations. See CollectionResponseAssociatedId.

AssociatedId

The ID of an associated object, as well as the type of association.

idstr

The ID of the associated HubSpot object.

typestr

The type of association, e.g., deals_to_companies.

CollectionResponseAssociatedId

A container object for a collection of AssociatedId objects returned by the API.

resultsList[AssociatedId]

The list of AssociatedId objects returned by the API.

pagingPaging

Used by this library to assist with retreiving multi-page API responses.

Pipeline

A pipeline represents the steps objects travel through within HubSpot.

idstr

The HubSpot ID for the pipeline. All accounts start with one pipeline with the id default.

labelstr

The human-readabel label for the pipeline.

stagesList[PipelineStage]

A list of PipelineStage objects in the order the object would follow through the pipeline.

created_atdatetime

The timestamp when this pipeline was created in HubSpot.

updated_atdatetime

The last modified timestamp for this pipeline.

archivedbool

Whether this pipeline is archived.

display_orderint

The place in the list of pipelines where this pipeline is shown in the HubSpot UI.

PipelineStage

A pipeline stage is one of the various stages defined in a Pipeline.

idstr

The HubSpot ID of the stage.

labelstr

The human-readabel label for the stage.

metadataDict[str, str]

A dictionary of additional data associated with ths stage, such as probability.

created_atdatetime

The timestamp when this stage was created in HubSpot.

updated_atdatetime

The last modified timestamp for this stage.

archivedbool

Whether this stage is archived.

archived_atdatetime

The timestamp when this stage was archived.

PublicOwner

An owner in HubSpot. Owners of companies and deals are responsible for driving a sale to close or similar.

idstr

The HubSpot ID of the owner.

emailstr

The owner’s email address in HubSpot.

first_namestr

The owner’s first name.

last_namestr

The owner’s last name.

user_idint

The associated user ID if the owner is a HubSpot user.

created_atdatetime

The timestamp when this owner was created in HubSpot.

updated_atdatetime

The last modified timestamp for this owner.

archivedbool

Whether this owner is archived.

teamsList[PublicTeam]

A list of teams the owner is in. See PublicTeam.

PublicTeam

A team of owners in HubSpot

idstr

The HubSpot ID of the Team.

namestr

The Team’s name.

membershipstr

One of PRIMARY, SECONDARY, or CHILD.

BUILTIN_PLURAL_MAP = {'companies': 'companies', 'company': 'companies', 'contact': 'contacts', 'contacts': 'contacts', 'deal': 'deals', 'deals': 'deals', 'feedback submission': 'feadback submissions', 'feedback submissions': 'feadback submissions', 'line item': 'line items', 'line items': 'line items', 'product': 'products', 'products': 'products', 'quote': 'quotes', 'quotes': 'quotes', 'ticket': 'tickets', 'tickets': 'tickets'}
BUILTIN_SINGULAR_MAP = {'companies': 'company', 'company': 'company', 'contact': 'contact', 'contacts': 'contact', 'deal': 'deal', 'deals': 'deal', 'feedback submission': 'feadback submission', 'feedback submissions': 'feadback submission', 'line item': 'line item', 'line items': 'line item', 'product': 'product', 'products': 'product', 'quote': 'quote', 'quotes': 'quote', 'ticket': 'ticket', 'tickets': 'ticket'}
ROBOT_AUTO_KEYWORDS = False
ROBOT_LIBRARY_DOC_FORMAT = 'REST'
ROBOT_LIBRARY_SCOPE = 'Global'
add_input_to_batch(object_id: Optional[str] = None, **properties) None

Add the provided free-named keyword arguments to the current batch input. If creating an UPDATE batch, you must also provide the Hubspot object id (an alternate ID property cannot be used).

The keyword will fail if an ID is provided to a batch that is currently in CREATE mode and has any inputs already.

See Batch Inputs` for complete information on using the batch input API.

Parameters
  • properties – A dictionary of HubSpot properties to set to the HubSpot object being created or updated.

  • id – The HubSpot ID of the object to be updated. If provided, the batch is assumed to be in UPDATE mode. The keyword will fail if an ID is provided to a batch that is currently in CREATE mode and has any inputs already.

auth_with_api_key(api_key: str) None

Deprecated! Use Auth With Token instead.

Authorize to HubSpot with an account-wide API key. This keyword verifies the provided credentials by retrieving the custom object schema from the API.

Parameters

api_key – The API key for the account to authenticate to.

auth_with_token(access_token: str) None

Authorize to HubSpot with Private App access token. This keyword verifies the provided credentials by retrieving the custom object schema from the API.

Learn more about Private Apps: https://developers.hubspot.com/docs/api/private-apps

Parameters

access_token – The access token created for the Private App in your HubSpot account.

property batch_input: BatchInputFactory
clear_current_batch() BatchInputFactory

Returns the current batch and then clears it.

See Batch Inputs` for complete information on using the batch input API.

create_new_batch(object_type: str, mode: BatchMode) None

Creates a new blank batch input for the provided object_type in either the UPDATE or CREATE mode.

See Batch Inputs` for complete information on using the batch input API.

Parameters
  • object_type – The object type to be created or updated by the batch.

  • mode – either UPDATE or CREATE.

create_object(object_type, **properties) SimplePublicObject

Creates a new Hubspot object of the provided object_type and with the provided properties in Hubspot. Read-only or nonexistent properties are ignored. The object_type parameter automatically looks up custom object IDs based on the provided name.

The Hubspot properties to be updated must be provided as additional labeled paremeters to this keyword.

Returns the newly created object. The new object’s id is available via the property id.

Parameters
  • object_type – The object type to be created.

  • properties – All remaining labeled parameters passed into this keyword will be used as the properties of the new object. Read-only or nonexistent properties will be ignored.

execute_batch() List[SimplePublicObject]

Sends the current batch input to the Hubspot API.

Keyword will only fail if all inputs resulted in error. Partial failures are reported as warnings.

See Batch Inputs` for complete information on using the batch input API.

Returns

The updated or created objects as a list of SimplePublicObject types.

extend_batch_with_inputs(properties: List[Dict[str, str]], ids: Optional[List[str]] = None) None

Extends the current batch input with the provided lists of Hubspot properties and Hubspot object ids. The ids parameter must be provided when extending an UPDATE batch. The two provided lists will be zipped together in the same order as provided.

The keyword will fail if an ID is provided to a batch that is currently in CREATE mode and has any inputs already.

See Batch Inputs` for complete information on using the batch input API.

Parameters
  • properties – A list of dictionaries of HubSpot properties to set to the HubSpot objects being created or updated.

  • ids – The HubSpot IDs of the objects to be updated. If provided, the batch is assumed to be in UPDATE mode. The keyword will fail if an ID is provided to a batch that is currently in CREATE mode and has any inputs already.

get_current_batch() BatchInputFactory

Returns the current batch.

See Batch Inputs` for complete information on using the batch input API.

Returns

The current batch input object.

get_current_batch_inputs() List[Dict[str, Dict[str, str]]]

Returns the inputs in the current batch. The returned list will be a list of dictionaries each with either 1 or 2 keys depending on if the batch is in CREATE or UPDATE mode. If in UPDATE mode, the dictionaries will have the keys properties and id, but if in CREATE mode, the dictionaries will only have the properties key.

See Batch Inputs` for complete information on using the batch input API.

Returns

A list of dictionaries representing the current inputs.

get_current_stage_of_object(object_type: str, object_id: str, id_property: Optional[str] = None, label_as_key: bool = True, use_cache: bool = True) Tuple[str, Dict]

Returns the current pipeline stage for the object as a tuple of the stage label and that stage’s associated metadata as a dictionary. If you want the label to be returned as the numerical API ID, set label_as_key to False.

If the object type does not have an applied pipeline, the keyword will fail.

This keyword caches results for future use, to refresh results from Hupspot, set use_cache to False.

Parameters
  • object_type – The object type to be returned and that has the ID indicated. Custom objects will be validated against the schema.

  • object_id – The ID of the object to be returned.

  • id_property – (Optional) Can be used to allow the API to search the object database using an alternate property as the unique ID.

  • label_as_key – (Optional) Defaults to True. Setting this to False will cause the returned dictionary to key off of id instead of label.

  • use_cache – (Optional) Setting this to False will force the system to recache the pipelines from Hubspot.

Returns

A tuple where index 0 is the label or ID of the object’s current stage and index 1 is associated data.

get_object(object_type: str, object_id: Union[str, List[str]], id_property: Optional[str] = None, properties: Optional[Union[List[str], str]] = None, associations: Optional[Union[List[str], str]] = None) Union[SimplePublicObject, SimplePublicObjectWithAssociations, List[SimplePublicObject]]

Reads objects of object_type from HubSpot with the provided object_id. The objects can be found using an alternate ID by providing the name of that HubSpot property which contains the unique identifier to id_property. The object_type parameter automatically looks up custom object IDs based on the provided name. If a list of object IDs is provided, the batch API will be utilized, but in that case, associations cannot be returned.

A list of property names can be provided to properties and they will be included in the returned object. Nonexistent properties are ignored.

A list of object types can be provided to associations and all object IDs associated to the returned object of that type will be returned as well. Object types passed to this parameter are also validated against built-in objects and custom object schemas.

Parameters
  • object_type – The object type to be returned and that has the ID indicated.

  • object_id – The ID of the object to be returned.

  • id_property – (Optional) Can be used to allow the API to search the object database using an alternate property as the unique ID.

  • properties – (Optional) A list of strings representing property names to be included in the returned object. Nonexistent properties are ignored.

  • associations – (Optional) A list of strings representing object types to retrieve as associated object IDs.

Returns

The requested object as a SimplePublicObject or SimplePublicObjectWithAssociations type. If a batch request was made, it returns a list of SimplePublicObject.

get_owner_by_id(owner_id: str = '', owner_email: str = '', user_id: str = '') PublicOwner

Returns an owner object with details about a HubSpot user denoted as an owner of another HubSpot object, such as a contact or company. You may provide the identifier as owner_id, owner_email, or user_id. The owner_id will correspond to fields from the CRM API while the user_id will correspond to the user provisioning API (see keyword Get User).

The owner object has the following attributes (accessible via dot notation):

If more than one of these IDs are provided, the keyword prefers the owner_id, then owner_email, then the user_id.

Parameters
  • owner_id – The owner’s HubSpot ID.

  • owner_email – The email address registered to the owner.

  • user_id – The owner’s associated HubSpot user ID.

Returns

The requested PublicOwner object.

get_owner_of_object(hs_object: Union[SimplePublicObject, SimplePublicObjectWithAssociations, Dict], owner_property: Optional[str] = None) PublicOwner

Looks up the owner of a given Hubspot object, the provided object should be from this library or it should be a dictionary with an hubspot_owner_id key. If the object has no owner, this keyword returns None. See keyword Get owner by ID for information about the returned object.

You can use an alternate property as the owner ID property by providing it with argument owner_property. If that property does not exist this keyword will try the default hubspot_owner_id property, instead.

Parameters
  • object – A HubSpot object, best if the object was obtained via another keyword such as Get owner by ID

  • owner_property – An alternate property of the provided object to use as the field containing the Owner to be looked up.

Returns

The PublicOwner of the provided object.

get_pipeline(object_type: str, pipeline_id: str, use_cache: bool = True) Pipeline

Returns the object_type pipeline identified by pipeline_id. The provided pipeline_id can be provided as the label (case sensitive) or API ID code.

The Pipeline object returned includes a stages property, which is a list of PipelineStage objects. The stages of the pipeline represent the discreet steps an object travels through within the pipeline. The order of the steps is determined by the display_order property. These properties can be accessessed with dot notation and generator comprehension; however, these are advanced Python concepts, so it is generally easier to use the keyword Get Pipeline Stages to get an ordered dictionary of the stages from first to last.

Example

*** Tasks ***
Get Step One
    ${pipeline}=    Get pipeline    DEALS   default
    ${step_one}=    Evaluate
    ... next((s.label for s in $pipeline.stages if s.display_order == 0))

This keyword caches results for future use, to refresh results from Hupspot, set use_cache to False.

Parameters
  • object_type – The object type to be returned and that has the ID indicated. Custom objects will be validated against the schema.

  • pipeline_id – The numerical pipeline ID or the pipeline label visibal in the HubSpot UI (case sensitive).

  • use_cache – (Optional) Setting this to False will force the system to recache the pipelines from Hubspot.

Returns

The Pipeline object requested.

get_pipeline_stages(object_type: str, pipeline_id: str, label_as_key: bool = True, use_cache: bool = True) Dict[str, Dict]

Returns a dictionary representing the stages available in the requested pipeline. Only pipelines for object_type are searched using the pipeline_id as the label or Hubspot API identifier code.

By default, the keys of the returned dictionary represent the labels of the stages, in order from first to last stage. You can have the keyword return the numerical API ID as the key instead by setting label_as_key to False.

Each item’s value is a dictionary with three keys: id, label and metadata. The id is the numerical API ID associated with the stage and label is the name of that stage. The metadata is a dictionary of metadata associated with that stage (e.g., isClosed and probability for “deals” pipelines) that is unique per pipeline.

Example

*** Settings ***
Library         RPA.Hubspot
Library         RPA.Robocorp.Vault

Task Setup      Authorize Hubspot

*** Tasks ***
Use pipeline stages
    ${stages}=    Get pipeline stages    DEALS    Default
    ${closed_won_stage_id}=    Set variable    ${stages}[Closed Won][id]
    ${deals}=    Search for objects    DEALS
    ...    dealstage    EQ    ${closed_won_stage_id}
    Log    Deals that have been won: ${deals}

*** Keywords ***
Authorize Hubspot
    ${secrets}=    Get secret    hubspot
    Auth with api key    ${secrets}[API_KEY]

This keyword caches results for future use, to refresh results from Hupspot, set use_cache to False.

Parameters
  • object_type – The object type to be returned and that has the ID indicated. Custom objects will be validated against the schema.

  • pipeline_id – The numerical pipeline ID or the pipeline label visibal in the HubSpot UI (case sensitive).

  • label_as_key – (Optional) Defaults to True. Setting this to False will cause the returned dictionary to key off of id instead of label.

  • use_cache – (Optional) Setting this to False will force the system to recache the pipelines from Hubspot.

Returns

A dictionary representing the pipeline stages and associated data.

get_user(user_id: str = '', user_email: str = '') Dict

Returns a dictionary with the keys id and email based on the provided user_id or user_email. If both are provided, this keyword will prefer the user_id.

Note

This keyword searches system users, not the CRM owners database.

list_associations(object_type: str, object_id: Union[str, List[str]], to_object_type: str) Union[List[AssociatedId], Dict[str, List[AssociatedId]]]

List associations of an object by type, you must define the object_type with its object_id. You must also provide the associated objects with to_object_type. The API will return a list of dictionaries with the associated object id and association type (e.g., contact_to_company).

You may provide a list of object IDs, if you do, the return object is a dictionary where the keys are the requested IDs and the value associated to each key is a list of associated objects (like a single search).

Parameters
  • object_type – The type of object for the object ID provided, e.g. contact.

  • object_id – The HubSpot ID for the object of type object_type. If you provide a list of object_ids, they will be searched via the batch read API.

  • to_object_type – The type of object associations to return.

Returns

A list of dictionaries representing the associated objects. The associated objects are returned as AssociatedId objects.

list_pipelines(object_type: str, archived: bool = False, use_cache: bool = True) List[Pipeline]

Returns a list of all pipelines configured in Hubspot for the provided object_type. By default only active, unarchived pipelines are returned.

This keyword caches results for future use, to refresh results from Hupspot, set use_cache to False.

Parameters
  • object_type – The object type to be returned and that has the ID indicated. Custom objects will be validated against the schema.

  • archived – (Optional) Setting this to True will return archived pipelines as well.

  • use_cache – (Optional) Setting this to False will force the system to recache the pipelines from Hubspot.

Returns

A list of Pipeline objects representing the pipelines associated with the provided object_type.

property pipelines: Dict[str, List[Pipeline]]
property schemas: List[ObjectSchema]
search_for_objects(object_type: str, *natural_search, search: Optional[List[Dict]] = None, string_query: str = '', properties: Optional[Union[List[str], str]] = None, max_results: int = 1000) List[SimplePublicObject]

Returns a list of objects of the specified type based on the provided search criteria. The following types are supported:

  • COMPANIES

  • CONTACTS

  • DEALS

  • FEEDBACK SUBMISSIONS

  • PRODUCTS

  • TICKETS

  • LINE ITEMS

  • QUOTES

  • Custom objects, which can be provided as the name of the object or the custom object ID in Hubspot.

Returns no more than max_results which defaults to 1,000 records. Provide 0 for all results.

By default, search criteria can be passed as additional unlabeled arguments to the keyword. They must be provided in order: property_name, operator, value. Boolean operators AND and OR can be used, but if both are used, groups of criteria combined with AND will be combined first, with each of those groups being combined with OR second. You can only define a maximum of three groups of filters combined with OR and each of those groups can have no more than three filters combined with AND.

You can use the following operators in your search:

OPERATOR

DESCRIPTION

LT

Less than

LTE

Less than or equal to

GT

Greater than

GTE

Greater than or equal to

EQ

Equal to

NEQ

Not equal to

BETWEEN

Within the specified range

IN

Included within the specified list

NOT_IN

Not included within the specified list

HAS_PROPERTY

Has a value for the specified property. When using this operator, or its opposite below, you cannot provide a value.

NOT_HAS_PROPERTY

Doesn’t have a value for the specified property.

CONTAINS_TOKEN

Contains a token.

NOT_CONTAINS_TOKEN

Doesn’t contain a token.

Example search:

*** Settings ***
Library         RPA.Hubspot
Library         RPA.Robocorp.Vault
Task Setup      Authorize Hubspot

*** Tasks ***
Obtain contacts with search
    ${contacts}=    Search for objects    CONTACTS
    ...    firstname    EQ    Alice    AND    lastname    NEQ    Smith
    ...    OR    enum1    HAS_PROPERTY
    ${message}=    Catenate    These contacts will have the first name "Alice" but not the last name "Smith",
    ...    or they will have a value in the proeprty "enum1": ${contacts}
    Log    ${message}

*** Keywords ***
Authorize Hubspot
    ${secrets}=    Get secret    hubspot
    Auth with api key    ${secrets}[API_KEY]
Object Searching

Alternatively, search criteria can be passed as a list of dictionaries to the label-only parameter search.

To include multiple filter criteria, you can group filters within filterGroups:

  • When multiple filters are present within a filterGroup, they’ll be combined using a logical AND operator.

  • When multiple filterGroups are included in the request body, they’ll be combined using a logical OR operator.

You can include a maximum of three filterGroups with up to three filters in each group.

from RPA.Hubspot import Hubspot
from RPA.Robocorp.Vault import RobocorpVault

vault = RobocorpVault()
secrets = vault.get_secret("hubspot")

hs = Hubspot(secrets["API_KEY"])

combination_search = [
    {
        "filters": [
            {
                "propertyName": "firstname",
                "operator": "EQ",
                "value": "Alice",
            },
            {
                "propertyName": "lastname",
                "operator": "NEQ",
                "value": "Smith",
            },
        ]
    },
    {"filters": [{"propertyName": "enum1", "operator": "HAS_PROPERTY"}]},
]
contacts = hs.search_for_objects("CONTACTS", search=combination_search)
print(
    "These contacts will have the first name 'Alice' but not the "
    + "last name 'Smith', or they will have a value in the "
    + f"property 'enum1': {contacts}"
)
Controlling Returned Properties

You can retrieve additional properties for the objects by defining them with properties. Properties must be provided as a single property as a string, or a list of properties as a list. If a requested property does not exist, it will be ignored.

Using Associations

Associated objects can be used as search criteria by using the pseudo-property associations.{object_type}, where {object_type} is a valid object type, such as contact, but this is not supported when seaching custom objects.

Text-based Search Query

If you want to search all text-based fields with a simple string, it can be provided via the optional label-only parameter string_query. This cannot be used at the same time with search_object or natural_search parameters.

param natural_search

all additional unlabeled parameters will be parsed as a natural language search.

param search

the search object to use as search criteria.

param string_query

a string query can be provided instead of a search object which is used as a text-based search in all default searchable properties in Hubspot.

param properties

a list of strings representing return properties to be included in the returned data.

return

A list of found HubSpot objects of type SimplePublicObject.

set_association(object_type: str, object_id: str, to_object_type: str, to_object_id: str, association_type: str = None) SimplePublicObjectWithAssociations

Sets an association between two Hubspot objects. You must define the primary object_type and it’s Hubspot object_id, as well as the Hubspot object it is to be associated with by using the to_object_type and to_object_id. You may also define the association_type, but if not, one will be inferred based on the provided object types, for example, if object_type is company and to_object_type is contact, the inferred association_type will be company_to_contact.

Returns the object with it’s associations.

Parameters
  • object_type – The type of object for the object ID provided, e.g. contact.

  • object_id – The HubSpot ID for the object of type object_type.

  • to_object_type – The type of object to associate the object_id to.

  • to_object_id – The HubSpot ID for the object to associate the object_id to.

Returns

The object represented by the object_id with the new association. The associations will be available on the returned object’s associations property.

set_current_batch_input(batch_input: BatchInputFactory) None

Sets the current batch input to the provided one.

See Batch Inputs` for complete information on using the batch input API.

Parameters

batch_input – A batch object such as one returned from the Get current batch keyword.

update_object(object_type: str, object_id: Union[str, List[str]], id_property: Optional[str] = None, **properties) SimplePublicObject

Performs a partial update of an Object identified by object_type and object_id with the provided properties in Hubspot. The objects can be found using an alternate ID by providing the name of that HubSpot property which contains the unique identifier to id_property. The object_type parameter automatically looks up custom object IDs based on the provided name.

The Hubspot properties to be updated must be provided as additional labeled paremeters to this keyword.

Returns the newly created object. The new object’s id is available via the property id.

Parameters
  • object_type – The object type to be created.

  • object_id – The HubSpot ID of the object to be updated

  • properties – All remaining labeled parameters passed into this keyword will be used as the properties of the new object. Read-only or nonexistent properties will be ignored.