@@ -8,7 +8,10 @@ need a Nexmo account. Sign up [for free at nexmo.com][signup].
88
99* [ Installation] ( #installation )
1010* [ Usage] ( #usage )
11- * [ Examples] ( #examples )
11+ * [ SMS API] ( #sms-api )
12+ * [ Voice API] ( #voice-api )
13+ * [ Verify API] ( #verify-api )
14+ * [ Application API] ( #application-api )
1215* [ Coverage] ( #api-coverage )
1316* [ License] ( #license )
1417
@@ -28,33 +31,36 @@ Alternatively you can clone the repository:
2831Usage
2932-----
3033
31- Specify your credentials using the ` NEXMO_API_KEY ` and ` NEXMO_API_SECRET `
32- environment variables; import the nexmo package; and construct a client object.
33- For example:
34+ Begin by importing the nexmo module:
3435
3536``` python
3637import nexmo
37-
38- client = nexmo.Client()
3938```
4039
41- Alternatively you can specify your credentials directly using the ` key `
42- and ` secret ` keyword args:
40+ Then construct a client object with your key and secret:
4341
4442``` python
45- import nexmo
43+ client = nexmo.Client(key = api_key, secret = api_secret)
44+ ```
45+
46+ For production you can specify the ` NEXMO_API_KEY ` and ` NEXMO_API_SECRET `
47+ environment variables instead of specifying the key and secret explicitly.
48+
49+ For newer endpoints that support JWT authentication such as the Voice API,
50+ you can also specify the ` application_id ` and ` private_key ` arguments:
4651
47- client = nexmo.Client(key = ' YOUR-API-KEY' , secret = ' YOUR-API-SECRET' )
52+ ``` python
53+ client = nexmo.Client(application_id = application_id, private_key = private_key)
4854```
4955
56+ In order to check signatures for incoming webhook requests, you'll also need
57+ to specify the ` signature_secret ` argument (or the ` NEXMO_SIGNATURE_SECRET `
58+ environment variable).
5059
51- Examples
52- --------
5360
54- ### Sending a message
61+ ## SMS API
5562
56- To use [ Nexmo's SMS API] [ doc_sms ] to send an SMS message, call the send_message
57- method with a dictionary containing the API parameters. For example:
63+ ### Send a text message
5864
5965``` python
6066response = client.send_message({' from' : ' Python' , ' to' : ' YOUR-NUMBER' , ' text' : ' Hello world' })
@@ -69,22 +75,51 @@ else:
6975 print ' Error:' , response[' error-text' ]
7076```
7177
72- ### Fetching a message
78+ Docs: [ https://docs.nexmo.com/messaging/sms-api/api-reference#request ] ( https://docs.nexmo.com/messaging/sms-api/api-reference#request?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
79+
80+
81+ ## Voice API
7382
74- You can retrieve a message log from the API using the ID of the message:
83+ ### Make a call
7584
7685``` python
77- message = client.get_message(' 02000000DA7C52E7' )
86+ response = client.create_call({
87+ ' to' : [{' type' : ' phone' , ' number' : ' 14843331234' }],
88+ ' from' : {' type' : ' phone' , ' number' : ' 14843335555' },
89+ ' answer_url' : [' https://example.com/answer' ]
90+ })
91+ ```
92+
93+ Docs: [ https://docs.nexmo.com/voice/voice-api/api-reference#call_create ] ( https://docs.nexmo.com/voice/voice-api/api-reference#call_create?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
7894
79- print ' The body of the message was:' , message[' body' ]
95+ ### Retrieve a list of calls
96+
97+ ``` python
98+ response = client.get_calls()
8099```
81100
82- ### Starting a verification
101+ Docs: [ https://docs.nexmo.com/voice/voice-api/api-reference#call_retrieve ] ( https://docs.nexmo.com/voice/voice-api/api-reference#call_retrieve?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
102+
103+ ### Retrieve a single call
104+
105+ ``` python
106+ response = client.get_call(uuid)
107+ ```
83108
84- Nexmo's [ Verify API] [ doc_verify ] makes it easy to prove that a user has provided their
85- own phone number during signup, or implement second factor authentication during signin.
109+ Docs: [ https://docs.nexmo.com/voice/voice-api/api-reference#call_retrieve_single ] ( https://docs.nexmo.com/voice/voice-api/api-reference#call_retrieve_single?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
86110
87- You can start the verification process by calling the start_verification method:
111+ ### Update a call
112+
113+ ``` python
114+ response = client.update_call(uuid, action = ' hangup' )
115+ ```
116+
117+ Docs: [ https://docs.nexmo.com/voice/voice-api/api-reference#call_modify_single ] ( https://docs.nexmo.com/voice/voice-api/api-reference#call_modify_single?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
118+
119+
120+ ## Verify API
121+
122+ ### Start a verification
88123
89124``` python
90125response = client.start_verification(number = ' 441632960960' , brand = ' MyApp' )
@@ -95,57 +130,113 @@ else:
95130 print ' Error:' , response[' error_text' ]
96131```
97132
133+ Docs: [ https://docs.nexmo.com/verify/api-reference/api-reference#vrequest ] ( https://docs.nexmo.com/verify/api-reference/api-reference#vrequest?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
134+
98135The response contains a verification request id which you will need to
99136store temporarily (in the session, database, url etc).
100137
101- ### Controlling a verification
138+ ### Check a verification
102139
103- Call the cancel_verification method with the verification request id
104- to cancel an in-progress verification:
140+ ``` python
141+ response = client.check_verification(' 00e6c3377e5348cdaf567e1417c707a5' , code = ' 1234' )
142+
143+ if response[' status' ] == ' 0' :
144+ print ' Verification complete, event_id=' + response[' event_id' ]
145+ else :
146+ print ' Error:' , response[' error_text' ]
147+ ```
148+
149+ Docs: [ https://docs.nexmo.com/verify/api-reference/api-reference#check ] ( https://docs.nexmo.com/verify/api-reference/api-reference#check?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
150+
151+ The verification request id comes from the call to the start_verification method.
152+ The PIN code is entered into your application by the user.
153+
154+ ### Cancel a verification
105155
106156``` python
107157client.cancel_verification(' 00e6c3377e5348cdaf567e1417c707a5' )
108158```
109159
110- Call the trigger_next_verification_event method with the verification
111- request id to trigger the next attempt to send the confirmation code:
160+ Docs: [ https://docs.nexmo.com/verify/api-reference/api-reference#control ] ( https://docs.nexmo.com/verify/api-reference/api-reference#control?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
161+
162+ ### Trigger next verification step
112163
113164``` python
114165client.trigger_next_verification_event(' 00e6c3377e5348cdaf567e1417c707a5' )
115166```
116167
117- The verification request id comes from the call to the start_verification method.
168+ Docs: [ https://docs.nexmo.com/verify/api-reference/api-reference#control ] ( https://docs.nexmo.com/verify/api-reference/api-reference#control?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
118169
119- ### Checking a verification
120170
121- Call the check_verification method with the verification request id and the
122- PIN code to complete the verification process:
171+ ## Application API
172+
173+ ### Create an application
123174
124175``` python
125- response = client.check_verification(' 00e6c3377e5348cdaf567e1417c707a5' , code = ' 1234' )
176+ response = client.create_application(name = ' Example App' , type = ' voice' , answer_url = answer_url)
177+ ```
126178
127- if response[' status' ] == ' 0' :
128- print ' Verification complete, event_id=' + response[' event_id' ]
129- else :
130- print ' Error:' , response[' error_text' ]
179+ Docs: [ https://docs.nexmo.com/tools/application-api/api-reference#create ] ( https://docs.nexmo.com/tools/application-api/api-reference#create?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
180+
181+ ### Retrieve a list of applications
182+
183+ ``` python
184+ response = client.get_applications()
131185```
132186
133- The verification request id comes from the call to the start_verification method.
134- The PIN code is entered into your application by the user.
187+ Docs: [ https://docs.nexmo.com/tools/application-api/api-reference#list ] ( https://docs.nexmo.com/tools/application-api/api-reference#list?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
188+
189+ ### Retrieve a single application
135190
136- ### Start an outbound call
191+ ``` python
192+ response = client.get_application(uuid)
193+ ```
137194
138- Use Nexmo's [ Call API ] [ doc_call ] to initiate an outbound voice call by calling
139- the initiate_call method with the number to call and the URL to a VoiceXML
140- resource for controlling the call:
195+ Docs: [ https://docs.nexmo.com/tools/application-api/api-reference#retrieve ] ( https://docs.nexmo.com/tools/application-api/api-reference#retrieve?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
196+
197+ ### Update an application
141198
142199``` python
143- response = client.initiate_call(to = ' 447525856424' , answer_url = ' http://example.com/call.xml' )
200+ response = client.update_application(uuid, answer_method = ' POST' )
201+ ```
144202
145- if response[' status' ] == ' 0' :
146- print ' Started call' , response[' call-id' ]
203+ Docs: [ https://docs.nexmo.com/tools/application-api/api-reference#update ] ( https://docs.nexmo.com/tools/application-api/api-reference#update?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
204+
205+ ### Delete an application
206+
207+ ``` python
208+ response = client.delete_application(uuid)
209+ ```
210+
211+ Docs: [ https://docs.nexmo.com/tools/application-api/api-reference#delete ] ( https://docs.nexmo.com/tools/application-api/api-reference#delete?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
212+
213+
214+ ## Validate webhook signatures
215+
216+ ``` python
217+ client = nexmo.Client(signature_secret = ' secret' )
218+
219+ if client.check_signature(request.query):
220+ # valid signature
147221else :
148- print ' Error:' , response[' error-text' ]
222+ # invalid signature
223+ ```
224+
225+ Docs: [ https://docs.nexmo.com/messaging/signing-messages ] ( https://docs.nexmo.com/messaging/signing-messages?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library )
226+
227+ Note: you'll need to contact
[email protected] to enable message signing on
228+ your account before you can validate webhook signatures.
229+
230+
231+ ## JWT parameters
232+
233+ By default the library generates short lived tokens for JWT authentication.
234+
235+ Use the auth method to specify parameters for a longer life token or to
236+ specify a different token identifier:
237+
238+ ``` python
239+ client.auth(nbf = nbf, exp = exp, jti = jti)
149240```
150241
151242
@@ -198,7 +289,4 @@ License
198289This library is released under the [ MIT License] [ license ]
199290
200291[ signup ] : https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library
201- [ doc_sms ] : https://docs.nexmo.com/messaging/sms-api?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library
202- [ doc_verify ] : https://docs.nexmo.com/verify/api-reference?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library
203- [ doc_call ] : https://docs.nexmo.com/voice/call?utm_source=DEV_REL&utm_medium=github&utm_campaign=python-client-library
204292[ license ] : LICENSE.txt
0 commit comments