Authentication

Node

class contacthub.node.Node(workspace, node_id)[source]

Bases: object

Node class for accessing data on a Contacthub node.

add_customer(force_update=False, **attributes)[source]

Add a new customer in contacthub. If the customer already exist and force update is true, this method will update the entire customer with new data

Parameters:
  • attributes – the attributes for inserting the customer in the node
  • force_update – a flag for update an already present customer
Returns:

the customer added or updated

add_customer_session(customer_id, session_id)[source]

Add a new session id for a customer.

Parameters:
  • customer_id – the customer ID for adding the session id
  • session_id – a session ID for create a new session
Returns:

the session id of the new session inserted

add_education(customer_id, **attributes)[source]

Insert a new Education for the given Customer

Parameters:
  • customer_id – the id of the customer for adding the Education
  • attributes – the attributes representing the new Education to add
Returns:

a Education object representing the added Education

add_event(**attributes)[source]

Add an event in this node. For adding it and associate with a known customer, specify the customer id in the attributes of the Event. For associate it to an external Id or a session id of a customer, specify in the bringBackProperties object like: {‘type’:’EXTERNAL_ID’, ‘value’:’value’, ‘nodeId’:’nodeId’ }

Parameters:attributes – the attributes of the event to add in the node
Returns:a new Event object representing the event added in this node
add_job(customer_id, **attributes)[source]

Insert a new Job for the given Customer

Parameters:
  • customer_id – the id of the customer for adding the job
  • attributes – the attributes representing the new job to add
Returns:

a Job object representing the added Job

add_like(customer_id, **attributes)[source]

Insert a new Like for the given Customer

Parameters:
  • customer_id – the id of the customer for adding the Like
  • attributes – the attributes representing the new Like to add
Returns:

a Like object representing the added Like

add_subscription(customer_id, **attributes)[source]

Insert a new Subscription for the given Customer

Parameters:
  • customer_id – the id of the customer for adding the Subscription
  • attributes – the attributes representing the new Subscription to add
Returns:

a Subscription object representing the added Subscription

add_tag(customer_id, tag)[source]

Add a new tag in the list of customer’s tags

Parameters:
  • customer_id – the id customer in which adding the tag
  • tag – a string, int, representing the tag to add
static create_session_id()[source]

Create a new random session id conformed to the UUID standard

Returns:a new session id conformed to the UUID standard
delete_customer(id, **attributes)[source]

Delete the specified Customer from contacthub. For deleting an existing customer object, you should:

node.delete_customer(**c.to_dict())
Parameters:
  • id – a the id of the customer to delete
  • attributes – the attributes of the customer to delete
Returns:

an object representing the deleted customer

get_customer(id=None, external_id=None)[source]

Retrieve a customer from the associated node by its id or external ID. Only one parameter can be specified for getting a customer.

Parameters:
  • id – the id of the customer to retrieve
  • external_id – the external id of the customer to retrieve
Returns:

a Customer object representing the fetched customer

get_customer_education(customer_id, education_id)[source]

Get an education associated to a customer by its ID

Parameters:
  • education_id – the unique id of the education to get in a customer
  • customer_id – the id of the customer for getting the education
Returns:

a new Education object containing the attributes associated to the education

get_customer_job(customer_id, job_id)[source]

Get a job associated to a customer by its ID

Parameters:
  • job_id – the unique id of the job to get in a customer
  • customer_id – the id of the customer for getting the job
Returns:

a new Job object containing the attributes associated to the job

get_customer_like(customer_id, like_id)[source]

Get a like associated to a customer by its ID

Parameters:
  • like_id – the unique id of the like to get in a customer
  • customer_id – the id of the customer for getting the like
Returns:

a new Like object containing the attributes associated to the like

get_customer_subscription(customer_id, subscription_id)[source]

Get an subscription associated to a customer by its ID

Parameters:
  • subscription_id – the unique id of the subscription to get in a customer
  • customer_id – the id of the customer for getting the subscription
Returns:

a new Subscription object containing the attributes associated to the subscription

get_customers(external_id=None, page=None, size=None, fields=None)[source]

Get all the customers in this node

Parameters:
  • external_id – the external id of the customer to retrieve
  • size – the size of the pages containing customers
  • page – the number of the page for retrieve customer data
  • fields – : a list of strings representing the properties to include in the response
