1.0.0 • Published 7 months ago
bullhorn-rest-tokens v1.0.0
BullhornRestTokens
BullhornRestTokens is a lightweight library for authenticating with the Bullhorn API for M2M purposes.
Installation
Install via npm:
npm install bullhorn-rest-tokens
Usage
Namespace-Based Example
Import the library and call the authenticate
function:
const BullhornRestTokens = require('bullhorn-rest-tokens');
(async () => {
try {
const config = {
authUrl: 'https://auth.bullhornstaffing.com',
restUrl: 'https://rest.bullhornstaffing.com',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
apiUser: 'your-api-user',
apiPass: 'your-api-pass',
};
// Authenticate with Bullhorn
const tokens = await BullhornRestTokens.authenticate(config);
console.log('Authenticated Tokens:', tokens);
// Use the tokens to make API requests
const axios = require('axios');
const response = await axios.get(`${tokens.restUrl}/entity/Candidate/1`, {
headers: {
Authorization: `Bearer ${tokens.restToken}`,
},
});
console.log('API Response:', response.data);
} catch (error) {
console.error('Authentication failed:', error.message);
}
})();
Function Overview
BullhornRestTokens.authenticate(config)
Authenticates with the Bullhorn API and returns REST tokens.
Parameters:
Parameter | Type | Description |
---|---|---|
authUrl | string | The authorization URL for Bullhorn. |
restUrl | string | The REST API base URL for Bullhorn. |
clientId | string | Your Bullhorn API client ID. |
clientSecret | string | Your Bullhorn API client secret. |
apiUser | string | The Bullhorn API username. |
apiPass | string | The Bullhorn API password. |
Returns:
A Promise that resolves to an object with the following structure:
{
restToken: 'abc123', // The REST token for API authentication
restUrl: 'https://...', // The base REST API URL
expiresIn: 3600, // Expiration time in seconds
issuedAt: 1672531200000 // Timestamp of when the token was issued
}
Example API Request
Once you’ve authenticated, use the returned restToken
and restUrl
to make API requests with your preferred HTTP library:
const axios = require('axios');
(async () => {
const tokens = await BullhornRestTokens.authenticate(config);
const response = await axios.get(`${tokens.restUrl}/entity/Candidate/1`, {
headers: {
Authorization: `Bearer ${tokens.restToken}`,
},
});
console.log('Candidate Data:', response.data);
})();
Error Handling
If authentication fails, the authenticate
function will throw an error. Ensure you handle errors appropriately:
try {
const tokens = await BullhornRestTokens.authenticate(config);
} catch (error) {
console.error('Error:', error.message);
}
Contributing
Contributions are welcome! Please submit a pull request with your changes.
License
This library is licensed under the MIT License. See LICENSE for details.
1.0.0
7 months ago