Establishing a Connection
The objects available within our connector are accessible from the "cdata.bullhorncrm" module. To use the module's objects directly:
- Import the module as follows:
import cdata.bullhorncrm as mod
- To establish a connection string, call the connect() method from the connector object using an appropriate connection string, such as:
mod.connect("DataCenterCode=CLS33;OAuthClientId=myoauthclientid;OAuthClientSecret=myoauthclientsecret;InitiateOAuth=GETANDREFRESH;")
Pre-connection Requirements
Unlike many other data sources, Bullhorn CRM doesn't allow users to create their own custom OAuth applications or edit their CallbackURL directly. Instead, you must contact Bullhorn CRM and request that they create or change your OAuth application credentials (Client Id and Client Secret).
Bullhorn CRM also provides or updates your CallbackURL as needed. However, since waiting for a new CallbackURL from Bullhorn CRM may be a time-consuming process, we recommended that you consider using an OAuth verifier code to connect instead of a CallbackURL. Once Bullhorn CRM has provided your OAuth credentials, you can use them to authenticate your application.
Connecting to Bullhorn CRM
You'll need your username and password to authenticate and access your account. Follow these steps to ensure a successful connection:
- Use your account credentials to log in to your Bullhorn CRM account.
- Set the DataCenterCode in your application settings to the code that corresponds to your data center. For a full list of data center codes, refer to the list here.
Notes:
- If you are uncertain about your data center code, note that codes like CLS2, CLS21, etc. are cluster IDs that are visible in the URL in your browser's address bar once you are logged in. For example, https://cls21.bullhornstaffing.com/BullhornSTAFFING/MainFrame.jsp?#no-ba... indicates that the logged-in user is associated with data center CLS21.
- If you specify a CallbackURL such as http://localhost:33333/, ensure it is exactly the same as what you specify in your application settings. This includes any trailing slashes ("/"). Any addition or removal of characters from this URL will result in an error.
Authenticating to Bullhorn CRM (OAuth)
Bullhorn CRM supports OAuth authentication only. Unlike many other data sources, Bullhorn CRM doesn't allow users to create their own custom OAuth applications or edit their CallbackURL directly. Instead, you must request Bullhorn CRM to set up a custom OAuth application for you. This involves contacting Bullhorn CRM support to initiate the setup process. For information about how to create a custom OAuth application for Bullhorn CRM, see Creating a Custom OAuth Application.
The following subsections describe how to authenticate to Bullhorn CRM from three common authentication flows.
For a complete list of connection string properties available in Bullhorn CRM, see Connection.
Desktop Applications
To authenticate your desktop application, use one of the following options: using a verifier code or a custom CallbackURL. While using a custom CallbackURL is more straightforward, it requires you to contact Bullhorn CRM directly to request changes to it, which can be a time-consuming process. Therefore, we highly recommend using a verifier code instead. Although the setup is slightly more involved, it streamlines the authentication process.
Option 1: Using a verifier code
To start the authentication process with a verifier code, construct your authorization URL. This URL is what triggers the OAuth process where the output generates a unique code, which is essential for obtaining access tokens that enable secure interactions between your application and Bullhorn CRM.
Retrieving an OAuth verifier code
- Construct your Authorization URL as follows: https://<authorization URL for your data center>/oauth/authorize?client_id=<your OAuth Client Id>&response_type=code
- For example, if you have data center "CLS40", the URL used for authentication is: https://auth-east.bullhornstaffing.com/oauth/authorize?client_id=<your OAuth Client Id>&response_type=code
- Refer to the list here to find the authorization URL specific to your data center code.
- Next, open your authorization URL in a browser.
- Log in and grant permissions to the connector. You are redirected to the CallbackURL, which contains the verifier code. The URL format is: https://www.bullhorn.com/?code=<verifiercode>&client_id=<clientid>
- Save the value of the verifier code directly from the URL.
Get and refresh the OAuth access token
Once you have retrieved the OAuth verifier code, the next step is to use it to obtain and manage your OAuth access token. This token allows your application to authenticate and interact securely with Bullhorn CRM. Configure the folllwing settings:
- OAuthVerifier: The OAuth verifier code.
- DataCenterCode: The data center your account is connected with. Find the list of the data centers here.
- OAuthClientId: The Client Id that was assigned when you registered your custom OAuth application.
- OAuthClientSecret: The Client Secret that was assigned when you registered your custom OAuth application.
- CallbackURL: The redirect URI that was defined when you registered your custom OAuth application.
- InitiateOAuth: GETANDREFRESH. Used to automatically get and refresh the OAuthAccessToken.
The connector handles the OAuth process by authenticating requests using the access token, refreshing the access token when necessary, and persistently storing OAuth settings in OAuthSettingsLocation.
Option 2: Using a custom CallbackURL
If you prefer using a CallbackURL (for example, http://localhost:33333), contact Bullhorn CRM and request that they configure your chosen URL as the authorized endpoint for OAuth callbacks. Once Bullhorn CRM confirms that your CallbackURL is set up, proceed to configure your application with the following settings:
- CallbackURL: The custom CallbackURL provided by Bullhorn CRM.
- DataCenterCode: The data center your account is connected with. Find the list of the data centers here.
- OAuthClientId: The Client Id that was assigned when you registered your custom OAuth application.
- OAuthClientSecret: The Client Secret that was assigned when you registered your custom OAuth application.
- InitiateOAuth: GETANDREFRESH. Used to automatically get and refresh the OAuthAccessToken.
Web Applications
Authenticating via the Web requires you to create and register a custom OAuth application with Bullhorn CRM, as described in Creating a Custom OAuth Application. For web applications connecting to Bullhorn CRM, a predefined and registered CallbackURL is required. This URL is where Bullhorn CRM redirects users after successful authentication. You can then use the connector to get and manage the OAuth token values.
This section describes how to get the OAuth access token, how to have the driver refresh the OAuth access token automatically, and how to refresh the OAuth access token manually.
Get the OAuth access token
- To obtain the OAuthAccessToken, set these connection properties:
- OAuthClientId: The Client Id in your custom OAuth application settings.
- OAuthClientSecret: The Client Secret in your custom OAuth application settings.
- Call stored procedures to complete the OAuth exchange:
- Call the GetOAuthAuthorizationURL stored procedure. Set the AuthMode input to WEB and set the CallbackURL to the Redirect URI that you specified in your custom OAuth application settings. The stored procedure returns the URL to the OAuth endpoint.
- Navigate to the URL that the stored procedure returned in Step 1. Log in, and authorize the web application. You are redirected back to the callback URL.
- Call the GetOAuthAccessToken stored procedure. Set the AuthMode input to WEB. Set the Verifier input to the code parameter in the query string of the callback URL.
Automatic refresh of the OAuth access token
To have the connector automatically refresh the OAuth access token:
- Before connecting to data for the first time, set these connection parameters:
- InitiateOAuth: REFRESH.
- OAuthClientId: The Client Id in your custom OAuth application settings.
- OAuthClientSecret: The Client Secret in your custom OAuth application settings.
- OAuthAccessToken: The access token returned by GetOAuthAccessToken.
- OAuthSettingsLocation: The path where you want the connector to save the OAuth values, which persist across connections.
- On subsequent data connections, set:
- InitiateOAuth
- OAuthSettingsLocation
Manual refresh of the OAuth access token
The only value needed to manually refresh the OAuth access token is the OAuth refresh token.
- To manually refresh the OAuthAccessToken after the ExpiresIn period (returned by GetOAuthAccessToken) has elapsed, call the RefreshOAuthAccessToken stored procedure.
- Set these connection properties:
- OAuthClientId: The Client Id in your custom OAuth application settings.
- OAuthClientSecret: The Client Secret in your custom OAuth application settings.
- Call RefreshOAuthAccessToken with OAuthRefreshToken set to the OAuth refresh token returned by GetOAuthAccessToken.
- After the new tokens have been retrieved, set the OAuthAccessToken property to the value returned by RefreshOAuthAccessToken. This opens a new connection.
Store the OAuth refresh token so that you can use it to manually refresh the OAuth access token after it has expired.
Headless Machines
If you need to log in to a resource that resides on a headless machine, you must authenticate on another device that has an internet browser. You can do this in either of the following ways:
- Option 1: Obtain the OAuthVerifier code.
- Option 2: Install the connector on a machine with an internet browser and transfer the OAuth authentication values after you authenticate through the usual browser-based flow.
After you execute either Option 1 or Option 2, configure the driver to automatically refresh the access token on the headless machine.
Option 1: Obtaining and Exchanging a Verifier Code
To obtain a verifier code, you must authenticate at the OAuth authorization URL as follows:
- Authenticate from the machine with an internet browser, and obtain the OAuthVerifier connection property.
Set these properties:
- InitiateOAuth: OFF.
- OAuthClientId: The Client Id assigned when you registered your custom OAuth application.
- OAuthClientSecret: The Client Secret assigned when you registered your custom OAuth application.
- DataCenterCode: The data center your account is connected with. Find the list of the data centers here.
- Call the GetOAuthAuthorizationURL stored procedure. The stored procedure returns the CallbackURL established when the custom OAuth application was registered. (See Creating a Custom OAuth Application.) Copy this URL and paste it into a new browser tab.
- Log in and grant permissions to the connector. The OAuth application redirects you the redirect URI, with a parameter called code appended. Note the value of this parameter; you will need it later to configure the OAuthVerifier connection property.
- Call the GetOAuthAccessToken stored procedure and save the REST URL. You will set this in the RestUrl property.
- Exchange the OAuth verifier code for OAuth refresh and access tokens.
On the headless machine, to obtain the OAuth authentication values, set these properties:
- InitiateOAuth: REFRESH.
- OAuthVerifier: The noted verifier code (the value of the code parameter in the redirect URI).
- OAuthSettingsLocation: Persist the encrypted OAuth authentication values to the specified file.
- OAuthClientId: The Client Id in your custom OAuth application settings.
- OAuthClientSecret: The Client Secret in the custom OAuth application settings.
- RestUrl: The URL returned by the GetOAuthAccessToken stored procedure.
- DataCenterCode: The data center your account is connected with. Find the list of the data centers here.
- Test the connection to generate the OAuth settings file.
- You are ready to connect after you re-set these properties:
- InitiateOAuth: REFRESH.
- OAuthSettingsLocation: The file containing the encrypted OAuth authentication values. To enable the automatic refreshing of the access token, be sure that this file gives read and write permissions to the connector.
- OAuthClientId: The Client Id assigned when you registered your custom OAuth application.
- OAuthClientSecret: The Client Secret assigned when you registered your custom OAuth application.
- RestUrl: The URL returned by the GetOAuthAccessToken stored procedure.
- DataCenterCode: The data center your account is connected with. Find the list of the data centers here.
Option 2: Transferring OAuth Settings
Prior to connecting on a headless machine, you must install and create a connection with the driver on a device that supports an internet browser. Set the connection properties as described above in "Desktop Applications".
After completing the instructions in "Desktop Applications", the resulting authentication values are encrypted and written to the path specified by OAuthSettingsLocation. The default filename is OAuthSettings.txt.
Test the connection to generate the OAuth settings file, then copy the OAuth settings file to your headless machine.
To connect to data via the headless machine, set these connection properties:
- InitiateOAuth: REFRESH.
- OAuthSettingsLocation: The path to the OAuth settings file you copied from the machine with the browser. To enable automatic refreshing of the access token, ensure that this file gives read and write permissions to the connector.
- OAuthClientId: The Client Id assigned when you registered your custom OAuth application.
- OAuthClientSecret: The Client Secret assigned when you registered your custom OAuth application.
- RestUrl: The URL returned by the GetOAuthAccessToken stored procedure.
- DataCenterCode: The data center your account is connected with. Find the list of the data centers here.