Returns:

A list containing Customer object of a node

get_event(id)[source]

Get a single event by its own id

Parameters:id – the id of the event to get
Returns:a new Event object representing the fetched event
get_events(customer_id, event_type=None, context=None, event_mode=None, date_from=None, date_to=None, page=None, size=None)[source]

Get all events associated to a customer.

Parameters:
  • customer_id – The id of the customer owner of the event
  • event_type – the type of the event present in Event.TYPES
  • context – the context of the event present in Event.CONTEXT
  • event_mode – the mode of event. ACTIVE if the customer made the event, PASSIVE if the customer recive the event
  • date_from – From string or datetime for search of event
  • date_to – From string or datetime for search of event
  • size – the size of the pages containing events
  • page – the number of the page for retrieve event data
Returns:

a list containing the fetched events associated to the given customer id

query(entity)[source]

Create a QueryBuilder object for a given entity, that allows to filter the entity’s data

Parameters:entity – A class of model on which to run the query
Returns:A QueryBuilder object for the specified entity
remove_education(customer_id, education_id)[source]

Remove a the given Education for the given Customer

Parameters:
  • customer_id – the id of the customer associated to the Education to remove
  • education_id – the id of the Education to remove
remove_job(customer_id, job_id)[source]

Remove a the given Job for the given Customer

Parameters:
  • customer_id – the id of the customer associated to the job to remove
  • job_id – the id of the job to remove
remove_like(customer_id, like_id)[source]

Remove a the given Like for the given Customer

Parameters:
  • customer_id – the id of the customer associated to the Like to remove
  • like_id – the id of the Like to remove
remove_subscription(customer_id, subscription_id)[source]

Remove a the given Subscription for the given Customer

Parameters:
  • customer_id – the id of the customer associated to the Subscription to remove
  • subscription_id – the id of the Subscription to remove
remove_tag(customer_id, tag)[source]

Remove (if exists) a tag in the list of customer’s tag

Parameters:
  • customer_id – the id customer in which adding the tag
  • tag – a string, int, representing the tag to add
update_customer(id, full_update=False, **attributes)[source]

Update a customer in contacthub with new data. If full_update is true, this method will update the full customer (PUT) and not only the changed data (PATCH)

Parameters:
  • id – the customer ID for updating the customer with new attributes
  • full_update – a flag for execute a full update to the customer
  • attributes – the attributes to patch or put in the customer
Returns:

the customer updated

update_education(customer_id, id, **attributes)[source]

Update the given Education of the given customer with new specified attributes

Parameters:
  • customer_id – the id of the customer associated to the Education to update
  • id – the id of the Education to update
  • attributes – the attributes for update the Education
Returns:

a Education object representing the updated Education

update_job(customer_id, id, **attributes)[source]

Update the given job of the given customer with new specified attributes

Parameters:
  • customer_id – the id of the customer associated to the job to update
  • id – the id of the job to update
  • attributes – the attributes for update the job
Returns:

a Job object representing the updated Job

update_like(customer_id, id, **attributes)[source]

Update the given Like of the given customer with new specified attributes

Parameters:
  • customer_id – the id of the customer associated to the Like to update
  • id – the id of the Like to update
  • attributes – the attributes for update the Like
Returns:

a Like object representing the updated Like

update_subscription(customer_id, id, **attributes)[source]

Update the given Subscription of the given customer with new specified attributes

Parameters:
  • customer_id – the id of the customer associated to the Subscription to update
  • id – the id of the Subscription to update
  • attributes – the attributes for update the Subscription
Returns:

a Subscription object representing the updated Subscription

Workspace

class contacthub.workspace.Workspace(workspace_id, token, base_url='https://api.contactlab.it/hub/v1/workspaces')[source]

Bases: object

Workspace class for authenticating on the specified base url APIs. This class is the first step for accessing the Contacthub APIs, the higher level.

classmethod from_ini_file(file_path)[source]

Create a new Workspace object, taking the Workspace id, the token and the base URL from a INI configuration file

Parameters:file_path – The path of the INI file for the parameters
Returns:a new Workspace object
get_node(node_id)[source]

Retrieve the node associated at the specified node id

Parameters:node_id – The ID of the node to retrieve
Returns:a Node object with the Workspace object specified