Via Composer
$ composer require jeffreyhyer/bamboohr
Or add the following to your composer.json
file:
{
"require": {
"jeffreyhyer/bamboohr": "^0.1.2"
}
}
Then execute the following command to install the package:
$ composer update
From within your PHP application you can access the BambooHR API with just a couple lines:
<?php
require "./vendor/autoload.php";
$bamboo = new BambooHR\BambooHR("BAMBOO COMPANY SUBDOMAIN", "BAMBOO API TOKEN");
// Get the employee directory
$employees = $bamboo->employees->directory();
<?php
$company = "demo"; // Your company's BambooHR subdomain (e.g. http://demo.bamboohr.com/)
$api_key = "0123456789abcdef"; // You API token
$bamboo = new BambooHR\BambooHR($company, $api_key);
Once instantiated you have access to all the BambooHR API endpoints through convenient helper
methods or properties. Through the use of PHP’s __get()
and __call()
so-called “magic” methods
you can access a given API through either it’s property or method name or one of a number of aliases.
For example, to access the employee directory you could use any of the following:
<?php
$bamboo->employee->directory(); // 'employee' is a "magic" property
$bamboo->employees->directory(); // 'employees' (plural) is an alias for 'employee'
$bamboo->employee()->directory(); // 'employee()' is a "magic" method
$bamboo->employees()->directory(); // Using the alias again...
...
All calls to the API return an instance of the BambooHR\Api\Response
class.
The Response
class has a number of convenient abstractions that make working with
API requests and responses easier including error checking and a standard response format.
Method | Return Type | Description |
---|---|---|
hasErrors() |
boolean |
Returns |
getErrors() |
array |
Returns an array of strings that contain the error(s) returned in the response headers |
getCode() |
integer |
Returns the HTTP status code of the response (e.g. 200 for OK, 403 for Forbidden, etc) |
getReason() |
string |
Returns the HTTP status text of the response (e.g. "OK", "Forbidden", etc) |
getResponse() |
object|array |
Returns the raw JSON-decoded response from the API |
See the BambooHR documentation relating to employees here: https://www.bamboohr.com/api/documentation/employees.php
Can be accessed via any of the following aliases:
Returns the current user as determined by the API key used for the request.
This is an alias/shortcut for calling: $bamboo->employees->byId(0, $fields)
Request
<?php
// Defaults to all fields
$bamboo->employees->me();
// -OR-
// Specify which fields to return
$bamboo->employees->me(['firstName', 'lastName']);
Response
<?php
BambooHR\Api\Response Object
(
[code:protected] => 200
[reason:protected] => OK
[errors:protected] => Array
(
)
[response:protected] => stdClass Object
(
[id] => 123
[address1] => 123 North Main St
[address2] =>
[age] => 25
[bestEmail] => test@yourcompany.com
[birthday] => 12-25
[city] => Lindon
[country] =>
[dateOfBirth] => 1901-01-01
[department] =>
[division] =>
[eeo] =>
[employeeNumber] => 123456
[employmentHistoryStatus] => Full-Time
[ethnicity] =>
[flsaCode] => Exempt
[firstName] => John
[fullName1] => John Doe
[fullName2] => Doe, John
[fullName3] => Doe, John B
[fullName4] => Doe, John B
[fullName5] => John B Doe
[displayName] => John Doe
[gender] => Male
[hireDate] => 2000-01-01
[originalHireDate] => 0000-00-00
[homeEmail] => john@yourcompany.com
[homePhone] => 555-123-4567
[jobTitle] => Job Title
[lastChanged] => 2001-01-01T12:34:56+00:00
[lastName] => Doe
[location] => Utah
[maritalStatus] => Married
[middleName] => B
[mobilePhone] =>
[payChangeReason] =>
[payGroupId] =>
[payRate] => 123456.00 USD
[payRateEffectiveDate] => 2000-01-01
[payType] => Salary
[payPer] => Year
[payPeriod] => Every other week
[preferredName] =>
[ssn] =>
[state] => UT
[stateCode] => UT
[status] => Active
[supervisor] => Jane Doe
[supervisorId] => 123457
[supervisorEId] => 124
[terminationDate] => 0000-00-00
[workEmail] =>
[workPhone] =>
[workPhonePlusExtension] =>
[workPhoneExtension] =>
[zipcode] => 12345
[isPhotoUploaded] => false
)
)
Returns the user identified by $id
Request
<?php
// Defaults to all fields
$bamboo->employees->byId(123);
// -OR-
// Specify which fields to return
$bamboo->employees->byId(123, ['firstName', 'lastName']);
Response
<?php
BambooHR\Api\Response Object
(
[code:protected] => 200
[reason:protected] => OK
[errors:protected] => Array
(
)
[response:protected] => stdClass Object
(
[id] => 123
[address1] => 123 North Main St
[address2] =>
[age] => 25
[bestEmail] => test@yourcompany.com
[birthday] => 12-25
[city] => Lindon
[country] =>
[dateOfBirth] => 1901-01-01
[department] =>
[division] =>
[eeo] =>
[employeeNumber] => 123456
[employmentHistoryStatus] => Full-Time
[ethnicity] =>
[flsaCode] => Exempt
[firstName] => John
[fullName1] => John Doe
[fullName2] => Doe, John
[fullName3] => Doe, John B
[fullName4] => Doe, John B
[fullName5] => John B Doe
[displayName] => John Doe
[gender] => Male
[hireDate] => 2000-01-01
[originalHireDate] => 0000-00-00
[homeEmail] => john@yourcompany.com
[homePhone] => 555-123-4567
[jobTitle] => Job Title
[lastChanged] => 2001-01-01T12:34:56+00:00
[lastName] => Doe
[location] => Utah
[maritalStatus] => Married
[middleName] => B
[mobilePhone] =>
[payChangeReason] =>
[payGroupId] =>
[payRate] => 123456.00 USD
[payRateEffectiveDate] => 2000-01-01
[payType] => Salary
[payPer] => Year
[payPeriod] => Every other week
[preferredName] =>
[ssn] =>
[state] => UT
[stateCode] => UT
[status] => Active
[supervisor] => Jane Doe
[supervisorId] => 123457
[supervisorEId] => 124
[terminationDate] => 0000-00-00
[workEmail] =>
[workPhone] =>
[workPhonePlusExtension] =>
[workPhoneExtension] =>
[zipcode] => 12345
[isPhotoUploaded] => false
)
)
Returns the employee directory
Request
<?php
$bamboo->employees->directory();
Response
<?php
// TODO
BambooHR\Api\Response Object
(
[code:protected] => 200
[reason:protected] => OK
[errors:protected] => Array
(
)
[response:protected] => stdClass Object
(
)
)
Add a new employee
See: https://www.bamboohr.com/api/documentation/employees.php#addEmployee
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
$data |
Array |
✅ |
Data describing the employee to be created. |
Request
<?php
$data = [
'firstName' => 'John',
'lastName' => 'Doe'
];
$bamboo->employees->add($data);
Response
<?php
// TODO
BambooHR\Api\Response Object
(
[code:protected] => 200
[reason:protected] => OK
[errors:protected] => Array
(
)
[response:protected] => stdClass Object
(
)
)
Edit/update an existing employee
See: https://www.bamboohr.com/api/documentation/employees.php#updateEmployee
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
$id |
Mixed (String) |
✅ |
The employee ID to update |
$data |
Array |
✅ |
The data to set on the employee |
Request
<?php
$data = [
'firstName' => 'Joe',
'lastName' => 'Schmo',
];
$bamboo->employees->update('123', $data);
Response
<?php
// TODO
BambooHR\Api\Response Object
(
[code:protected] => 200
[reason:protected] => OK
[errors:protected] => Array
(
)
[response:protected] => stdClass Object
(
)
)
Get a list of files associated with the given employee
See: https://www.bamboohr.com/api/documentation/employees.php#listEmployeeFiles
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
$id |
Mixed (String) |
✅ |
An employee ID |
Request
<?php
$bamboo->employee->files(123);
Response
<?php
// TODO
BambooHR\Api\Response Object
(
[code:protected] => 200
[reason:protected] => OK
[errors:protected] => Array
(
)
[response:protected] => stdClass Object
(
)
)