An API wrapper for Basecamp 3.
Visit https://launchpad.37signals.com/integrations and register your app.
The Basecamp3 API only supports 3-legged authentication and makes calls on behalf of one user. To receive an access token, you can use Laravel Socialite with the 37signals Socialite Driver. After you save the access token and the desired Basecamp3 account, you can now create an instance of the API wrapper.
This example app should help you get started: Basecamp Example App
composer require coopbelvedere/laravel-basecamp-api
php artisan vendor:publish --provider="Belvedere\Basecamp\BasecampServiceProvider"
Add a user-agent
to identify your app in your config/basecamp.php
file.
Retrieve your basecamp id, base uri (href), token and refresh token and initialize the API wrapper.
Basecamp::init([
'id' => $user->basecamp_id,
'href' => $user->href,
'token' => $user->token,
'refresh_token' => $user->refresh_token,
]);
The client uses a Laravel Filesystem cache strategy by default. You can override this with your preferred Laravel cache store:
Basecamp::setCache(Cache::store('redis'));
You can optionally add an array of middlewares to the Guzzle Handler Stack. Here is an example for logging a request:
Basecamp::setMiddlewares([
\GuzzleHttp\Middleware::log(
Log::getLogger(),
new \GuzzleHttp\MessageFormatter('{method} {uri} HTTP/{version} {req_body}')
)
]);
The Client also comes with a middleware which will refresh an expired access
token and automatically retry the intended endpoint. You can listen to the
basecamp.refreshed_token
event to update the access token in your app.
The event returns 2 parameters, your basecamp user id and the new access token.
You can add something like this in your EventServiceProvider.php
boot method:
Event::listen('basecamp.refreshed_token', function ($id, $token) {
$user = \App\User::where('basecamp_id', $id)->first();
$user->access_token = $token->access_token;
$user->expires_at = \Carbon\Carbon::now()->addSeconds($token->expires_in);
$user->save();
});
Most collection of resources in Basecamp can be paginated.
// Get projects.
$projects = $basecamp->projects()->index();
// Get total of projects
$projects->total();
// Save the next page link for your next request
$nextPage = $projects->nextPage();
// Call the next page of projects.
$projects = $basecamp->projects()->index($nextPage);
- Attachments
- Campfires
- Chatbots
- Client approvals
- Client correspondances
- Client replies
- Comments
- Documents
- Events
- Forwards
- Inboxes
- Message Boards
- Messsages
- Message types
- People
- Projects
- Question answers
- Questionnaires
- Questions
- Recordings
- Schedule entries
- Schedules
- Templates
- To-do list groups
- To-do lists
- To-dos
- To-do sets
- Uploads
- Vaults
- Webhooks
Copyright (c) 2017-present, Coopérative Belvédère Communication