Action Network

Overview

Action Network is an online tool for storing information and organizing volunteers and donors. It is used primarily for digital organizing and event mangement. For more information, see Action Network developer docs

Note

Authentication

Only ActionNetwork accounts of the partner tier are able to access their API. You can generate your key from the API & Sync page, located in the Start Organizing menu, under Details.

Quick Start

To instantiate a class, you can either pass in the API token as an argument or set the AN_API_TOKEN environmental variable.

from parsons import ActionNetwork

# First approach: Use API credentials via environmental variables
an = ActionNetwork()

# Second approach: Pass API credentials as arguments
an = ActionNetwork(api_token='MY_API_TOKEN')

You can then call various endpoints:

# List all people stored in Action Network
all_contacts = an.get_people()

# Add a person
an.add_person('person.email@fakeemail.com')

# Add a tag
an.add_tag('fake_tag')

# Update a person
an.update_person('fake_id', given_name='new_given_name', tags=['tag_1', 'tag_2'])

API

class parsons.ActionNetwork(api_token=None)[source]
Args:
api_token: str

The OSDI API token

get_people(limit=None, per_page=25, page=None, filter=None)[source]
Args:
limit:

The number of entries to return. When None, returns all entries.

per_page

The number of entries per page to return. 25 maximum.

page

Which page of results to return

filter

The OData query for filtering results. E.g. “modified_date gt ‘2014-03-25’”. When None, no filter is applied.

Returns:

A list of JSONs of people stored in Action Network.

get_person(person_id)[source]
Args:
person_id:

Id of the person.

Returns:

A JSON of the entry. If the entry doesn’t exist, Action Network returns {'error': 'Couldn't find person with id = <id>'}.

upsert_person(email_address=None, given_name=None, family_name=None, tags=None, languages_spoken=None, postal_addresses=None, mobile_number=None, mobile_status='subscribed', background_processing=False, **kwargs)[source]

Creates or updates a person record. In order to update an existing record instead of creating a new one, you must supply an email or mobile number which matches a record in the database.

Identifiers are intentionally not included as an option on this method, because their use can cause buggy behavior if they are not globally unique. ActionNetwork support strongly encourages developers not to use custom identifiers.

Args:
email_address:
Either email_address or mobile_number are required. Can be any of the following
  • a string with the person’s email

  • a list of strings with a person’s emails

  • a dictionary with the following fields
    • email_address (REQUIRED)

    • primary (OPTIONAL): Boolean indicating the user’s primary email address

    • status (OPTIONAL): can taken on any of these values
      • “subscribed”

      • “unsubscribed”

      • “bouncing”

      • “previous bounce”

      • “spam complaint”

      • “previous spam complaint”

given_name:

The person’s given name

family_name:

The person’s family name

tags:

Optional field. A list of strings of pre-existing tags to be applied to the person.

languages_spoken:

Optional field. A list of strings of the languages spoken by the person

postal_addresses:

Optional field. A list of dictionaries. For details, see Action Network’s documentation: https://actionnetwork.org/docs/v2/person_signup_helper

mobile_number:
Either email_address or mobile_number are required. Can be any of the following
  • a string with the person’s cell phone number

  • an integer with the person’s cell phone number

  • a list of strings with the person’s cell phone numbers

  • a list of integers with the person’s cell phone numbers

  • a dictionary with the following fields
    • number (REQUIRED)

    • primary (OPTIONAL): Boolean indicating the user’s primary mobile number

    • status (OPTIONAL): can taken on any of these values
      • “subscribed”

      • “unsubscribed”

mobile_status:

‘subscribed’ or ‘unsubscribed’

background_request: bool

If set true, utilize ActionNetwork’s “background processing”. This will return an immediate success, with an empty JSON body, and send your request to the background queue for eventual processing. https://actionnetwork.org/docs/v2/#background-processing

**kwargs:

Any additional fields to store about the person. Action Network allows any custom field.

Adds a person to Action Network

add_person(email_address=None, given_name=None, family_name=None, tags=None, languages_spoken=None, postal_addresses=None, mobile_number=None, mobile_status='subscribed', **kwargs)[source]

Creates a person in the database. WARNING: this endpoint has been deprecated in favor of upsert_person.

update_person(entry_id, background_processing=False, **kwargs)[source]

Updates a person’s data in Action Network, given their Action Network ID. Note that you can’t alter a person’s tags with this method. Instead, use upsert_person.

Args:
entry_id:

The person’s Action Network id

background_processing: bool

If set true, utilize ActionNetwork’s “background processing”. This will return an immediate success, with an empty JSON body, and send your request to the background queue for eventual processing. https://actionnetwork.org/docs/v2/#background-processing

**kwargs:
Fields to be updated. The possible fields are
email_address:
Can be any of the following
  • a string with the person’s email

  • a dictionary with the following fields
    • email_address (REQUIRED)
      • primary (OPTIONAL): Boolean indicating the user’s

      primary email address

    • status (OPTIONAL): can taken on any of these values
      • “subscribed”

      • “unsubscribed”

      • “bouncing”

      • “previous bounce”

      • “spam complaint”

      • “previous spam complaint”

given_name:

The person’s given name

family_name:

The person’s family name

languages_spoken:

Optional field. A list of strings of the languages spoken by the person

postal_addresses:

Optional field. A list of dictionaries. For details, see Action Network’s documentation: https://actionnetwork.org/docs/v2/people#put

custom_fields:

A dictionary of any other fields to store about the person.

get_tags(limit=None, per_page=None)[source]
Args:
limit:

The number of entries to return. When None, returns all entries.

per_page:

This is a deprecated argument.

Returns:

A list of JSONs of tags in Action Network.

get_tag(tag_id)[source]
Args:
tag_id:

Id of the tag.

Returns:

A JSON of the entry. If the entry doesn’t exist, Action Network returns “{‘error’: ‘Couldn’t find tag with id = <id>’}”

add_tag(name)[source]
Args:
name:

The tag’s name. This is the ONLY editable field

Adds a tag to Action Network. Once created, tags CANNOT be edited or deleted.

create_event(title, start_date=None, location=None)[source]

Create an event in Action Network

Args:
title: str

The public title of the event

start_date: str OR datetime

OPTIONAL: The starting date & time. If a string, use format “YYYY-MM-DD HH:MM:SS” (hint: the default format you get when you use str() on a datetime)

location: dict

OPTIONAL: A dict of location details. Can include any combination of the types of values in the following example: .. code-block:: python

my_location = {

“venue”: “White House”, “address_lines”: [

“1600 Pennsylvania Ave”

], “locality”: “Washington”, “region”: “DC”, “postal_code”: “20009”, “country”: “US”

}

Returns:

Dict of Action Network Event data.