lobrs / calendly-sdk-php
Calendly API SDK PHP
Installs: 19 268
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 2
Forks: 1
Open Issues: 1
pkg:composer/lobrs/calendly-sdk-php
Requires
- php: >=7.4
- ext-json: *
- guzzlehttp/guzzle: ^7.4
- league/oauth2-client: ^2.6
Requires (Dev)
- mockery/mockery: ~1.5.1
- phpunit/phpunit: ^9.5
README
PHP implementation of Calendly API (v2).
Installation
composer require lobrs/calendly-sdk-php
Usage
\LoBrs\Calendly\Calendly::setToken($token); $currentUser = \LoBrs\Calendly\Calendly::me();
Get user from UUID
$user = \LoBrs\Calendly\Models\User::get($uuid);
Get model list
Returns an array of objects from the model class.
// List scheduled events from a user $scheduled_events = \Calendly\Models\Event::getList([ "user" => $user->uri ]); // List busy times from a user $busy_times = \Calendly\Models\UserBusyTime::getList([ "user" => $user->uri, "start_time" => date(DateTime::ATOM, strtotime("+1 minute")), "end_time" => date(DateTime::ATOM, strtotime("+7 days")), ]);
You can also use paginate($options) method, returning a PaginatedList.
$result = \Calendly\Models\Event::paginate([ "user" => $user->uri ]); echo $result->countResults() . " results \n"; echo $result->getNextPageURL(); // Request next page with the same options. $next_page_results = $result->next();
Refer to the Calendly API documentation to find requests options.
Currently supported models
| Models | Get uuid | Paginate | Create | Delete |
|---|---|---|---|---|
| Event | ✓ | ✓ | ||
| EventType | ✓ | ✓ | ||
| EventTypeAvailableTime | ✓ | |||
| Guest | ✓ | |||
| Invitee | ✓ | |||
| Organization | ✓ | |||
| OrganizationInvitation | ✓ | |||
| OrganizationMembership | ✓ | ✓ | ||
| Profile | ✓ | |||
| RoutingForm | ✓ | ✓ | ||
| RoutingFormSubmission | ✓ | ✓ | ||
| SchedulingLink | ✓ | ✓ | ||
| User | ✓ | |||
| UserAvailabilitySchedule | ✓ | |||
| UserBusyTime | ✓ | |||
| WebhookSubscription | ✓ | ✓ | ✓ | ✓ |
Direct API request usage
You can directly call the API using Calendly::request($uri, "GET", $params), which returns the body of the response.
Webhooks
You can use WebhookSubscription Model directly to manage your Webhooks methods getList, get, create and delete.
Webhook subscription
We provide the subscribe helper method to add a new webhook.
The 3rd parameter can be a $uuid referencing a user or organization uuid or an array of options.
\LoBrs\Calendly\Webhooks\Webhook::subscribe("https://example.com/my-webhook", [ 'invitee.created' ], [ 'user' => 'user_abc123', 'organization' => 'organization_abc123', 'scope' => 'organization', ], 'my-webhook-secret-key');
To improve security, you can sign your webhooks by providing the webhook secret key parameter.
Webhook payload example
$payload = @file_get_contents('php://input'); $header = $_SERVER['HTTP_CALENDLY_WEBHOOK_SIGNATURE']; try { $webhook = Webhook::readEvent($payload, $header, 'my-webhook-secret-key'); } catch (WebhookExpiredResponseException|WebhookSignatureException $e) {}
OAuth
This package comes with an OAuth2 CLient, using ThePhpLeague OAuth2 Client
Usage flow
$provider = new CalendlyOAuthProvider([ "clientId" => env('CALENDLY_CLIENT'), "clientSecret" => env('CALENDLY_OAUTH_SECRET'), 'redirectUri' => env('CALENDLY_REDIRECT_URI'), ]); if (!isset($_GET['code'])) { // If we don't have an authorization code then get one $authUrl = $provider->getAuthorizationUrl(); header('Location: ' . $authUrl); exit; } else { // Try to get an access token (using the authorization code grant) $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'], ]); try { // We got an access token, let's now get the user's details $user = $provider->getResourceOwner($token); print_r($user->toArray()); } catch (Exception $e) { exit('Failed to get user details'); } // Use this to interact with an API on the users behalf echo $token->getToken(); }