Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justijndepover/teamleader-api
PHP Client for the Teamleader API
https://github.com/justijndepover/teamleader-api
api oauth2 php teamleader
Last synced: 22 days ago
JSON representation
PHP Client for the Teamleader API
- Host: GitHub
- URL: https://github.com/justijndepover/teamleader-api
- Owner: justijndepover
- License: mit
- Created: 2021-03-31T08:51:35.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T08:05:48.000Z (9 months ago)
- Last Synced: 2024-12-14T21:52:26.237Z (about 1 month ago)
- Topics: api, oauth2, php, teamleader
- Language: PHP
- Homepage:
- Size: 86.9 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Teamleader API
[![Latest Version on Packagist](https://img.shields.io/packagist/v/justijndepover/teamleader-api.svg?style=flat-square)](https://packagist.org/packages/justijndepover/teamleader-api)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Total Downloads](https://img.shields.io/packagist/dt/justijndepover/teamleader-api.svg?style=flat-square)](https://packagist.org/packages/justijndepover/teamleader-api)PHP Client for the Teamleader API
![Logo](https://raw.githubusercontent.com/justijndepover/teamleader-api/master/docs/logo.jpg)
## Caution
This application is still in development and could implement breaking changes. Please use at your own risk.
## Installation
You can install the package with composer
```sh
composer require justijndepover/teamleader-api
```## Installing the package in Laravel
To use the plugin in Laravel applications, please refer to the [Laravel usage page](docs/laravel-usage.md)
## Usage
Connecting to Teamleader:
```php
// note the state param: this can be a random string. It's used as an extra layer of protection. Teamleader will return this value when connecting.
$teamleader = new Teamleader(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, STATE);
// open the teamleader login
header("Location: {$teamleader->redirectForAuthorizationUrl()}");
exit;
```After connecting, Teamleader will send a request back to your redirect uri.
```php
$teamleader = new Teamleader(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, STATE);if ($_GET['error']) {
// your application should handle this error
}if ($_GET['state'] != $teamleader->getState()) {
// state value does not match, your application should handle this error
}$teamleader->setAuthorizationCode($_GET['code']);
$teamleader->connect();// store these values:
$accessToken = $teamleader->getAccessToken();
$refreshToken = $teamleader->getRefreshToken();
$expiresAt = $teamleader->getTokenExpiresAt();
```Your application is now connected. To start fetching data:
```php
$teamleader = new Teamleader(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, STATE);
$teamleader->setAccessToken($accessToken);
$teamleader->setRefreshToken($refreshToken);
$teamleader->setTokenExpiresAt($expiresAt);// fetch data:
$teamleader->crm->get();// you should always store your tokens at the end of a call
$accessToken = $teamleader->getAccessToken();
$refreshToken = $teamleader->getRefreshToken();
$expiresAt = $teamleader->getTokenExpiresAt();
```## Available methods
Note that your application should have the correct scopes enabled inside the [integration](https://marketplace.focus.teamleader.eu/be/nl/ontwikkel/integraties)
This application is in an early development stage. Therefore not all resources are available as props yet. (for example: `$teamleader->users->me`)
In the meantime it's possible to fetch every resource available through the `get` and `post` methods:
```php
$teamleader->get('users.me');
$teamleader->get('departments.list');
$teamleader->get('departments.info', ['id' => $id]);
$teamleader->post('contacts.add', [
// all the data
]);
```## Rate limiting
After each request, the rate limiting headers are available.
```php
// returns the maximum rate limit your application can hit in 1 minute
$teamleader->getRateLimitLimit();// returns the current limit remaining
$teamleader->getRateLimitRemaining();// returns the datetime (UTC) when your application can make calls again, after hitting the rate limit.
$teamleader->getRateLimitReset();
```How you handle rate limiting is up to you. But the application provides a helper method to ensure you never hit the limit:
```php
$teamleader->get('contacts.info', ['id' => $id]);
// executing this function will sleep until the X-RateLimitReset header has passed, but only if the rate limit is hit.
$teamleader->ensureRateLimitingIsNotExceeded();
```## Security
If you find any security related issues, please open an issue or contact me directly at [[email protected]]([email protected]).
## Contribution
If you wish to make any changes or improvements to the package, feel free to make a pull request.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.