ActionKit

Overview

ActionKit is a platform for advocacy, fundraising, and get-out-the-vote. This Parsons integration with the ActionKit REST API supports fetching, creating, and updating records of campaigns, events, mailers, orders, survey questions, transactions, and users. Bulk upload of new users and user updates is also supported.

Note

Authentication

ActionKit requires HTTP Basic Auth. Clients with an ActionKit account can obtain the domain, username, and password needed to access the ActionKit API. See the ActionKit REST API Authentication documentation for more information on obtaining ActionKit API credentials.

Quickstart

To instantiate the ActionKit class, you can either store your ActionKit API domain, username, and password as environmental variables (ACTION_KIT_DOMAIN, ACTION_KIT_USERNAME, and ACTION_KIT_PASSWORD, respectively) or pass in your domain, username, and password as arguments:

from parsons import ActionKit

# First approach: Use API credentials via environmental variables
ak = ActionKit()

# Second approach: Pass API credentials as arguments
ak = ActionKit(domain='myorg.actionkit.com', username='my_name', password='1234')

You can then call various endpoints:

# Create a new user
ak.create_user(email='john@email', first_name='John', last_name='Smith', city='Boston')

# Fetch user fields
user_fields = ak.get_user(user_id='123')

# Update user fields
ak.update_user(user_id='123', city='New York')

# Delete uer
ak.delete_user(user_id='123')

API

class parsons.ActionKit(domain=None, username=None, password=None)[source]

Instantiate the ActionKit class

Args:
domain: str

The ActionKit domain (e.g. myorg.actionkit.com) Not required if ACTION_KIT_DOMAIN env variable set.

username: str

The authorized ActionKit username. Not required if ACTION_KIT_USERNAME env variable set.

password: str

The authorized ActionKit user password. Not required if ACTION_KIT_PASSWORD env variable set.

get_user(user_id)[source]

Get a user.

Args:
user_id: int

The user id of the record to get.

Returns:

User json object

get_user_fields()[source]

Get list of valid user fields that can be passed with the ActionKit.create_user() method.

Returns:

List of user fields

create_user(email, **kwargs)[source]

Create a user.

Args:
email: str

Email for the user

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

User json object

update_user(user_id, **kwargs)[source]

Update a user.

Args:
user_id: int

The user id of the person to update

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

None

get_event(event_id)[source]

Get an event.

Args:
event_id: int

The id for the event.

Returns:
dict

Event json object.

get_events(limit=None, **kwargs)[source]

Get multiple events.

Args:
limit: int

The number of events to return. If omitted, all events are returned.

**kwargs:

Optional arguments to pass to the client. A full list can be found in the ActionKit API Documentation.

Additionally, expressions to filter the data can also be provided. For addition info, visit Django’s docs on field lookups.

ak.get_events(fields__name__contains="FirstName")
Returns:
Parsons.Table

The events data.

update_event(event_id, **kwargs)[source]

Update an event.

Args:
event_id: int

The event id of the event to update

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

None

delete_user(user_id)[source]

Delete a user.

Args:
user_id: int

The user id of the person to delete

Returns:

None

get_campaign(campaign_id)[source]

Get a campaign.

Args:
campaign_id: int

The campaign id of the record.

Returns:

Campaign json object

get_campaign_fields()[source]

Get list of valid campaign fields that can be passed with the ActionKit.create_campaign() and ActionKit.update_campaign() methods.

Returns:

List of campaign fields

create_campaign(name, **kwargs)[source]

Create a campaign.

Args:
name: str

The name of the campaign to create

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

API location of new resource

get_event_create_page(event_create_page_id)[source]

Get a event create page.

Args:
event_create_page_id: int

The event create page id of the record to get.

Returns:

Event create page json object

get_event_create_page_fields()[source]

Get list of event create page fields that can be passed with the ActionKit.create_event_create_page().

Returns:

List of event create page fields

create_event_create_page(name, campaign_id, title, **kwargs)[source]

Add an event page to a campaign.

Args:
campaign_id: int

The campaign to assoicate page with

name: str

The name of the page to create

title: str

The title of the page to create

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

API location of new resource

get_event_create_form(event_create_form_id)[source]

Get a event create form.

Args:
event_create_form_id: int

The event create form id of the record to get.

Returns:

Event create form json object

get_event_create_form_fields()[source]

Get list of valid event create form fields that can be passed with the ActionKit.create_event_create_form() method.

Returns:

List of event create form fields

create_event_create_form(page_id, thank_you_text, **kwargs)[source]

Create a event create form.

Args:
page_id: int

The page to associate the form with

thank_you_text: str

Free form thank you text

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

API location of new resource

get_event_signup_page(event_signup_page_id)[source]

Get event signup page.

Args:
event_signup_page_id: int

The event signup page id of the record to get.

Returns:

Event signup page json object

get_event_signup_page_fields()[source]

Get list of valid event signup page fields that can be passed with the ActionKit.create_event_signup_page() method.

Returns:

List of event signup page fields

create_event_signup_page(name, campaign_id, title, **kwargs)[source]

Add an event signup page to a campaign.

Args:
campaign_id: int

The campaign to assoicate page with

name: str

The name of the page to create

title: str

The title of the page to create

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

API location of new resource

get_event_signup_form(event_signup_form_id)[source]

Get a user.

Args:
event_signup_form_id: str

The event signup form id of the record to get.

Returns:

Event signup form json object

get_event_signup_form_fields()[source]

Get list of valid event signup form fields that can be passed with the ActionKit.create_event_signup_form() method.

Returns:

List of event signup form fields

create_event_signup_form(page_id, thank_you_text, **kwargs)[source]

