sumocoders/teamleader-oauth2

PHP Teamleader oauth2 package to connect with Teamleader API (https://developer.teamleader.eu/)

v1.1.0 2023-02-20 13:02 UTC

This package is auto-updated.

Last update: 2024-11-03 11:08:55 UTC


README

Installation

composer require sumocoders/teamleader-oauth2

Setup

This package uses PSR-17 and PSR-18. You can use any implementation you want.

For saving the access we provide a TokenStorageInterface, where you'll need to implement storing and fetching of the tokens:

interface TokenStorageInterface
{
    public function getTokenType(): string;
    public function getAccessToken(): ?string;
    public function getRefreshToken(): ?string;
    public function isExpired(): bool;
    public function storeTokens(array $tokens): void;
}

Look at the default token storage class how you can make your own implementation.

The Teamleader class will need a clientId and clientSecret. Which you'll need to obtain at the Teamleader marketplace.

Usage

To obtain an access token you'll need to call:

$teamleader->acquireAccessToken($redirectUrl, $code);

Where $redirectUrl is the url you want Teamleader to come back to after Oauth2 authentication and $code is for the return when Teamleader comes back to your site and validate the authentication.

After that you can use the Teamleader class to make calls to the Teamleader API. When the access token is expired the Teamleader class will automatically refresh the token.

Getting data

$teamleader->get('users.me');
$teamleader->get('departments.list');
$teamleader->get('companies.list');

Posting data

$teamleader->post(
    'contacts.add',
    [
        'first_name' => 'John',
        'last_name' => 'Doe',
    ]
);
$teamleader->post(
    'contacts.update',
    [
        'id' => 'xxx',
        'first_name' => 'John',
        'last_name' => 'Doe',
        'emails' => [
            ['type' => 'primary', 'email' => 'john@doe.com'],
        ],
    ]
)