New/Mode¶
Overview¶
New/Mode is a multi-channel advocacy and civic engagement platform
for organizations and campaigns. This Parsons class includes methods for fetching tools, actions, targets, campaigns,
organizations, services, and outreaches. There are also methods for looking up targets and running actions given a
tool_id. Most methods return either individual items as dictionaries or lists of items as Parsons Table objects.
Authentication
To use the class, you need to provide a New/Mode username and password. For more information, see The New/Mode API is Here.
Quickstart¶
To instantiate the Newmode class, you can either store your New/Mode username
and password as environmental variables (NEWMODE_API_USER and NEWMODE_API_PASSWORD,
respectively) or pass in your username and password as arguments.
from parsons import Newmode
newmode = Newmode()
from parsons import Newmode
newmode = Newmode(api_user='my_username', api_password='my_password')
tools = newmode.get_tools()
tool = newmode.get_tool(tool_id)
API¶
- class parsons.newmode.newmode.Newmode(client_id: str | None = None, client_secret: str | None = None, api_user: str | None = None, api_password: str | None = None, api_version: str = 'v1.0')[source]¶
- class parsons.newmode.newmode.NewmodeV2(client_id: str | None = None, client_secret: str | None = None, api_version: str = 'v2.1')[source]¶
-
- base_request(method: Literal['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], url: str, retries: int = 2, use_campaigns_client: bool = False, data: dict[str, Any] | None = None, json: dict[str, Any] | None = None, params: dict[str, Any] | None = None) dict[str, Any] | None[source]¶
Internal method to instantiate OAuth2APIConnector class, make a single call to Newmode API, and validate the response.
- paginate_request(method: str, endpoint: str, use_campaigns_client: bool = False, data_key: str = 'data', data: dict[str, Any] | None = None, json: dict[str, Any] | None = None, params: dict[str, Any] | None = None, supports_version: bool = True, override_api_version: str | None = None, retries: int = 2) list[dict[str, Any]][source]¶
Wrapper method to handle pagination for API requests.
- converted_request(endpoint: str, method: str, retries: int = 2, supports_version: bool = True, data: dict[str, Any] | None = None, json: dict[str, Any] | None = None, params: dict[str, Any] | None = None, convert_to_table: bool = True, data_key: str | None = None, use_campaigns_client: bool = False, override_api_version: str | None = None) Table | dict[str, Any][source]¶
Internal method to make a call to the Newmode API and convert the result to a Parsons table.
- Parameters:
- Return type:
- get_campaign(campaign_id: str, retries: int = 2, params: dict[str, Any] | None = None) Table[source]¶
Retrieve a specific campaign by ID.
In v2, a campaign is equivalent to Tools or Actions in V1.
- get_campaign_ids(retries: int = 2, params: dict[str, Any] | None = None) list[str][source]¶
Retrieve all campaigns In v2, a campaign is equivalent to Tools or Actions in V1.
- get_recipient(campaign_id: str, street_address: str | None = None, city: str | None = None, postal_code: str | None = None, region: str | None = None, params: dict[str, Any] | None = None, retries: int | None = None) Table[source]¶
Retrieve a specific recipient by ID
- Parameters:
campaign_id (str) – str The ID of the campaign to retrieve.
street_address (str | None) – str Street address of recipient
city (str | None) – str City of recipient
postal_code (str | None) – str Postal code of recipient
region (str | None) – str Region (i.e. state/province abbreviation) of recipient
params (dict[str, Any] | None) – dict Query parameters to include in the request.
retries (int | None)
- Returns:
Parsons Table containing recipient data.
- Return type:
- run_submit(campaign_id: str, retries: int = 2, json: dict[str, Any] | None = None, data: dict[str, Any] | None = None, params: dict[str, Any] | None = None) dict[str, Any][source]¶
Pass a submission from a supporter to a campaign that ultimately fills in a petition, sends an email or triggers a phone call depending on your campaign type
- Parameters:
- Returns:
Parsons Table containing submit data.
- Return type:
- class parsons.newmode.newmode.NewmodeV1(api_user: str | None = None, api_password: str | None = None, api_version: str | None = None)[source]¶
-
- get_tool(tool_id: int | str, params: dict[str, Any] | None = None) dict[str, Any] | None[source]¶
Get specific tool.
- lookup_targets(tool_id: int | str, search: str | None = None, params: dict[str, Any] | None = None) Table[source]¶
Lookup targets for a given tool
- Parameters:
search (str | None) – The search criteria. It could be: - Empty: If empty, return custom targets associated to the tool. - Postal code: Return targets matched by postal code. - Lat/Long: Latitude and Longitude pair separated by ‘::’. Ex. 45.451596::-73.59912099999997. It will return targets matched for those coordinates. - Search term: For your csv tools, this will return targets matched by given valid search term.
- Returns:
Targets information as table.
- Return type:
- get_action(tool_id: int | str, params: dict[str, Any] | None = None) dict[str, Any] | None[source]¶
Get the action information for a given tool.
- run_action(tool_id: int | str, payload: dict[str, Any], params: dict[str, Any] | None = None) str | int | None[source]¶
Run specific action with given payload.
- Parameters:
- Returns:
Action link (if otl) or sid.
- Return type:
- get_target(target_id: int | str, params: dict[str, Any] | None = None) dict[str, Any] | None[source]¶
Get specific target.
- get_campaign(campaign_id: int | str, params: dict[str, Any] | None = None) dict[str, Any] | None[source]¶
Get specific campaign.
- get_organization(organization_id: int | str, params: dict[str, Any] | None = None) dict[str, Any] | None[source]¶
Get specific organization.
- get_service(service_id: int | str, params: dict[str, Any] | None = None) dict[str, Any] | None[source]¶
Get specific service.
- get_outreaches(tool_id: int | str, params: dict[str, Any] | None = None) Table[source]¶
Get existing outreaches for a given tool.