Library.Hubspot (Portico/Z v0.1.0)

HubSpot API context.

Requires config.exs to have a setup incantation like so:

config :library, 
  Library.Hubspot: [
    api_key: "yer key",
    portal_id: "yer id"
  ]

Link to this section Summary

Functions

Get a HS contact by email

Get rows from a table by name or id.

List all tables in HubSpot

Update contact properties in HS

Link to this section Functions

Link to this function

get_contact(email)

Get a HS contact by email

Returns a big honkin' HS profile JSON on success (see here for more details).

Returns {:error, :not_found} on failure

Examples

iex> example = Library.Hubspot.get_contact("nobody@example.com")
...> %{"vid" => 43036951} = example

iex> Library.Hubspot.get_contact("ghost")
{:error, :not_found}
Link to this function

list_table_rows(table, opts \\ [])

Get rows from a table by name or id.

table can be either the name or the HubDB ID of a table.

opts are forwarded to the HubDB API

Examples

iex> rows = Library.Hubspot.list_table_rows("courses_electives_concentrations")
iex> [%Library.Hubspot.HubdbTableRow{childTableId: "0"} | _] = rows 
Link to this function

list_tables(opts \\ [])

List all tables in HubSpot

opts are forwarded to the HubDB API

Link to this function

post_form(form_id, body \\ %{})

Post a HS Form

See https://legacydocs.hubspot.com/docs/methods/forms/submit_form for details.

Link to this function

update_contact(vid_or_email, properties \\ %{})

Update contact properties in HS

This can work with an integer hubspot_vid or an email address.

Examples

Library.Hubspot.update_contact(vid, %{firstname: "COOL"})
{:ok, %{"id" => vid, ...}}

Library.Hubspot.update_contact(bad_vid, %{prop: "val"})
{:error, %{"status" => "error", ...}}

iex> {:ok, %{"properties" => %{"firstname" => "x"}}} = Library.Hubspot.update_contact("nobody@example.com", %{firstname: "x"})
Link to this function

update_table_row(table, row_id, params, opts \\ [])

Update a row in a table.

table can be either the name or the HubDB ID of a table.

row_id needs to be the ID of a row, typically found using list_table_rows/2.

params are forwarded to the HubDB API. See Library.Hubspot.HubdbTableRow.update_params/2 for details of the format.