PHP code example of justijndepover / teamleader-api

1. Go to this page and download the library: Download justijndepover/teamleader-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

justijndepover / teamleader-api example snippets


// 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;

$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();

$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();

$teamleader->get('users.me');
$teamleader->get('departments.list');
$teamleader->get('departments.info', ['id' => $id]);
$teamleader->post('contacts.add', [
    // all the data
]);

// 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();

$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();