GithubHelp home page GithubHelp logo

bullhorn-rest-client's Introduction

Bullhorn REST Client

Provides a simple client for the Bullhorn REST API.

Installation

$ composer require jonathanraftery/bullhorn-rest-client

Usage

use jonathanraftery\Bullhorn\Rest\Client as BullhornClient;
$client = new BullhornClient();

By default, the client will look for credentials in environment variables:

  • BULLHORN_CLIENT_ID
  • BULLHORN_CLIENT_SECRET
  • BULLHORN_USERNAME
  • BULLHORN_PASSWORD

Options

The client constructor accepts an option array.

use jonathanraftery\Bullhorn\Rest\Auth\CredentialsProvider\MemoryCredentialsProvider;
use jonathanraftery\Bullhorn\Rest\Client as BullhornClient;
use jonathanraftery\Bullhorn\Rest\ClientOptions;

$client = new BullhornClient([
    // NOTE: MemoryCredentialProvider not recommended for production
    ClientOptions::CredentialsProvider => new MemoryCredentialsProvider(
        'clientId', 'clientSecret', 'username', 'password'
    ),
]);

The ClientOptions class can be used to view the available options.

Credential Providers

A credential provider supplies the client with the credentials needed to connect to the API. There are simple providers included, or you can create your own with a class implementing the CredentialsProviderInterface (for example, to fetch credentials from Google Cloud Secret Manager).

use jonathanraftery\Bullhorn\Rest\Client as BullhornClient;
use jonathanraftery\Bullhorn\Rest\ClientOptions;
use jonathanraftery\Bullhorn\Rest\Auth\CredentialsProvider\CredentialsProviderInterface;

class CustomCredentialProvider implements CredentialsProviderInterface {
    public function getClientId() : string{ return 'id'; }
    public function getClientSecret() : string{ return 'secret'; }
    public function getUsername() : string{ return 'username'; }
    public function getPassword() : string{ return 'password'; }
}

$client = new BullhornClient([
    ClientOptions::CredentialsProvider => new CustomCredentialProvider()
]);

By default, the client will use an EnvironmentCredentialsProvider, which will look in the environment variables listed above for credentials. The variables used can be changed by constructing an EnvironmentCredentialsProvider with the other variables.

Auth Data Stores

API session data needs persisted in a data store. By default, the client will use a local JSON file for this store, but custom stores can be used.

use jonathanraftery\Bullhorn\Rest\Client as BullhornClient;
use jonathanraftery\Bullhorn\Rest\ClientOptions;
use jonathanraftery\Bullhorn\Rest\Auth\Store\DataStoreInterface;

class CustomDataStore implements DataStoreInterface {
    private $vars;

    public function get(string $key) : ?string{
        return $this->vars[$key];
    }

    public function store(string $key,$value){
        $this->vars[$key] = $value;
    }
}

$client = new BullhornClient([
    ClientOptions::AuthDataStore => new CustomDataStore()
]);

Initial OAuth consent

Before Bullhorn authorizes API calls from a new user, the user is required to give consent. If no consent has been given yet the library will throw an IdentityException and the client will respond with an HTML representation of the consent form.

To permanently fix this, visit the authorization URL with your credentials auth.bullhornstaffing.com/oauth/authorize?response_type=code&action=Login&username=&password=&state=<client_secret>&approval_prompt=auto&client_id=<client_id> while logged into bullhorn and press the Agree button. This will authorize your application to use the API in the user's name.

Raw Requests

Simple requests as documented in the Bullhorn API documentation can be run as:

use jonathanraftery\Bullhorn\Rest\Client as BullhornClient;
$client = new BullhornClient();
$response = $client->rawRequest(
    'GET',
    'search/JobOrder',
    [
        'query' => 'id:1234'
    ]
);

PUT/POST Requests

The client uses GuzzleHTTP for requests, and the parameters to the request method match those to create a request object in Guzzle. The third parameter is the request options, as described in the Guzzle documentation.

To set the body of a PUT/POST request, set the "body" option of the request to the JSON content of the request body such as:

use jonathanraftery\Bullhorn\Rest\Client as BullhornClient;
$client = new BullhornClient();
$response = $client->rawRequest(
    'PUT',
    'entity/Candidate',
    [
        'body' => json_encode(['firstName' => 'Alanzo', 'lastName' => 'Smith', 'status' => 'Registered'])
    ]
);

Entity Operations

Entities can be fetched, created, and deleted

use jonathanraftery\Bullhorn\Rest\Client as BullhornClient;
use jonathanraftery\Bullhorn\Rest\BullhornEntities;
$client = new BullhornClient();
$fetchedJobOrders = $client->fetchEntities(BullhornEntities::JobOrder, [1,2,3], [
    'fields' => 'id',
]);
$createdJobOrder = $client->createEntity(BullhornEntities::JobOrder, [
    'propName' => 'value',
    'propName2' => 'value',
]);
$deleteId = 1;
$client->deleteEntity(BullhornEntities::JobOrder, $deleteId);

Event Subscriptions

use jonathanraftery\Bullhorn\Rest\Client as BullhornClient;
use jonathanraftery\Bullhorn\Rest\BullhornEntities;
use jonathanraftery\Bullhorn\Rest\EventTypes;
$client = new BullhornClient();
$client->createEventSubscription('SubscriptionName', [BullhornEntities::JobOrder], [EventTypes::Created]);
$client->fetchEventSubscriptionEvents('SubscriptionName');
$client->deleteEventSubscription('SubscriptionName');

