PHP code example of pistej / humanity-php-sdk

1. Go to this page and download the library: Download pistej/humanity-php-sdk 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/ */

    

pistej / humanity-php-sdk example snippets



use \Humanity\Entity\Company;
use \Humanity\Entity\Employee;
use \Humanity\Humanity;

// Load Humanity SDK for PHP via composer

$config = [
	'provider' => [
		'clientId' => '...',
		'clientSecret' => '...',
		'redirectUri' => '...',
		'scopes' => [
			Company::SCOPE_VIEW,
			Employee::SCOPE_VIEW
		],
	],
];

// Create new instance of humanity class
$humanity = new Humanity($config);

// Obtain access token
$humanity->obtainAccessToken();
// Get access token instance
$accessToken = $humanity->getAccessToken();
printf('Access token: %s<br/>', $accessToken->accessToken);

$me = $humanity->me();
printf('Hello, %s<br/>', $me->display_name);

// Get Company repository instance
$companyRepository = $humanity->getCompanyRepository();
// Retrieve company data for current logged employee
$company = $companyRepository->get($me->company_id);
printf('Company: %s<br/>', $company->name);

// Get Employee repository instance
$employeeRepository = $humanity->getEmployeeRepository();
// Retrieve employees data for company.
$employees = $employeeRepository->getByCompany($company->company_id);

echo 'Employees: ';
echo '<ul>';
// Iterating employees collection
foreach ($employees as $employee) {
	printf('<li>%s</li>', $employee->display_name);
}
echo '</ul>';
bash
$ composer