To update user's device, you will need to make a HTTP PUT request to
https://<your_api_key>:<your_api_token><subdomain>/v2/accounts/<your_sid>/users/<user_id>/devices/<device_id>
<your_api_key>
and <your_api_token>
with the API key and token created by you.<your_sid>
with your “Account sid”<subdomain>
with the region of your account<user_id>
and <device_id>
with the user's unique identifier and device identifier as present in GET user details API.<your_api_key>
, <your_api_token>
and <your_sid>
are available in the API settings page of your Exotel Dashboard
The following are the PUT parameters supported with Content-Type: application/json
set in the header
Parameter Name |
Value |
available |
Boolean (true/false); Indicates if the device is available (ON) to take calls or unavailable (OFF). Example - |
contact_uri |
The phone number of the user in E.164 format to be modified. |
curl -X PUT \ https://<your_api_key>:<your_api_token><subdomain>/v2/accounts/<your_sid>/users/<user_id>/devices/<device_id> \ -H 'content-type: application/json' \ -d '{ "available": true }'
var request = require('request'); var options = { url: 'https://<your_api_key>:<your_api_token><subdomain>/v2/accounts/<your_sid>/users/<user_id>/devices/<device_id>', method: 'PUT', headers: { 'content-type': 'application/json' }, body: { available: true }, json: true }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } } request(options, callback);
<?php $request = new HttpRequest(); $request->setUrl('https://<your_api_key>:<your_api_token><subdomain>/v2/accounts/<your_sid>/users/<user_id>/devices/<device_id>'); $request->setMethod(HTTP_METH_PUT); $request->setHeaders(array( 'content-type' => 'application/json', )); $request->setBody('{ "available": true } '); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; }
import requests url = "https://<your_api_key>:<your_api_token><subdomain>/v2/accounts/<your_sid>/users/<user_id>/devices/<device_id>" payload = "{\"available\": true}" headers = { 'content-type': "application/json", } response = requests.request("PUT", url, data=payload, headers=headers) print(response.text)
require 'uri' require 'net/http' url = URI("https://<your_api_key>:<your_api_token><subdomain>/v2/accounts/<your_sid>/users/<user_id>/devices/<device_id>") http = Net::HTTP.new(url.host, url.port) request = Net::HTTP::Put.new(url) request["content-type"] = 'application/json' request.body = "{\"available\": true}" response = http.request(request) puts response.read_body
HTTP Response:
{ "request_id":"6b99d8f854244f1eb8bb91d75f1c565a", "method":"PUT", "http_code":200, "response": { "code":200, "error_data":null, "status":"success", "data": { "id":100280, "name":"Primary Device", "contact_uri":"+91917622XXXX", "type":"tel", "available":true, "verified":true, "status":"free" } } }
Parameter Name | Type & Value |
request_id | This indicates the unique id of the request. Useful for debugging and tracing purposes. |
method | This indicates the HTTP method for the request such as GET/POST/PUT etc. |
http_code | This indicates the HTTP code for the request such as 200, 400, 500 etc. |
response |
Response block contains the user device record matching the request URI. The block contains
|
Description of parameters under 'data' block:
Parameter Name | Description |
id | Unique ID of the device of the user. To be used as <device-id> while performing a PUT operation on the user. |
name | Friendly name of the device |
contact_uri |
Phone number of the device in E.164 format like +919999XXXXXX or the SIP URI of the device if it is a soft-phone like sip:arjuns2d853099. |
type |
Type of device. Possible values
|
available |
Boolean (true/false); |
verified | Boolean (true/false); Indicates if the device is verified or not on Exotel. If a user needs to verify their device, these steps can be followed. |
status |
Indicates the current device status. Possible values-
|
Possible error scenarios in case of this PUT API -
HttpCode | Code | Description |
409 | 10809 |
This device is unverified
|
403 | 10810 |
Another device is ON. Only one device can be ON at a time
|
403 | 1003 |
API credentials used are unauthorized
|
403 | 10814 |
This account's KYC is incomplete. Operation not permitted
|
403 | 10815 |
This is a trial account. Operation not permitted
|
403 | 10817 |
This device is not PSTN. Operation not permitted
|
400 | 1007 |
device_contact_uri cannot be updated in the same request
|
401 | 1010 |
Authentication failed
|
404 | 10808 |
Device not found
|
404 | 10801 | User not found |
409 | 10811 |
Device already exists
|
429 | NA |
Too many requests
|
500 | 1004 |
Internal Server Error
|
*These will be populated under the `error_data` block of response
Step 1 : Fetch the user id and device id of the corresponding user where the contact_uri (phone number) is +9199512131xx by querying the GET API like below
https://<your_api_key>:<your_api_token><subdomain>/v2/accounts/<account_sid>/users?fields=devices&devices.contact_uri=%2B9199512131xx
Step 2: Use the user id and device id returned in the API response to toggle the value of available by setting it to true for ON and false for OFF like below
https://<your_api_key>:<your_api_token><subdomain>/v2/accounts/<your_sid>/users/<user_id>/devices/<device_id>
curl -X PUT \ https://<your_api_key>:<your_api_token><subdomain>/v2/accounts/<your_sid>/users/<user_id>/devices/<device_id> \ -H 'content-type: application/json' \ -d '{ "available": true }'