Sessions

A session will automatically be initiated upon the first request if no session exists in the data store.

A session can be manually initiated with:

use jonathanraftery\Bullhorn\Rest\Client as BullhornClient;
$client = new BullhornClient();
$client->initiateSession();

The session will automatically refresh if expiration detected, or can be refreshed manually (shown with optional parameters)

use jonathanraftery\Bullhorn\Rest\Client as BullhornClient;
$client = new BullhornClient();
$client->refreshSession(['ttl' => 60]);

bullhorn-rest-client's People

Contributors

40katty04 avatar drmmr763 avatar jonathanraftery avatar kajdemunter avatar sjerdo avatar survivorbat avatar yaroslawww avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bullhorn-rest-client's Issues

Bullhorn Rest Client + Lucene Query Builder = Awesome

Hi All

Just wanted to share my personal experience using this package in conjunction with a query builder package:

https://github.com/minimalcode-org/search

I combined both these into a laravel project as a service and was able to get some great results:

// build a query:
$queryBuilder = Criteria::where('email')->in($emails);
$queryBuilder->orWhere('phone')->in($phones);
// make a request
$response = $client->request(
                'POST',
                'search/Candidate',
                [
                    'body' => json_encode([
                        'query'  => $queryBuilder->getQuery(),
                        'fields' => 'id,firstName,lastName,email,phone'
                    ]),
                ]
            );

Not sure the overall vision for this package, but it might be interesting to make the query builder a dependency. If not totally understand and I'm happy to handle that all in my project.

Hope this helps someone out there. Cheers!

PHP8 support

Can you add PHP8 support?

- jonathanraftery/bullhorn-rest-client is locked to version 1.3.1 and an update of this package was not requested.
- jonathanraftery/bullhorn-rest-client 1.3.1 requires php ^7.3 -> your php version (8.0.6; overridden via config.platform, same as actual) does not satisfy that requirement.

CandidateEducation, CandidateWorkHistory etc not working

Greetings,

How can I fetch Candidate's other entities like CandidateWorkHistory, CandidateEducation etc listed here in https://bullhorn.github.io/rest-api-docs/entityref.html#candidateworkhistory.

Following snippet is not working in this version 1.4.0 -

$client->searchEntities(
    'CandidateWorkHistory',
    'where=candidate.id=xxxxx',
    [
        'fields' => 'id,startDate,endDate,title,companyName,comments'
    ]
); 

It's working fine with old version 0.3.3 -

$client->request(
    "GET",
    'query/CandidateWorkHistory?where=candidate.id=xxxxx&fields=id,startDate,endDate,title,companyName,comments',
    ['http_errors'=>false]
);

I am getting error 'errors.searchUnknownEntity'
Thank you for your great work.

Sometimes getting refresh token issue

Sometimes the session refresh is not working.

Is there anyway that we can all the records of candidates, companies, contacts, job orders, placements?

Problem with the request limit

Hi!
Bullhorn can give back max 200 row per request.
The MAX_ENTITY_REQUEST_COUNT =500 is not good, in JobOrders.php line 7.
Anyway your sript is wonderfull. Thank you very much!!!!

Undefined array key 0 on line 296

The "Invalid credentials" status gives me an error in your sdk:

Undefined array key 0 on line 296 in /vendor/jonathanraftery/bullhorn-rest-client/src/Auth/AuthClient.php

License

Hi there,

I can't seem to find any license information for this project, are you able to confirm what license the code is under?

Thanks!

Improve PUT/POST request interface

Hello.
I am trying to send a PUT request which requires additional parameters.
I have the request like
$response = $client->request(
'PUT',
'entity/Candidate',
["firstName" => "Alanzo", "lastName" => "Smith", "status" => "Registered"]
);

But I get back this error message from Bullhorn - No content to map to Object due to end of input.
Can you advise what I am doing wrong?

Add Logging

Logging should be added in accordance with PSR-3 logger abstraction

AuthorizationException from Terms of Service Acknowledgement

Client will throw AuthorizationException: 'Identity provider exception' if Terms of Service have not been acknowledged.

Typically this exception results from incorrect credentials, but currently is also thrown in the event above. Client needs a more meaningful exception in this case, or to automatically acknowledge the ToS.

Current workaround

Manually perform OAuth login with the provided credentials to clear the ToS acknowledgement. Once acknowledged, the issue is permanently resolved.

Authentication Flow Update

Hi @jonathanraftery

Thanks so much for this package we have been using successfully for some time.

I did just have quite a harrowing issue with Authentication. Bullhorn recently changed in June 2023 some of their authentication flows and their generic auth.bullhornstaffing urls aren't as reliable as they are. I just got off a call with one of their senior support analysts who pointed me to this documentation:

https://bullhorn.github.io/Data-Center-URLs/

I hacked the AuthClient class to change the URLs to auth-west per his recommendation. That fixed the auth issue for us. But it does mean hacking the library to resolve. Making this configurable somehow would be great.

PHP8.2: Using ${var} in strings is deprecated

In bullhorn-rest-client/src/Auth/AuthClient.php

Line 299:
throw new BullhornAuthException("Failed to fetch authorization code (HTTP error: ${errorMessage})");

Suggested change:
throw new BullhornAuthException("Failed to fetch authorization code (HTTP error: ". $errorMessage .")");

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.