Package: newmode
newmode-pythonIntroductionThis project contains the Python API wrapper for New/Mode API.Versionsnewmode-pythonusesSemantic Versioningfor all changes.Supported Python VersionsThis library has been tested in Python version >= 3.7. Other Python 3.x could be supported.InstallationInstall from PyPi usingpip, a
package manager for Python.pip install newmodeDon'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 | pythonOr, you candownload the source code
(ZIP)fortwilio-python, and then run:python setup.py installYou may need to run the above commands withsudo.Getting StartedGetting started with the New/Mode API couldn't be easier. Create aClientand you're ready to go.API CredentialsTheClientneeds your New/Mode credentials. You can either pass these
directly to the constructor (see the code below) or via environment variables.fromNewmodeimportClientapi_user="XXXXXXXXXXXXXXXXX"api_password="YYYYYYYYYYYYYYYYYY"api_version="v1.0"client=Client(api_user,api_password,api_version)Alternately, aClientconstructor without these parameters will
look forNEWMODE_API_USERandNEWMODE_API_PASSWORDvariables 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.fromNewmodeimportClientclient=Client()Example usagefromNewmodeimportClientapi_user="XXXXXXXXXXXXXXXXX"api_password="YYYYYYYYYYYYYYYYYY"api_version="v1.0"client=Client(api_user,api_password,api_version)response=client.getTools()print(response)API FunctionsgetToolsReturn all existing tools.fromNewmodeimportClientapi_user="XXXXXXXXXXXXXXXXX"api_password="YYYYYYYYYYYYYYYYYY"api_version="v1.0"client=Client(api_user,api_password,api_version)response=client.getTools()print(response)getToolReturn specific tool.fromNewmodeimportClientapi_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)lookupTargetsLookup for targets for a given tool.The search parameter could be:EmptyFor custom target tools, this will return all targets.Postal CodeFor postal code tools, this will return targets matching the postal code.CustomFor csv tools, where search is a valid search term this will return matching targets.fromNewmodeimportClientapi_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)getActionReturn action information for given tool.fromNewmodeimportClientapi_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)runActionRun action for given tool.fromNewmodeimportClientapi_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)getTargetGet specific target.fromNewmodeimportClientapi_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)getCampaignsGet existing campaigns.fromNewmodeimportClientapi_user="XXXXXXXXXXXXXXXXX"api_password="YYYYYYYYYYYYYYYYYY"api_version="v1.0"client=Client(api_user,api_password,api_version)response=client.getCampaigns()print(response)getCampaignGet specific campaign.fromNewmodeimportClientapi_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)getOrganizationsGet existing organizations.fromNewmodeimportClientapi_user="XXXXXXXXXXXXXXXXX"api_password="YYYYYYYYYYYYYYYYYY"api_version="v1.0"client=Client(api_user,api_password,api_version)response=client.getOrganizations()print(response)getOrganizationGet specific organization.fromNewmodeimportClientapi_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)getServicesGet existing services.fromNewmodeimportClientapi_user="XXXXXXXXXXXXXXXXX"api_password="YYYYYYYYYYYYYYYYYY"api_version="v1.0"client=Client(api_user,api_password,api_version)response=client.getServices()print(response)getServiceGet specific service.fromNewmodeimportClientapi_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)getOutreachesGet existing outreaches for given tool.fromNewmodeimportClientapi_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)getOutreachGet specific outreach.fromNewmodeimportClientapi_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)PagingIn order to get results paginated, you need to send params like this:fromNewmodeimportClientapi_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)Publishing new versionsIn order to publish new versions to Pypi.org, you need to run:python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*Getting helpIf you need help installing or using the library, pleasecontact us.