Create a event signup form.

Args:
page_id: int

The page to associate the form with

thank_you_text: str

Free form thank you text

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

API location of new resource

update_event_signup(event_signup_id, **kwargs)[source]

Update an event signup.

Args:
event_signup_id: int

The id of the event signup to update

event_signup_dict: dict

A dictionary of fields to update for the event signup.

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

None

get_mailer(entity_id)[source]

Get a mailer.

Args:
entity_id: int

The entity id of the record to get.

Returns:

Mailer json object

create_mailer(**kwargs)[source]

Create a mailer.

Args:
**kwargs:

Arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

URI of new mailer

copy_mailer(mailer_id)[source]

copy a mailer returns new copy of mailer which should be updatable.

update_mailing(mailer_id, **kwargs)[source]

Update a mailing.

Args:
mailing_id: int

The id of the mailing to update

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

None

rebuild_mailer(mailing_id)[source]

Rebuild a mailer.

Args:
mailing_id: int

Id of the mailer.

Returns:

URI to poll for progress

queue_mailer(mailing_id)[source]

Queue a mailer.

Args:
mailing_id: int

Id of the mailer.

Returns:

URI to poll for progress

update_order(order_id, **kwargs)[source]

Update an order.

Args:
order_id: int

The id of the order to update

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

None

get_page_followup(page_followup_id)[source]

Get a page followup.

Args:
page_followup_id: int

The user id of the record to get.

Returns:

Page followup json object

get_page_followup_fields()[source]

Get list of valid page followup fields that can be passed with the ActionKit.create_page_followup() method.

Returns:

List of page followup fields

create_page_followup(signup_page_id, url, **kwargs)[source]

Add a page followup.

Args:
signup_page_id: int

The signup page to associate the followup page with

url: str

URL of the folloup page

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

API location of new resource

get_survey_question(survey_question_id)[source]

Get a survey question.

Args:
survey_question_id: int

The survey question id of the record to get.

Returns:

Survey question json object

update_survey_question(survey_question_id, **kwargs)[source]

Update a survey question.

Args:
survey_question_id: int

The id of the survey question to update

survey_question_dict: dict

A dictionary of fields to update for the survey question.

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

None

update_transaction(transaction_id, **kwargs)[source]

Update a transaction.

Args:
transaction_id: int

The id of the transaction to update

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:

None

create_generic_action(page, email=None, ak_id=None, **kwargs)[source]

Post a generic action. One of ak_id or email is a required argument.

Args:
page:

The page to post the action. The page short name.

email:

The email address of the user to post the action.

ak_id:

The action kit id of the record.

**kwargs:

Optional arguments and fields to pass to the client. A full list can be found in the ActionKit API Documentation.

Returns:
dict

The response json

bulk_upload_csv(csv_file, import_page, autocreate_user_fields=False, user_fields_only=False)[source]

Bulk upload a csv file of new users or user updates. If you are uploading a table object, use bulk_upload_table instead. See ActionKit User Upload Documentation Be careful that blank values in columns will overwrite existing data.

If you get a 500 error, try sending a much smaller file (say, one row), which is more likely to return the proper 400 with a useful error message

Args:
import_page: str

The page to post the action. The page short name.

csv_file: str or buffer

The csv (optionally zip’d) file path or a file buffer object A user_id or email column is required. ActionKit rejects files that are larger than 128M

autocreate_user_fields: bool

When True columns starting with “user_” will be uploaded as user fields. See the autocreate_user_fields documentation.

user_fields_only: bool

When uploading only an email/user_id column and user_ user fields, ActionKit has a fast processing path. This doesn’t work, if you upload a zipped csv though.

Returns:
dict

success: whether upload was successful progress_url: an API URL to get progress on upload processing res: requests http response object

bulk_upload_table(table, import_page, autocreate_user_fields=0, no_overwrite_on_empty=False, set_only_columns=None)[source]

Bulk upload a table of new users or user updates. See ActionKit User Upload Documentation Be careful that blank values in columns will overwrite existing data.

Tables with only an identifying column (user_id/email) and user_ user fields will be fast-processed – this is useful for setting/updating user fields.

Note

If you get a 500 error, try sending a much smaller file (say, one row), which is more likely to return the proper 400 with a useful error message

Args:
import_page: str

The page to post the action. The page short name.

table: Table Class

A Table of user data to bulk upload A user_id or email column is required.

autocreate_user_fields: bool

When True columns starting with “user_” will be uploaded as user fields. ActionKit. See the autocreate_user_fields documentation.

no_overwrite_on_empty: bool

When uploading user data, ActionKit will, by default, take a blank value and overwrite existing data for that user. This can be undesirable, if the goal is to only send updates. Setting this to True will divide up the table into multiple upload batches, changing the columns uploaded based on permutations of empty columns.

set_only_columns: list

This is similar to no_overwrite_on_empty but restricts to a specific set of columns which, if blank, should not be overwritten.

Returns:
dict

success: bool – whether upload was successful (individual rows may not have been) results: [dict] – This is a list of the full results.

progress_url and res for any results

collect_upload_errors(result_array)[source]

Collect any upload errors as a list of objects from bulk_upload_table ‘results’ key value. This waits for uploads to complete, so it may take some time if you uploaded a large file. Args:

result_array: list

After receiving a dict back from bulk_upload_table you may want to see if there were any errors in the uploads. If you call collect_upload_errors(result_array) it will iterate across each of the uploads fetching the final result of e.g. /rest/v1/uploaderror?upload=123

Returns:
[dict]

message: str – error message upload: str – upload progress API path e.g. “/rest/v1/upload/123456/” id: int – upload error record id (different than upload id)