This project contains the Python API wrapper for New/Mode API.
newmode-python
uses Semantic Versioning for all changes.
This library has been tested in Python version >= 3.7. Other Python 3.x could be supported.
Install from PyPi using pip, a package manager for Python.
pip install newmode
Don't have pip installed? Try installing it, by running this from the command line:
$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
Or, you can download the source code
(ZIP) for twilio-python
, and then run:
python setup.py install
You may need to run the above commands with sudo
.
Getting started with the New/Mode API couldn't be easier. Create a
Client
and you're ready to go.
The Client
needs your New/Mode credentials. You can either pass these
directly to the constructor (see the code below) or via environment variables.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
Alternately, a Client
constructor without these parameters will
look for NEWMODE_API_USER
and NEWMODE_API_PASSWORD
variables inside the
current environment. API version has a default value of v1.0 so
it's not required to pass this parameter.
We suggest storing your credentials as environment variables. Why? You'll never have to worry about committing your credentials and accidentally posting them somewhere public.
from Newmode import Client
client = Client()
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
response = client.getTools()
print(response)
Return all existing tools.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
response = client.getTools()
print(response)
Return specific tool.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
tool_id = "XX"
response = client.getTool(tool_id)
print(response)
Lookup for targets for a given tool.
The search parameter could be:
For custom target tools, this will return all targets.
For postal code tools, this will return targets matching the postal code.
For csv tools, where search is a valid search term this will return matching targets.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
tool_id = "XX"
search = "XXX"
response = client.lookupTargets(tool_id, search)
print(response)
Return action information for given tool.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
tool_id = "XX"
response = client.getAction(tool_id)
print(response)
Run action for given tool.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
tool_id = "XX"
payload = {
"first_name": "Mark",
"last_name": "Styles",
"email_address": "lambic@pm.me",
"postal_code": "H4E 2Y7",
"email_subject": "This is my subject",
"your_letter": "This is my letter"
}
response = client.runAction(tool_id, payload)
print(response)
Get specific target.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
target_id = "XXXXXX"
response = client.getTarget(target_id)
print(response)
Get existing campaigns.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
response = client.getCampaigns()
print(response)
Get specific campaign.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
campaign_id = "XX"
response = client.getCampaign(campaign_id)
print(response)
Get existing organizations.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
response = client.getOrganizations()
print(response)
Get specific organization.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
organization_id = "XX"
response = client.getOrganization(organization_id)
print(response)
Get existing services.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
response = client.getServices()
print(response)
Get specific service.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
service_id = "XX"
response = client.getService(service_id)
print(response)
Get existing outreaches for given tool.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
tool_id = "XX"
response = client.getOutreaches(tool_id)
print(response)
Get specific outreach.
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
outreach_id = "XX"
response = client.getOutreach(outreach_id)
print(response)
In order to get results paginated, you need to send params like this:
from Newmode import Client
api_user = "XXXXXXXXXXXXXXXXX"
api_password = "YYYYYYYYYYYYYYYYYY"
api_version = "v1.0"
client = Client(api_user, api_password, api_version)
params = {
'page[size]': 5,
'page[number]': 2
}
response = client.getServices(params = params)
print(response)
In order to publish new versions to Pypi.org, you need to run:
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*
If you need help installing or using the library, please contact us.