PDI

Overview

PDI is a political data provider that is primarily active in California. This class allows you to interact with the PDI API .

This Parsons connector provides methods to fetch lists of acquisition types, flag IDs, questions, universes, and flags given start and end dates.

Note

Authentication

A user name, password, and API token are required to instantiate the PDI class. To obtain log in credentials, request a PDI API account from support@politicaldata.com. The administrative process usually takes a couple of hours.

Quickstart

To instantiate the PDI class, you can either store your PDI API username, password, and API token as environmental variables (PDI_USERNAME, PDI_PASSWORD, and PDI_API_TOKEN, respectively) or pass them in as arguments:

from parsons import PDI

# First approach: Use API credentials via environmental variables
pdi = PDI()

# Second approach: Pass API credentials as arguments
pdi = PDI(username='my_username', password='my_password', api_token='my_token')

# Get all contacts (flag IDs) available from PDI
pdi.get_flag_ids()

# Get all flags since the beginning of 2020
pdi.get_flags(start_date='2020-01-01')

PDI Class

class parsons.PDI(username=None, password=None, api_token=None, qa_url=False)[source]
add_email(contact_id: int, email: str, primary=True)

Add an email address to a contact Args:

contact_id: int

Unique ID of the contact you’d like to apply the email to

email: str primary: bool

True indicates that this email address is the contact’s primary email

Returns:
dict

Response from PDI

add_phone(contact_id: int, phone_number: str, phone_type='Mobile', primary=True, extension=None)

Add a phone number to a contact Args:

contact_id: int

Unique ID of the contact you’d like to apply the phone_number to

phone_number: str phone_type: str

