temba_client.v2 package

This package contains the temba_client.v2.TembaClient client class. This is client for the v2 API which is current stable API version recommended for most users.

Module contents

class temba_client.v2.TembaClient(host, token, user_agent=None, verify_ssl=None)[source]

Bases: temba_client.clients.BaseCursorClient

Client for the Temba API v2

Parameters:
  • host (str) – server hostname, e.g. ‘rapidpro.io’
  • token (str) – organization API token
  • user_agent (str) – string to be included in the User-Agent header
bulk_add_contacts(contacts, group)[source]

Adds contacts to a group

Parameters:
  • contacts (list[*]) – contact objects, UUIDs or URNs
  • group (*) – contact group object or UUID
bulk_archive_contacts(contacts)[source]

Archives all messages for contacts

Parameters:contacts (list[*]) – contact objects, UUIDs or URNs
bulk_archive_messages(messages)[source]

Archives messages

Parameters:messages (list[*]) – message objects or ids
bulk_block_contacts(contacts)[source]

Blocks contacts

Parameters:contacts (list[*]) – contact objects, UUIDs or URNs
bulk_delete_contacts(contacts)[source]

Deletes contacts

Parameters:contacts (list[*]) – contact objects, UUIDs or URNs
bulk_delete_messages(messages)[source]

Deletes messages

Parameters:messages (list[*]) – message objects or ids
bulk_interrupt_contacts(contacts)[source]

Interrupt active flow runs for contacts

Parameters:contacts (list[*]) – contact objects, UUIDs or URNs
bulk_label_messages(messages, label=None, label_name=None)[source]

Labels messages

Parameters:
  • messages (list[*]) – message objects or ids
  • label (*) – existing label object or UUID
  • label_name (str) – label name which can be created if required
bulk_remove_contacts(contacts, group)[source]

Removes contacts from a group

Parameters:
  • contacts (list[*]) – contact objects, UUIDs or URNs
  • group (*) – contact group object or UUID
bulk_restore_messages(messages)[source]

Restores previously archived messages

Parameters:messages (list[*]) – message objects or ids
bulk_unblock_contacts(contacts)[source]

Un-blocks contacts

Parameters:contacts (list[*]) – contact objects, UUIDs or URNs
bulk_unlabel_messages(messages, label=None, label_name=None)[source]

Un-labels messages

Parameters:
  • messages (list[*]) – message objects or ids
  • label (*) – existing label object or UUID
  • label_name (str) – label name which is ignored if doesn’t exist
create_broadcast(text, urns=None, contacts=None, groups=None)[source]

Creates and sends a broadcast to the given URNs, contacts or contact groups

Parameters:
  • text (str) – message text
  • urns (list[str]) – list of URN strings
  • contacts (list) – list of contact objects or UUIDs
  • groups (list) – list of group objects or UUIDs
Returns:

the new broadcast

create_campaign(name, group)[source]

Creates a new campaign

Parameters:
  • name (str) – campaign name
  • group (*) – group object, UUID or name
Returns:

the new campaign

create_campaign_event(campaign, relative_to, offset, unit, delivery_hour, message=None, flow=None)[source]

Creates a new campaign event

Parameters:
  • campaign (*) – campaign object, UUID or name
  • relative_to (str) – contact field key
  • offset (int) –
  • unit (str) –
  • delivery_hour (int) –
  • message (str) –
  • flow (*) – flow object, UUID or name
Returns:

the new campaign

create_contact(name=None, language=None, urns=None, fields=None, groups=None)[source]

Creates a new contact

Parameters:
  • name (str) – full name
  • language (str) – the language code, e.g. “eng”
  • urns (list[str]) – list of URN strings
  • fields (dict[str,str]) – dictionary of contact field values
  • groups (list) – list of group objects, UUIDs or names
Returns:

the new contact

create_field(label, value_type)[source]

Creates a new contact field

Parameters:
  • label (str) – field label
  • value_type (str) – field value type
Returns:

the new field

create_flow_start(flow, urns=None, contacts=None, groups=None, restart_participants=None, extra=None)[source]

Creates a new flow start

Parameters:
  • flow (str) – flow UUID
  • urns (list[str]) – URNs of contacts to start
  • contacts (list[str]) – UUIDs of contacts to start
  • groups (list[str]) – UUIDs of contact groups to start
  • restart_participants (bool) – whether to restart participants already in this flow
  • extra (*) – a dictionary of extra parameters to pass to the flow
Returns:

the new label

create_group(name)[source]

Creates a new contact group

Parameters:name (str) – group name
Returns:the new group
create_label(name)[source]

Creates a new message label

Parameters:name (str) – label name
Returns:the new label
create_resthook_subscriber(resthook, target_url)[source]

Creates a new resthook subscriber

Parameters:
  • resthook – the resthook slug
  • target_url – the target URL
Returns:

the new subscriber

delete_campaign_event(event)[source]

Deletes an existing contact group

Parameters:event (*) – campaign event object or UUID
delete_contact(contact)[source]

Deletes an existing contact

Parameters:contact (*) – contact object, UUID or URN
delete_group(group)[source]

Deletes an existing contact group

Parameters:group (*) – group object or UUID
delete_label(label)[source]

Deletes an existing message label

Parameters:label (*) – label object or UUID
delete_resthook_subscriber(subscriber)[source]

