@@ -8,7 +8,10 @@ need a Nexmo account. Sign up [for free at nexmo.com][signup].
8
8
9
9
* [ Installation] ( #installation )
10
10
* [ 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 )
12
15
* [ Coverage] ( #api-coverage )
13
16
* [ License] ( #license )
14
17
@@ -28,33 +31,36 @@ Alternatively you can clone the repository:
28
31
Usage
29
32
-----
30
33
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:
34
35
35
36
``` python
36
37
import nexmo
37
-
38
- client = nexmo.Client()
39
38
```
40
39
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:
43
41
44
42
``` 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:
46
51
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)
48
54
```
49
55
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).
50
59
51
- Examples
52
- --------
53
60
54
- ### Sending a message
61
+ ## SMS API
55
62
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
58
64
59
65
``` python
60
66
response = client.send_message({' from' : ' Python' , ' to' : ' YOUR-NUMBER' , ' text' : ' Hello world' })
@@ -69,22 +75,51 @@ else:
69
75
print ' Error:' , response[' error-text' ]
70
76
```
71
77
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
73
82
74
- You can retrieve a message log from the API using the ID of the message:
83
+ ### Make a call
75
84
76
85
``` 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 )
78
94
79
- print ' The body of the message was:' , message[' body' ]
95
+ ### Retrieve a list of calls
96
+
97
+ ``` python
98
+ response = client.get_calls()
80
99
```
81
100
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
+ ```
83
108
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 )
86
110
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
88
123
89
124
``` python
90
125
response = client.start_verification(number = ' 441632960960' , brand = ' MyApp' )
@@ -95,57 +130,113 @@ else:
95
130
print ' Error:' , response[' error_text' ]
96
131
```
97
132
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
+
98
135
The response contains a verification request id which you will need to
99
136
store temporarily (in the session, database, url etc).
100
137
101
- ### Controlling a verification
138
+ ### Check a verification
102
139
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
105
155
106
156
``` python
107
157
client.cancel_verification(' 00e6c3377e5348cdaf567e1417c707a5' )
108
158
```
109
159
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
112
163
113
164
``` python
114
165
client.trigger_next_verification_event(' 00e6c3377e5348cdaf567e1417c707a5' )
115
166
```
116
167
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 )
118
169
119
- ### Checking a verification
120
170
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
123
174
124
175
``` python
125
- response = client.check_verification(' 00e6c3377e5348cdaf567e1417c707a5' , code = ' 1234' )
176
+ response = client.create_application(name = ' Example App' , type = ' voice' , answer_url = answer_url)
177
+ ```
126
178
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()
131
185
```
132
186
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
135
190
136
- ### Start an outbound call
191
+ ``` python
192
+ response = client.get_application(uuid)
193
+ ```
137
194
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
141
198
142
199
``` 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
+ ```
144
202
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
147
221
else :
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 support@nexmo.com 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)
149
240
```
150
241
151
242
@@ -198,7 +289,4 @@ License
198
289
This library is released under the [ MIT License] [ license ]
199
290
200
291
[ 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
204
292
[ license ] : LICENSE.txt
0 commit comments