Package: tnzapi
tnzapiDocumentationThe documentation for the TNZ API can be foundhere.Versionstnzapiuses a modified version ofSemantic Versioningfor all changes.See this documentfor details.Supported Python VersionsThis library supports the following Python implementations:Python 3.9Python 3.10Python 3.11InstallationInstall from PyPi usingpip, a
package manager for Python.pip install tnzapiDon'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

python setup.py installYou may need to run the above commands withsudo.Getting StartedGetting started with the TNZ API couldn't be easier. Create aClientand you're ready to go.API CredentialsTheTNZAPIneeds your TNZ API credentials (TNZ Auth Tokens). You can either pass these
directly to the constructor (see the code below) or via environment variables.fromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")Send MessageSend SMS/Email/Voice/Fax throughtnzapilibrary.Send SMSfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Messaging.SMS.SendMessage(Reference="Test",MessageText="Test SMS Message click [[Reply]] to opt out",Recipients=["+64211231234"],)print(response)Send an EmailfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Messaging.Email.SendMessage(EmailSubject="Test Email",Recipients=["recipient@example.com"],MessagePlain="Hi world!")print(response)Send a Fax DocumentfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Messaging.Fax.SendMessage(Recipients="+6491232345",Attachments=["C:\\Document.pdf"])print(response)Make a Call - Text-to-Speech (TTS)fromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Messaging.TTS.SendMessage(Recipients=["+64211232345"],Reference="Voice Test - 64211232345",MessageToPeople="Hi there!",Keypads=[Keypad(Tone=1,Play="You pressed 1",RouteNumber="+6491232345")])print(response)Make a Call - Upload MP3 / Wav FilefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Messaging.Voice.SendMessage(Recipients=["+64211232345"],Reference="Voice Test - 64211232345",MessageToPeople="C:\\file1.wav",MessageToAnswerPhones="C:\\file2.wav",Keypads=[Keypad(Tone=1,RouteNumber="+6491232345",PlayFile="C:\\file3.wav")])print(response)ReportsRetrieve your message status usingtnzapilibrary.Reports - Get Message StatusfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Reports.Status.Poll(MessageID="ID123456")print(response)Reports - Get SMS ReplyfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")request=client.Reports.SMSReply.Poll(MessageID="ID123456")print(response)Reports - Get SMS Received ListfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Reports.SMSReceived.Poll(#TimePeriod = 1440DateFrom="2023-07-01 00:00:00",DateTo="2023-08-01 00:00:00")print(response)ActionsAmend your message usingtnzapilibrary.Actions - Abort Pending/Delayed JobfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Actions.Abort.SendRequest(MessageID="ID123456")print(response)Actions - Resubmit Failed JobfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Actions.Resubmit.SendRequest(MessageID="ID123456",SendTime="2023-07-10T09:00"#optional)print(response)Actions - Reschedule DELAYED JobfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Actions.Reschedule.SendRequest(MessageID="ID123456",SendTime=datetime.now())print(response)Actions - Set Number of Operators on TTS/Voice JobfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")request=client.Set.Pacing(MessageID="ID123456",NumberOfOperators=10)print(response)Addressbook - ContactsManage your contacts usingtnzapilibrary.Contacts - ListfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.Contact.List(RecordsPerPage=10,Page=1)print(response)Contacts - DetailfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.Contact.Detail(ContactID="[Contact ID]")print(response)Contacts - CreatefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.Contact.Create(Title="Mr",Company="TNZ Group",FirstName="First",LastName="Last",MobilePhone="+642122223333",ViewPublic="Account",EditPublid="Account")print(response)Contacts - UpdatefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.Contact.Update(ContactID="[Contact ID]",Attention="Test Attention")print(response)Contacts - DeletefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.Contact.Delete(ContactID="[Contact ID]")print(response)Addressbook - Contact GroupManage your contact group relationship usingtnzapilibrary.Contact Group - ListfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.ContactGroup.List(RecordsPerPage=10,Page=1,ContactID="[Contact ID]")print(response)Contact Group - DetailfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.ContactGroup.Detail(ContactID="[Contact ID]",GroupCode="[Group Code]")print(response)Contact Group - CreatefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.ContactGroup.Create(ContactID="[Contact ID]",GroupCode="[Group Code]")print(response)Contact Group - DeletefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.ContactGroup.Delete(ContactID="[Contact ID]",GroupCode="[Group Code]")print(response)Addressbook - GroupManage your group usingtnzapilibrary.Group - ListfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.Group.List(RecordsPerPage=10,Page=1)print(response)Group - DetailfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.Group.Detail(GroupCode="[Group Code]")print(response)Group - CreatefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.Group.Create(GroupCode="[Group Code]",GroupName="[Group Name]")print(response)Group - UpdatefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.Group.Update(GroupCode="[Group Code]",GroupName="[Group Name]")print(response)Group - DeletefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.Group.Delete(GroupCode="[Group Code]")print(response)Addressbook - Group ContactManage your group contact relationship usingtnzapilibrary.Group Contact - ListfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.GroupContact.List(RecordsPerPage=10,Page=1,GroupCode="[Group Code]")print(response)Group Contact - DetailfromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.GroupContact.Detail(GroupCode="[Group Code]",ContactID="[Contact ID]")print(response)Group Contact - CreatefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.GroupContact.Create(GroupCode="[Group Code]",ContactID="[Contact ID]")print(response)Group Contact - DeletefromtnzapiimportTNZAPIclient=TNZAPI(AuthToken="[Your Auth Token]")response=client.Addressbook.GroupContact.Delete(GroupCode="[Group Code]",ContactID="[Contact ID]")print(response)Getting helpIf you need help installing or using the library, please check theTNZ Contactif you don't find an answer to your question.