{"id":21406689,"url":"https://github.com/ringcentral/ringcentral-php","last_synced_at":"2025-04-05T08:06:20.070Z","repository":{"id":27532124,"uuid":"31013348","full_name":"ringcentral/ringcentral-php","owner":"ringcentral","description":"RingCentral Connect Platform PHP SDK ","archived":false,"fork":false,"pushed_at":"2024-05-01T11:50:16.000Z","size":4630,"stargazers_count":53,"open_issues_count":17,"forks_count":50,"subscribers_count":24,"default_branch":"master","last_synced_at":"2024-05-02T07:27:45.458Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://developers.ringcentral.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ringcentral.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-19T11:58:40.000Z","updated_at":"2024-06-18T13:48:01.579Z","dependencies_parsed_at":"2024-04-24T11:39:02.315Z","dependency_job_id":"b0456de6-46db-41bc-affb-a61975ad02e2","html_url":"https://github.com/ringcentral/ringcentral-php","commit_stats":{"total_commits":176,"total_committers":21,"mean_commits":8.380952380952381,"dds":"0.38636363636363635","last_synced_commit":"b1a10f47b3bb780f9310f65610dad17980e5c371"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringcentral%2Fringcentral-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringcentral%2Fringcentral-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringcentral%2Fringcentral-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ringcentral%2Fringcentral-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ringcentral","download_url":"https://codeload.github.com/ringcentral/ringcentral-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305933,"owners_count":20917208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T16:41:55.914Z","updated_at":"2025-04-05T08:06:20.049Z","avatar_url":"https://github.com/ringcentral.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RingCentral SDK for PHP\n\n[![Build Status](https://github.com/ringcentral/ringcentral-php/workflows/CI%20Pipeline/badge.svg?branch=master)](https://github.com/ringcentral/ringcentral-php/actions)\n[![Coverage Status](https://coveralls.io/repos/ringcentral/ringcentral-php/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/ringcentral/ringcentral-php?branch=master)\n[![Code Document](https://img.shields.io/badge/phpdoc-reference-blue?branch=master\u0026service=github)](https://ringcentral.github.io/ringcentral-php/)\n[![Chat](https://img.shields.io/badge/chat-on%20glip-orange.svg)](https://glipped.herokuapp.com/)\n[![Twitter](https://img.shields.io/twitter/follow/ringcentraldevs.svg?style=social\u0026label=follow)](https://twitter.com/RingCentralDevs)\n\n__[RingCentral Developers](https://developer.ringcentral.com/api-products)__ is a cloud communications platform which can be accessed via more than 70 APIs. The platform's main capabilities include technologies that enable:\n__[Voice](https://developer.ringcentral.com/api-products/voice), [SMS/MMS](https://developer.ringcentral.com/api-products/sms), [Fax](https://developer.ringcentral.com/api-products/fax), [Glip Team Messaging](https://developer.ringcentral.com/api-products/team-messaging), [Data and Configurations](https://developer.ringcentral.com/api-products/configuration)__.\n\n## Additional resources\n\n* [RingCentral API Reference](https://developer.ringcentral.com/api-docs/latest/index.html) - an interactive reference for the RingCentral API that allows developers to make API calls with no code.\n* [Document](https://ringcentral.github.io/ringcentral-php/) - an interactive reference for the SDK code documentation.\n\n# Requirements\n\n- PHP 7.2+\n- CURL extension\n- MCrypt extension\n\n# Installation\n\nPlease choose one of the following installation options:\n\n## With [Composer](http://getcomposer.org) **(recommended)**\n\nThe installation of composer is local by default. We suggest that you install it at the top level of your application's\ndirectory structure.\n\n1. Install composer:\n\n    ```sh\n    $ curl -sS https://getcomposer.org/installer | php\n    ```\n\n    More info about installation on [Linux / Unix / OSX](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx)\n    and [Windows](https://getcomposer.org/doc/00-intro.md#installation-windows).\n\n3. Run the Composer command to install the latest version of SDK:\n\n    ```sh\n    $ php composer.phar require ringcentral/ringcentral-php\n    ```\n\n4. Require Composer's autoloader in your PHP script (assuming it is in the same directory where you installed Composer):\n\n    ```php\n    require('vendor/autoload.php');\n    ```\n\n## PHAR with bundled dependencies\n\n**This is not recommended! Use [Composer](http://getcomposer.org) as modern way of working with PHP packages.**\n\n1. Download [PHAR file](https://github.com/ringcentral/ringcentral-php/releases/latest)\n\n2. Require files:\n\n    ```php\n    require('path-to-sdk/ringcentral.phar');\n    ```\n\nPlease keep in mind that bundled dependencies may interfere with your other dependencies.\n\n# Basic Usage\n\n## Initialization\n\n```php\n$rcsdk = new RingCentral\\SDK\\SDK('clientId', 'clientSecret', RingCentral\\SDK\\SDK::SERVER_PRODUCTION);\n```\n\nYou also may supply custom AppName and AppVersion parameters with your application codename and version. These parameters\nare optional but they will help a lot to identify your application in API logs and speed up any potential troubleshooting.\nAllowed characters for AppName and AppVersion are: letters, digits, hyphen, dot and underscore.\n\n```php\n$rcsdk = new RingCentral\\SDK\\SDK('clientId', 'clientSecret', RingCentral\\SDK\\SDK::SERVER_PRODUCTION, 'MyApp', '1.0.0');\n```\n\nFor production use `RingCentral\\SDK\\SDK::SERVER_PRODUCTION` constant. Or type in the server URL by hand.\n\n## Authentication\n\nCheck authentication status:\n\n```php\n$rcsdk-\u003eplatform()-\u003eloggedIn();\n```\n\nAuthenticate user with jwt:\n\n```php\n$rcsdk-\u003eplatform()-\u003elogin([\n    'jwt' =\u003e 'your_jwt_token'\n]);\n```\n\nAuthenticate user with authorization code:\n\n```php\n$rcsdk-\u003eplatform()-\u003elogin([\n    'code' =\u003e 'authorization code from RingCentral login redirect uri'\n]);\n```\n\n### Authentication lifecycle\n\nPlatform class performs token refresh procedure if needed. You can save authentication between requests in CGI mode:\n\n```php\n// when application is going to be stopped\nfile_put_contents($file, json_encode($rcsdk-\u003eplatform()-\u003eauth()-\u003edata(), JSON_PRETTY_PRINT));\n\n// and then next time during application bootstrap before any authentication checks:\n$rcsdk-\u003eplatform()-\u003eauth()-\u003esetData(json_decode(file_get_contents($file), true));\n```\n\n**Important!** You have to manually maintain synchronization of SDK's between requests if you share authentication.\nWhen two simultaneous requests will perform refresh, only one will succeed. One of the solutions would be to have\nsemaphor and pause other pending requests while one of them is performing refresh.\n\n## Performing API call\n\n```php\n$apiResponse = $rcsdk-\u003eplatform()-\u003eget('/account/~/extension/~');\n$apiResponse = $rcsdk-\u003eplatform()-\u003epost('/account/~/extension/~', array(...));\n$apiResponse = $rcsdk-\u003eplatform()-\u003eput('/account/~/extension/~', array(...));\n$apiResponse = $rcsdk-\u003eplatform()-\u003edelete('/account/~/extension/~');\n\nprint_r($apiResponse-\u003ejson()); // stdClass will be returned or exception if Content-Type is not JSON\nprint_r($apiResponse-\u003erequest()); // PSR-7's RequestInterface compatible instance used to perform HTTP request\nprint_r($apiResponse-\u003eresponse()); // PSR-7's ResponseInterface compatible instance used as HTTP response\n```\n\n### Multipart response\n\nLoading of multiple comma-separated IDs will result in HTTP 207 with `Content-Type: multipart/mixed`. This response will\nbe parsed into multiple sub-responses:\n\n```php\n$presences = $rcsdk-\u003eplatform()\n                 -\u003eget('/account/~/extension/id1,id2/presence')\n                 -\u003emultipart();\n\nprint 'Presence loaded ' .\n      $presences[0]-\u003ejson()-\u003epresenceStatus . ', ' .\n      $presences[1]-\u003ejson()-\u003epresenceStatus . PHP_EOL;\n```\n\n### Send SMS - Make POST request\n\n```php\n$apiResponse = $rcsdk-\u003eplatform()-\u003epost('/account/~/extension/~/sms', array(\n    'from' =\u003e array('phoneNumber' =\u003e 'your-ringcentral-sms-number'),\n    'to'   =\u003e array(\n        array('phoneNumber' =\u003e 'mobile-number'),\n    ),\n    'text' =\u003e 'Test from PHP',\n));\n```\n\n### Get Platform error message\n\n```php\ntry {\n\n    $rcsdk-\u003eplatform()-\u003eget('/account/~/whatever');\n\n} catch (\\RingCentral\\SDK\\Http\\ApiException $e) {\n\n    // Getting error messages using PHP native interface\n    print 'Expected HTTP Error: ' . $e-\u003egetMessage() . PHP_EOL;\n\n    // In order to get Request and Response used to perform transaction:\n    $apiResponse = $e-\u003eapiResponse();\n    print_r($apiResponse-\u003erequest());\n    print_r($apiResponse-\u003eresponse());\n\n    // Another way to get message, but keep in mind, that there could be no response if request has failed completely\n    print '  Message: ' . $e-\u003eapiResponse-\u003eresponse()-\u003eerror() . PHP_EOL;\n\n}\n```\n\n### How to debug HTTP\n\nYou can set up any HTTPS sniffer (e.g. proxy server, like Charles) and route SDK traffic to it by providing a custom\nGuzzle Client instance:\n\n```php\nuse GuzzleHttp\\Client as GuzzleClient;\n\n$guzzle = new GuzzleClient([\n    'proxy' =\u003e 'localhost:8888',\n    'verify' =\u003e false\n]);\n\n$rcsdk = new SDK(\"clientId\", \"clientSecret\", SDK::SERVER_PRODUCTION, 'Demo', '1.0.0', $guzzle);\n```\n\n# Subscriptions\n\n## Webhook Subscriptions\n\n```php\n$apiResponse = $rcsdk-\u003eplatform()-\u003epost('/subscription', array(\n    'eventFilters' =\u003e array(\n        '/restapi/v1.0/account/~/extension/~/message-store',\n        '/restapi/v1.0/account/~/extension/~/presence'\n    ),\n    'deliveryMode' =\u003e array(\n        'transportType' =\u003e 'WebHook',\n        'address' =\u003e 'https://consumer-host.example.com/consumer/path'\n    )\n));\n```\n\nWhen webhook subscription is created, it will send a request with `validation-token` in headers to webhook address. Webhook address should return a success request with `validation-token` in headers to finish webhook register.\n\n## WebSocket Subscriptions\n\n```php\nuse RingCentral\\SDK\\WebSocket\\WebSocket;\nuse RingCentral\\SDK\\WebSocket\\Subscription;\nuse RingCentral\\SDK\\WebSocket\\Events\\NotificationEvent;\n\n// connect websocket\n$websocket = $rcsdk-\u003einitWebSocket();\n$websocket-\u003eaddListener(WebSocket::EVENT_READY, function (SuccessEvent $e) {\n    print 'Websocket Ready' . PHP_EOL;\n    print 'Connection Details' . print_r($e-\u003eapiResponse()-\u003ebody(), true) . PHP_EOL;\n});\n$websocket-\u003eaddListener(WebSocket::EVENT_ERROR, function (ErrorEvent $e) {\n    print 'Websocket Error' . PHP_EOL;\n});\n$websocket-\u003econnect();\n\n// create subscription\n$subscription = $rcsdk-\u003ecreateSubscription();\n$subscription-\u003eaddEvents(array(\n    '/restapi/v1.0/account/~/extension/~/presence',\n    '/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS'\n));\n$subscription-\u003eaddListener(Subscription::EVENT_NOTIFICATION, function (NotificationEvent $e) {\n    print 'Notification ' . print_r($e-\u003epayload(), true) . PHP_EOL;\n});\n$subscription-\u003eregister();\n```\n\nWe need to create websocket connection before creating subscription. When websocket connection get error, need to re-created websocket and subscription manually.\n\n## PubNub Subscriptions\n\nThis is **deprecated**, please use WebSocket Subscription.\n\n```php\nuse RingCentral\\SDK\\Subscription\\Events\\NotificationEvent;\nuse RingCentral\\SDK\\Subscription\\PubnubSubscription;\n\n$subscription = $rcsdk-\u003ecreateSubscription('Pubnub);\n$subscription-\u003eaddEvents(array('/restapi/v1.0/account/~/extension/~/presence'))\n$subscription-\u003eaddListener(PubnubSubscription::EVENT_NOTIFICATION, function (NotificationEvent $e) {\n    print_r($e-\u003epayload());\n});\n$subscription-\u003esetKeepPolling(true);\n$apiResponse = $subscription-\u003eregister();\n```\n\nPlease keep in mind that due to limitations of the PubNub library, which is synchronous, subscriptions may expire and must\nbe re-created manually.\n\n# Multipart Requests\n\nSDK provides a helper to make sending of faxes easier.\n\n```php\n$request = $rcsdk-\u003ecreateMultipartBuilder()\n                 -\u003esetBody(array(\n                     'to'         =\u003e array(\n                         array('phoneNumber' =\u003e '16501112233'),\n                     ),\n                     'faxResolution' =\u003e 'High',\n                 ))\n                 -\u003eadd('Plain Text', 'file.txt')\n                 -\u003eadd(fopen('path/to/file', 'r'))\n                 -\u003erequest('/account/~/extension/~/fax'); // also has optional $method argument\n\n$response = $rcsdk-\u003eplatform()-\u003esendRequest($request);\n```\n\n# How to demo?\n\nClone the repo and create a file `demo/_credentials.php` copy the contents from the file 'demo/_credentialsSample.php' as shown below:\n\n```php\nreturn array(\n    'username'     =\u003e '18881112233', // your RingCentral account phone number\n    'extension'    =\u003e null, // or number\n    'password'     =\u003e 'yourPassword',\n    'clientId'     =\u003e 'yourClientId',\n    'clientSecret' =\u003e 'yourClientSecret',\n    'server'       =\u003e 'https://platform.ringcentral.com', // for production - https://platform.ringcentral.com\n    'smsNumber'    =\u003e '18882223344', // any of SMS-enabled numbers on your RingCentral account\n    'mobileNumber' =\u003e '16501112233', // your own mobile number to which script will send sms\n    'dateFrom'     =\u003e 'yyyy-mm-dd',\n    'dateTo'       =\u003e 'yyyy-mm-dd'\n);\n```\n\nThen execute:\n\n```sh\n$ php index.php\n```\n\nShould output:\n\n```\nAuth exception: Refresh token has expired\nAuthorized\nRefreshing\nRefreshed\nUsers loaded 10\nPresence loaded Something New - Available, Something New - Available\nExpected HTTP Error: Not Found (from backend)\nSMS Phone Number: 12223334455\nSent SMS https://platform.ringcentral.com/restapi/v1.0/account/111/extension/222/message-store/333\nSubscribing\n```\n\nAfter that script will wait for any presence notification. Make a call to your account or make outbound call from your\naccount. When you will make a call, script will print notification and exit.\n\nPlease take a look in `demo` folder to see all the demos.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fringcentral%2Fringcentral-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fringcentral%2Fringcentral-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fringcentral%2Fringcentral-php/lists"}