endpoint-sample.php


SUBMITTED BY: SabriLK

DATE: Jan. 5, 2016, 3:53 p.m.

FORMAT: PHP

SIZE: 4.5 kB

HITS: 642

  1. <?php
  2. require 'vendor/autoload.php';
  3. use Plivo\RestAPI;
  4. $auth_id = "Your AUTH_ID";
  5. $auth_token = "Your AUTH_TOKEN";
  6. $p = new RestAPI($auth_id, $auth_token);
  7. // Create an Endpoint
  8. $params = array(
  9. 'username' => 'Testing', # The username for the endpoint to be created
  10. 'password' => 'TestingCity', # The password for your endpoint username
  11. 'alias' => 'Sample address' # Alias for this endpoint
  12. );
  13. $response = $p->create_endpoint($params);
  14. // print_r ($response['response']);
  15. /*
  16. Sample Output
  17. (
  18. [alias] => Sample address
  19. [api_id] => f800f950-ac43-11e4-ac1f-22000ac51de6
  20. [endpoint_id] => 32969375408354
  21. [message] => created
  22. [username] => Testing150204080105
  23. )
  24. */
  25. // Get Details of all existing Endpoints
  26. $response = $p->get_endpoints();
  27. // print_r ($response['response']);
  28. /*
  29. Sample Output
  30. (
  31. [api_id] => 13632e02-ac44-11e4-b423-22000ac8a2f8
  32. [meta] => Array (
  33. [limit] => 20
  34. [next] =>
  35. [offset] => 0
  36. [previous] =>
  37. [total_count] => 2
  38. )
  39. [objects] => Array (
  40. [0] => Array (
  41. [alias] => Sample address
  42. [application] => /v1/Account/xxxxxxxxxxxxxxxx/Application/16982793927977910/
  43. [endpoint_id] => 32969375408354
  44. [password] => 7681fb638a6edc7c70a522f58659af10
  45. [resource_uri] => /v1/Account/xxxxxxxxxxxxxxxx/Endpoint/32969375408354/
  46. [sip_registered] => false
  47. [sip_uri] => sip:Testing150204080105@phone.plivo.com
  48. [sub_account] =>
  49. [username] => Testing150204080105
  50. ) [1] => Array (
  51. [alias] => pkyjzb
  52. [application] => /v1/Account/xxxxxxxxxxxxxxxx/Application/16982793927977910/
  53. [endpoint_id] => 23652884295839
  54. [password] => d592b36b4855eeb3b1c53cd53e031438
  55. [resource_uri] => /v1/Account/xxxxxxxxxxxxxxxx/Endpoint/23652884295839/
  56. [sip_registered] => false
  57. [sip_uri] => sip:pkyjzb150204052138@phone.plivo.com
  58. [sub_account] =>
  59. [username] => pkyjzb150204052138
  60. )
  61. )
  62. )
  63. */
  64. // Print the total number of Endpoints
  65. // echo "<br> Total count : ";
  66. // echo ($response['response']['meta']['total_count']);
  67. /*
  68. Sample Output
  69. Total count : 2
  70. */
  71. // Get details of Single Endpoint
  72. $params = array(
  73. 'endpoint_id' => '23652884295839' # ID of the endpoint for which the details have to be retrieved
  74. );
  75. $response = $p->get_endpoint($params);
  76. // print_r ($response['response']);
  77. /*
  78. Sample Output
  79. (
  80. [alias] => pkyjzb
  81. [api_id] => cd8011ec-ac44-11e4-b932-22000ac50fac
  82. [application] => /v1/Account/xxxxxxxxxxxxxxxx/Application/16982793927977910/
  83. [endpoint_id] => 23652884295839
  84. [password] => d592b36b4855eeb3b1c53cd53e031438
  85. [resource_uri] => /v1/Account/xxxxxxxxxxxxxxxx/Endpoint/23652884295839/
  86. [sip_registered] => false
  87. [sip_uri] => sip:pkyjzb150204052138@phone.plivo.com
  88. [sub_account] =>
  89. [username] => pkyjzb150204052138
  90. )
  91. */
  92. // Modify an Endpoint
  93. $params = array(
  94. 'endpoint_id' => '23652884295839', # ID of the endpoint for which has to be modified
  95. 'alias' => 'SampleAlias' # Values that have to be updated
  96. );
  97. $response = $p->modify_endpoint($params);
  98. // print_r ($response['response']);
  99. /*
  100. Sample Output
  101. (
  102. [api_id] => 067341d6-ac45-11e4-b932-22000ac50fac
  103. [message] => changed
  104. )
  105. */
  106. // Delete an Endpoint
  107. $params = array(
  108. 'endpoint_id' => '23652884295839' # Auth ID of the sub acccount for which the details has to be deleted
  109. );
  110. $response = $p->delete_endpoint($params);
  111. // print_r ($response);
  112. /*
  113. Sample Output
  114. (
  115. [status] => 204
  116. [response] =>
  117. )
  118. Unsuccessful Output
  119. (
  120. [status] => 404
  121. [response] => Array (
  122. [api_id] => c0cf0530-ac39-11e4-96e3-22000abcb9af
  123. [error] => not found
  124. x`)
  125. )
  126. */

comments powered by Disqus