1.0.0 • Published 7 months ago

bullhorn-rest-tokens v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

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:
ParameterTypeDescription
authUrlstringThe authorization URL for Bullhorn.
restUrlstringThe REST API base URL for Bullhorn.
clientIdstringYour Bullhorn API client ID.
clientSecretstringYour Bullhorn API client secret.
apiUserstringThe Bullhorn API username.
apiPassstringThe 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