Options are Home, Work, Direct, Mobile, Fax, and Other. Defaults to `Mobile

primary: bool

True indicates that this phone number is the contact’s primary phone number

extension: str

Returns:
dict

Response from PDI

create_acquisition_type(acquisition_type: str, acquisition_description: str, acquisition_method: str, page_default: str = None)

Create a new Acquisition Type Args:

acquisition_type (string): The acquisition type acquisition_description (string): The acquisition description acquisition_method (string): The acquisition method Options are:

“Phone” “Canvass” “Mail” “IVR” “Text Message” “Email” “Event” “Online” “Social” “Site” “Other Method” ,

pageDefault (string, optional): The page default.

“Lookup” (Lookup Page) “WalkList” (Create Lists & Files - Walk List) “PhoneList” (Create Lists & Files - Phone List) “PhoneBank” (Online Phone Bank) “Canvassing” (Mobile Canvassing Device) “Import” (Imports)

}

create_activity(activity_name: str, canvassing_shift: bool)

Create a New Activity Args:

activity_name str: The activity name canvassing_shift bool: The canvassing shift

create_activity_assignment(eventactivityid: str, contact_id: str, status: str, completed: bool, confirmed=False, specific_occurrence_start=None)

Create an activity assignement Args:

eventactivityid: str

The ID of the specific event activity you’d like to assign a contact

contact_id: str

The ID of the contact to which the assignment belongs

status: str

Options are: “Yes”, “No”, “Maybe”, “Scheduled”, “Invited”, “Cancelled”, “No-Show”, “Completed”, and “”

completed: boolean

Indicates whether contact attended event

confirmed: boolean

Indicates whether invitation confirmed they will attend the event

specific_occurrence_start: str

If invitation is for a specific occurrence of a recurring event, then the start datetime of the event in UTC formatted as yyyy-MM-ddTHH:mm:ss.fffZ

Returns:
dict

Response from PDI in dictionary object

create_contact(name_prefix='', first_name='', last_name='', middle_name='', name_suffix='', nickname='', occupation='', employer='', volunteer_status='', donor_status='', member_status='', date_of_birth=None, gender=None, pdi_id=None)

Create new contact Args:

pdiId (string, optional): The pdi identifier. pdiId field is ignored when updating. , namePrefix (string): The name prefix. firstName (string): The first name. middleName (string): The middle name. lastName (string): The last name. nameSuffix (string): The name suffix. nickname (string): The nickname. occupation (string): The occupation. employer (string): The employer. volunteerStatus (string): The volunteer status. Options are: “Prospect”, “Active”, “Inactive”, “None”, “” , donorStatus (string): The donor status. Options are: “Prospect”, “Active”, “Inactive”, “None”, “” , memberStatus (string): The member status. Options are: “Prospect”, “Active”, “Inactive”, “None”, “” , dateOfBirth (string, optional): The date of birth. Format allowed: yyyy-MM-dd , gender (string, optional): The gender. Options are: “F”, “M”, “U”

Returns:
parsons.Table

A Parsons table of all the data.

create_event(calendar_id: str, location_id: str, event_name: str, start_datetime: str, end_datetime: str, description=None, all_day=False, recurrencetype=None, recurrence_end_datetime=None, host_phone=None, host_email=None, website=None)

Create event in a specified calendar

Args:
calendar_id: str

The calendar in which you’d like to create an event

location_id: str

The unique ID of the PDI location this event took place/is to take place at

event_name: str

The name of your event

description: str

A short description for your event

start_datetime: str

The start datetime of the event in UTC timezone formatted as yyyy-MM-ddThh:mm:ss.fffZ

end_datetime: str

The end date formatted like start_datetime

is_all_day: bool

set to True if event is an all day event. Defaults to False

recurrencetype: str

Either ‘daily’, ‘weekly’, or ‘monthly’. Defaults to None

recurrence_end_datetime: str

The end time of the last recurrence of the event formatted as yyyy-MM-ddThh:mm:ss.fffZ

host_phone: str

An optional contact phone number for the host. Defaults to None

host_email: str

An optional contact email for the host. Defaults to None

website: str

An optional website for the event. Defualts to None

Returns:
dict

Response from PDI in dictionary object

create_event_activity(calendar_id: str, event_id: str, activity_id: str, location_id: str, activity_name: str, start_datetime: str, end_datetime: str, description=None, recurrencetype=None, recurrence_end_datetime=None, signup_goal=None)

Create event in a specified calendar with an associated activity

Args:
calendar_id: str

The unique ID of the calendar in which you’d like to create an event

event_id: str

The unique ID of the event this activity is to be associated with

activity_id:

The unique ID of the activity type you’d like to add to the event

location_id: str

The unique ID of the PDI location where this event took place/is to take place

activity_name: str

The name of your activity. e.g. ‘Pictionary!’

description: str

A short description for your event activity

start_datetime: str

The start datetime of the event in UTC timezone formatted as yyyy-MM-ddThh:mm:ss.fffZ

end_datetime: str

The end date formatted like start_datetime

recurrencetype: str

Either ‘daily’, ‘weekly’, or ‘monthly’. Defaults to None

recurrence_end_datetime: str

The end time of the last recurrence of the event formatted as yyyy-MM-ddThh:mm:ss.fffZ

signup_goal: int

The goal of how many people you want to complete the activity

Returns:
dict

Response from PDI in dictionary object

create_event_with_activity(calendar_id: str, location_id: str, activity_id: str, event_name: str, activity_name: str, start_datetime: str, end_datetime: str, description=None, all_day=False, recurrencetype=None, recurrence_end_datetime=None, host_phone=None, host_email=None, website=None, signup_goal=None)

Create event in a specified calendar with an associated activity. The activty will be assigned the same start, end time, and recurrance settings as the event.

Args:
calendar_id: str

The unique ID of the calendar in which you’d like to create an event

location_id: str

The unique ID of the PDI location whek this event took place/is to take place

activity_id:

The unique ID of the activity type you’d like to add to the event

event_name: str

The name of your event

activity_name: str

The name of your activity. e.g. ‘Pictionary!’

description: str

A short description for your event

start_datetime: str

The start datetime of the event in UTC timezone formatted as yyyy-MM-ddThh:mm:ss.fffZ

end_datetime: str

The end date formatted like start_datetime

is_all_day = bool

set to True if event is an all day event. Defaults to False

recurrencetype: str

Either ‘daily’, ‘weekly’, or ‘monthly’. Defaults to None

recurrence_end_datetime: str

The end time of the last recurrence of the event formatted as yyyy-MM-ddThh:mm:ss.fffZ

host_phone: str

An optional contact phone number for the host. Defaults to None

host_email: str

An optional contact email for the host. Defaults to None

website: str

An optional website for the event. Defualts to None

signup_goal: int

The goal of how many people you want to complete the activity

Returns:
dict

Response from PDI in dictionary object

create_flag_id(flag_id, is_default, flag_description=None, compile=None)

Save a new flag id.

Args:
flag_id: str

The flag id type. One of: “AMM”, “BNH”, “BNM”, “DEAD”, “DNC”, “DNR”, “ENDR”, “GTD”, “HH”, “L2VT”, “LBO”, “LM”, “LO”, “LS”, “LSD”, “LSR”, “MAYBE”, “MOV”, “NAH”, “NO”, “REF”, “SO”, “SS”, “SUP”, “U”, “UL2VT”, “VL2VT”, “VOL”, “VTD”.

is_default: bool

The default.

flag_description: str

(Optional) The flag id description.

compile: str

(Optional) The compile.

Returns:
str

The identifier for the new flag id.

create_flags(flag_list: list)

Save a list of flags, each flag must look like the dictionary below [

{

“pdiId”: “string”, “flagEntryDate”: An end date formatted like yyyy-MM-dd., “acquisitionTypeId”: “string”, “flagId”: “string”, “questionId”: “string”, “contactId”: “string”

}

]

create_invitation(event_id: str, contact_id: str, status: str, attended: bool, confirmed=False, specific_occurrence_start=None)

Create a PDI event invitation indicating a contact has been registered for an event Args:

event_id: str

The ID of the event to write the RSVP to

contact_id: str

The ID of the contact to which the invitation belongs

status: str

Options are: “Yes”, “No”, “Maybe”, “Scheduled”, “Invited”, “Cancelled”, “No-Show”, “Completed”, and “”

attended: boolean

Indicates whether contact attended event

confirmed: boolean

Indicates whether invitation confirmed they will attend the event. Defaults to False

specific_occurrence_start: str

If invitation is for a specific occurrence of a recurring event, then the start datetime of the event in UTC formatted as yyyy-MM-ddTHH:mm:ss.fffZ

Returns:
dict

Response from PDI in dictionary object

create_location(address: str, name: str)

Create a new PDI address Args:

address: str

A full address including street number, city, state, and zip.

name: str

The name of the location. E.g. “The Overlook Hotel”

Returns:
dict

Response from PDI in dictionary object

create_question(question: str, type: str, category: str, answer_options: list, question_label: str = None, question_description: str = None, candidate_issue_id: str = None, default: bool = True, *args)
answer_options:[

{ “id”: “string”, “flagId”: “string”, “displayDescription”: “string”, “displayCode”: “string” }

]

delete_acquisition_type(id: str)

Delete a Acquisition Type by id. Args:

id: str

The Acquisition Type id

delete_contact(id: str)

Delete a Question by id. Args:

id: str

The Question id

delete_flag(id: str)

Delete a Flag by id. Args:

id: str

The Flag id

delete_flag_id(id)

Delete a flag id.

NOTE: The function returns True (even if the id doesn’t exist) unless there is an error.

Args:
id: str

The flag id identifier.

Returns:
bool

True if the operation is successful.

get_acquisition_type(id: str)

Get a Acquisition Type by id. Args:

id: str

The Acquisition Type id

Returns:
parsons.Table

A Parsons table of all the data.

get_acquisition_types(limit: int = None)

Get a list of Acquisition Types. Args:

limit: int

Specify limit to return.

Returns:
parsons.Table

A Parsons table of all the data.

get_activities(limit: int = None)

Get a list of Activities. Args:

limit: int

Specify limit to return.

Returns:
parsons.Table

A Parsons table of all the data.

get_activity(id: str)

Get a Activity by id. Args:

id: str

The Activity id

Returns:
parsons.Table

A Parsons table of all the data.

get_calendars(limit=None)

Gets a list of calendars. Relevant API docs:

Args:
limit: int

Specify limit to return (max=2000)

Returns:

Parsons Table object with id, name, description, and timeZone records

get_contact(id: str)

Get a Contact by id.

Args:
id: str

The Contact id

Returns:
parsons.Table

A Parsons table of all the data.

get_contacts(email: str = None, phone: str = None, first_name: str = None, last_name: str = None, zip_code: str = None, search_by_email: bool = False, limit: int = None)

Get a list of Contacts. Args:

email: str, email address phone: str, phone number first_name: str, first name last_name: str, last name zip code: str, zip code search_by_email: bool, whether to search using email address limit: int

The number of contacts to return.

Returns:
parsons.Table

A Parsons table of all the data.

get_event_activities(start_date, end_date, limit=None)

Get a list of event activities. Relevant API docs:

Args:
start_date: str

Earliest records to be returned in the API response Per the API docs, use “YYYY-MM-DD” format

end_date: str

Latest records to be returned in the API response. Per the API docs, use “YYYY-MM-DD” format

limit: int

Specify limit to return (max=2000)

Returns:

Parsons Table with event activity responses

get_event_activity_assignments(start_date, end_date, expand, limit=None)

Get a list of event activity assignments. Relevant API docs:

Args:
start_date: str

Earliest records to be returned in the API response Per the API docs, use “YYYY-MM-DD” format

end_date: str

Latest records to be returned in the API response. Per the API docs, use “YYYY-MM-DD” format

expand: bool

Parameter to determine if we return the list of shift assigments expanded or not

limit: int

Specify limit to return (max=2000)

Returns:

Parsons Table with event activity assignment responses

get_event_invitations(event_id: str, expand=True, limit=None)

Get a table of PDI event invitations for a specified event

Args:
event_id: str

ID of event for which you want invitations

expand: bool

If True returns columns for contact (and all contact info) and event)

Returns:
parsons.Table

A Parsons table containing all requested event invitation data.

get_events(first_event_date: str, last_event_date: str, limit=None)

Get a table of PDI events in a given time frame

Args:
first_event_date: str

First date in the timeframe from which you want events formatted at ‘yyy-MM-dd’

last_event_date: str

Last date in the timeframe from which you want events formatted at ‘yyy-MM-dd’

limit: int

The max number of events to return

Returns:
parsons.Table

A Parsons table containing all requested events data.

get_flag_id(id)

Get a specified flag id.

Args:
id: str

The flag id identifier.

Returns:
dict

FlagID object.

get_flag_ids(limit=None)

Get a list of flag ids.

Args:
limit: int

Specify limit to return.

Returns:
parsons.Table

A Parsons table of all the data.

get_flags(start_date, end_date, limit=None)

Get a list of flags.

Args:
start_date: str

A start date formatted like yyyy-MM-dd.

end_date: str

An end date formatted like yyyy-MM-dd.

limit: int

Specify limit to return.

Returns:
parsons.Table

A Parsons table of all the data.

get_locations(limit=None)

Get a list of PDI Locations

Args:
limit: int

The max number of locations to return

Returns:
parsons.Table

A Parsons table containing all requested location data.

get_question(id: str)

Get a Question by id.

Args:
id: str

The Question id

Returns:
parsons.Table

A Parsons table of all the data.

get_questions(limit=None)

Get a list of Questions.

Args:
limit: int

Specify limit to return.

Returns:
parsons.Table

A Parsons table of all the data.

get_universe(id: str)

Get a Universe by id.

Args:
id: str

The Universe id

Returns:
parsons.Table

A Parsons table of all the data.

get_universes(limit=None)

Get a list of Universes.

Args:
limit: int

The number of universes to return.

Returns:
parsons.Table

A Parsons table of all the data.

update_acquisition_type(id: str, acquisition_type: str, acquisition_description: str, acquisition_method: str, page_default: str = None)

Update Acquisition Type Args:

acquisition_type (string): The acquisition type acquisition_description (string): The acquisition description acquisition_method (string): The acquisition method Options are:

“Phone” “Canvass” “Mail” “IVR” “Text Message” “Email” “Event” “Online” “Social” “Site” “Other Method” ,

pageDefault (string, optional): The page default.

“Lookup” (Lookup Page) “WalkList” (Create Lists & Files - Walk List) “PhoneList” (Create Lists & Files - Phone List) “PhoneBank” (Online Phone Bank) “Canvassing” (Mobile Canvassing Device) “Import” (Imports)

}

update_activity(id: str, activity_name: str, canvassing_shift: str)

Update an Activity Args:

id: Activity id activity_name str: The activity name canvassing_shift bool: The canvassing shift

update_activity_assignment(activityassignementid: str, eventactivityid: str, contact_id: str, status=None, completed=None, confirmed=None, specific_occurrence_start=None)

Create an activity assignement Args:

activityassignementid: str

Id of the specific event activity assignement you want to modify

eventactivityid: str

The ID of the specific event activity you’d like to assign a contact

contact_id: str

The ID of the contact to which the assignment belongs

status: str

Options are: “Yes”, “No”, “Maybe”, “Scheduled”, “Invited”, “Cancelled”, “No-Show”, “Completed”, and “”

completed: boolean

Indicates whether contact attended event

confirmed: boolean

Indicates whether invitation confirmed they will attend the event

specific_occurrence_start: str

If invitation is for a specific occurrence of a recurring event, then the start datetime of the event in UTC formatted as yyyy-MM-ddTHH:mm:ss.fffZ

Returns:
dict

Response from PDI in dictionary object

update_contact(id, first_name, last_name, name_prefix='', middle_name='', name_suffix='', nickname='', occupation='', employer='', volunteer_status='', donor_status='', member_status='', date_of_birth=None, gender='U')

Update Contact Args:

namePrefix (string): The name prefix. firstName (string): The first name. middleName (string): The middle name. lastName (string): The last name. nameSuffix (string): The name suffix. nickname (string): The nickname. occupation (string): The occupation. employer (string): The employer. volunteerStatus (string): The volunteer status. Options are: “Prospect”, “Active”, “Inactive”, “None”, “” , donorStatus (string): The donor status. Options are: “Prospect”, “Active”, “Inactive”, “None”, “” , memberStatus (string): The member status. Options are: “Prospect”, “Active”, “Inactive”, “None”, “” , dateOfBirth (string, optional): The date of birth. Format allowed: yyyy-MM-dd , gender (string, optional): The gender. Options are: “F”, “M”, “U”

Returns:
parsons.Table

A Parsons table of all the data.

update_flag_id(id, flag_id, is_default, flag_description=None, compile=None)

Update a flag id.

Args:
id: str

The flag id identifier.

flag_id: str

The flag id type. One of: “AMM”, “BNH”, “BNM”, “DEAD”, “DNC”, “DNR”, “ENDR”, “GTD”, “HH”, “L2VT”, “LBO”, “LM”, “LO”, “LS”, “LSD”, “LSR”, “MAYBE”, “MOV”, “NAH”, “NO”, “REF”, “SO”, “SS”, “SUP”, “U”, “UL2VT”, “VL2VT”, “VOL”, “VTD”.

is_default: bool

The default.

flag_description: str

(Optional) The flag id description.

compile: str

(Optional) The compile.

Returns:
str

The identifier for the udpated flag id.

update_invitation(invitation_id: str, event_id: str, contact_id: str, status=None, attended=None, confirmed=None, specific_occurrence_start=None)

Modify a PDI event invitation Args:

invitation_id: str

The ID of the event invitation

event_id: str

The ID of the event that corresponds to the invitation

contact_id: str

The ID of the contact to which the invitation belongs

status: str

Options are: “Yes”, “No”, “Maybe”, “Scheduled”, “Invited”, “Cancelled”, “No-Show”, “Completed”, and “”

attended: boolean

Indicates whether contact attended event

confirmed: boolean

Indicates whether invitation confirmed they will attend the event

specific_occurrence_start: str

If invitation is for a specific occurrence of a recurring event, then the start datetime of the event in UTC formatted as yyyy-MM-ddTHH:mm:ss.fffZ

Returns:
dict

Response from PDI in dictionary object