Deletes an existing resthook subscriber

Parameters:subscriber (*) – the resthook subscriber or id
get_boundaries(geometry=None)[source]

Gets all administrative boundaries

Returns:boundary query
get_broadcasts(id=None, before=None, after=None)[source]

Gets all matching broadcasts

Parameters:
  • id – broadcast id
  • before (datetime) – created before
  • after (datetime) – created after
Returns:

broadcast query

get_campaign_events(uuid=None, campaign=None)[source]

Gets all matching campaign events

Parameters:
  • uuid – event UUID
  • campaign – campaign object or UUID
Returns:

campaign event query

get_campaigns(uuid=None)[source]

Gets all matching campaigns

Parameters:uuid – campaigns UUID
Returns:campaign query
get_channel_events(id=None, contact=None, before=None, after=None)[source]

Gets all matching channel events

Parameters:
  • id – event id
  • contact – contact object or UUID
  • before (datetime) – created before
  • after (datetime) – created after
Returns:

channel event query

get_channels(uuid=None, address=None)[source]

Gets all matching channels

Parameters:
  • uuid – channel UUID
  • urn – channel address
Returns:

channel query

get_contacts(uuid=None, urn=None, group=None, deleted=None, before=None, after=None)[source]

Gets all matching contacts

Parameters:
  • uuid – contact UUID
  • urn – contact URN
  • group – contact group name or UUID
  • deleted – return deleted contact only
  • before (datetime) – modified before
  • after (datetime) – modified after
Returns:

contact query

get_definitions(flows=(), campaigns=(), dependencies=None)[source]

Gets an export of specified definitions

Parameters:
  • flows – flow objects or UUIDs to include
  • campaigns – campaign objects or UUIDs to include
  • dependencies – whether to include dependencies
Returns:

definitions export

get_fields(key=None)[source]

Gets all matching contact fields

Parameters:key – field key
Returns:field query
get_flow_starts(uuid=None)[source]

Gets all matching flows starts

Parameters:uuid – flow start UUID
Returns:flow start query
get_flows(uuid=None)[source]

Gets all matching flows

Parameters:uuid – flow UUID
Returns:flow query
get_groups(uuid=None, name=None)[source]

Gets all matching contact groups

Parameters:
  • uuid – group UUID
  • name – group name
Returns:

group query

get_labels(uuid=None, name=None)[source]

Gets all matching message labels

Parameters:
  • uuid – label UUID
  • name – label name
Returns:

label query

get_messages(id=None, broadcast=None, contact=None, folder=None, label=None, before=None, after=None)[source]

Gets all matching messages

Parameters:
  • id – message id
  • broadcast – broadcast id
  • contact – contact object or UUID
  • folder – folder name
  • label – message label name or UUID
  • before (datetime) – created before
  • after (datetime) – created after
Returns:

message query

get_org(retry_on_rate_exceed=False)[source]

Gets the current organization

Parameters:retry_on_rate_exceed – whether to sleep and retry if request rate limit exceeded
Returns:the org
get_resthook_events(resthook=None)[source]

Gets all resthook events

Parameters:resthook – the resthook slug
Returns:resthook event query
get_resthook_subscribers(id=None, resthook=None)[source]

Gets all resthook subscribers

Parameters:
  • id – subscriber id
  • resthook – the resthook slug
Returns:

resthook subscriber query

get_resthooks()[source]

Gets all resthooks

Returns:resthook query
get_runs(id=None, flow=None, contact=None, responded=None, before=None, after=None)[source]

Gets all matching flow runs

Parameters:
  • id – flow run id
  • flow – flow object or UUID
  • contact – contact object or UUID
  • responded – whether to limit results to runs with responses
  • before (datetime) – modified before
  • after (datetime) – modified after
Returns:

flow run query

update_campaign(campaign, name, group)[source]

Updates an existing campaign

Parameters:
  • campaign (*) – campaign object, UUID or URN
  • name (str) – campaign name
  • group (*) – group object, UUID or name
Returns:

the updated campaign

update_campaign_event(event, relative_to, offset, unit, delivery_hour, message=None, flow=None)[source]

Updates an existing campaign event

Parameters:
  • event (*) – campaign event object, UUID or name
  • relative_to (str) – contact field key
  • offset (int) –
  • unit (str) –
  • delivery_hour (int) –
  • message (str) –
  • flow (*) – flow object, UUID or name
Returns:

the new campaign

update_contact(contact, name=None, language=None, urns=None, fields=None, groups=None)[source]

Updates an existing contact

Parameters:
  • contact (*) – contact object, UUID or URN
  • name (str) – full name
  • language (str) – the language code, e.g. “eng”
  • urns (list[str]) – list of URN strings
  • fields (dict[str,str]) – dictionary of contact field values
  • groups (list) – list of group objects or UUIDs
Returns:

the updated contact

update_field(field, label, value_type)[source]

Updates an existing contact field

Parameters:
  • field (*) – contact field object or key
  • label (str) – field label
  • value_type (str) – field value type
Returns:

the updated field

update_group(group, name)[source]

Updates an existing contact group

Parameters:
  • group (*) – group object or UUID
  • name (str) – group name
Returns:

the updated group

update_label(label, name)[source]

Updates an existing message label

Parameters:
  • label (*) – label object or UUID
  • name (str) – label name
Returns:

the updated label