PHP cURL - REST API - get already generated AccessToken/BhRestToken - 02309332

Forum for users and developers of Bullhorn's API service.

Moderators: StaffingSupport, s.emmons, BullhornSupport

Post Reply
vedant
User
Posts: 4
Joined: Wed Jan 27, 2016 4:18 am

PHP cURL - REST API - get already generated AccessToken/BhRestToken - 02309332

Post by vedant » Sun Mar 06, 2016 2:40 am

Hello everyone,

I am creating one web application.I am using PHP cURL to use Bullhorn REST API to access their services.

The procedure is as following:

Make an API call to get Authorization code.
Using that Authorization code, make another API call to get Access Token [which is valid for 10 min].
Using that Access Token, make another Login API call to get BhRestToken(session key) and restUrl (Base url).
Using that BhRestToken and restUrl, make other API calls to access the database. [Create new records / Get some records / Update records]

Here, when I want to perform any action to access bullhorn service, I have to follow above steps. Means I am making 3-4 API calls

The problem I am facing is, I am not getting, how to check whether the previous present Access Token OR BhRestToken is valid / available so that, I can execute the last step directly. If that Access Token OR BhRestToken is not valid / available then, I will follow all the steps.

Can anyone help me to solve this issue?

DaveNorthCreek
User
Posts: 89
Joined: Fri Nov 20, 2015 2:04 pm

Re: PHP cURL - REST API - get already generated AccessToken/BhRestToken

Post by DaveNorthCreek » Tue Mar 08, 2016 2:43 pm

Just save and reuse the tokens all the way up. When you get an error, go back one step in your workflow and re-apply for a new token.

Once you write the code and automate it, you just ask for a connection and don't think about it again.

My code is spread across multiple classes, but it follows that strategy. I have a test method that prints out a BhRestToken to the terminal so I can use it on Postman. I check whenever I connect to see if the previously cached token still works. If it doesn't, up the stack. No harm to get an error message from Bullhorn- they come back pretty quick.

Cheers,
Dave
North Creek

vedant
User
Posts: 4
Joined: Wed Jan 27, 2016 4:18 am

Re: PHP cURL - REST API - get already generated AccessToken/BhRestToken

Post by vedant » Sat Mar 12, 2016 4:15 am

Thank you for your answer. It really helped me. :)

maheswari
User
Posts: 3
Joined: Wed Jul 27, 2016 10:53 am

Re: PHP cURL - REST API - get already generated AccessToken/BhRestToken

Post by maheswari » Mon Aug 01, 2016 6:33 am

Could you please hep me , how to generate the access token using refresh token?

ColinC
User
Posts: 67
Joined: Fri Apr 08, 2016 4:54 pm

Re: PHP cURL - REST API - get already generated AccessToken/BhRestToken

Post by ColinC » Mon Aug 01, 2016 1:22 pm

Hello maheswari,

On our getting started page (http://developer.bullhorn.com/articles/getting_started) it runs through this and more.

The section in specific is here:
Use a refresh token to get a new access token
To obtain an access token with a refresh token, make a POST request with the following URL, substituting your actual values for the placeholders in the query parameters:

https://auth.bullhornstaffing.com/oauth ... ent_secret}

I hope this helps!
Colin Coffman
Enterprise Support Analyst
B U L L H O R N
Staffing and Recruiting Software, On Target, On Demand
617-478-9126 (US Support)
+44 800 032 2848 ext. 9131 (UK Support)

ColinC
User
Posts: 67
Joined: Fri Apr 08, 2016 4:54 pm

Re: PHP cURL - REST API - get already generated AccessToken/BhRestToken

Post by ColinC » Mon Aug 01, 2016 1:23 pm

That didn't paste properly. Let's try this.

Code: Select all

https://auth.bullhornstaffing.com/oauth/token?grant_type=refresh_token&refresh_token={refresh_token}&client_id={client_id}&client_secret={client_secret}
Colin Coffman
Enterprise Support Analyst
B U L L H O R N
Staffing and Recruiting Software, On Target, On Demand
617-478-9126 (US Support)
+44 800 032 2848 ext. 9131 (UK Support)

maheswari
User
Posts: 3
Joined: Wed Jul 27, 2016 10:53 am

Re: PHP cURL - REST API - get already generated AccessToken/BhRestToken

Post by maheswari » Wed Aug 03, 2016 7:43 am

public function BHConnect() {
try {
if (isset($_SESSION['BH']['auth_code'])) {
if ((!isset($_SESSION['BH']['restToken'])) || (isset($_SESSION['BH']['tokenCreated']) && $_SESSION['BH']['tokenCreated'] + 8 * 60 < time())) {

$token = $this->getRefreshAccess($_SESSION['BH']['refreshToken']);

$sessionToken = $this->getBHSession($token->access_token);

$this->setBHSession($sessionToken);
}
} else {
$this->setCredentials();

$authCode = $this->getBHAuthCode();

$token = $this->getBHTokens($authCode);

$sessionToken = $this->getBHSession($token->access_token);

$this->setBHSession($sessionToken);
}
} catch (Exception $e) {
return $e;
}


private function getRefreshAccess($refreshtoken) {
$method = 'token?grant_type=refresh_token&refresh_token=' . $refreshtoken . '&client_id=' .
$this->bh_client_id . '&client_secret=' . $this->bh_clinet_secret;

$options = array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => true, CURLOPT_POSTFIELDS => array());

$response = $this->makeHttpRequest($this->bh_auth_url, $method, $options);

return $response;
}


How to I check the first access token was expired ?
The above code is returned error like Invalid, expired, or revoked refresh token.

maryjohn
User
Posts: 5
Joined: Wed Aug 10, 2016 6:04 am

Re: PHP cURL - REST API - get already generated AccessToken/BhRestToken

Post by maryjohn » Wed Aug 10, 2016 6:47 am

Could you please hep me , how to generate the access token using refresh token?
Hello I Am Mary

dfuller
User
Posts: 24
Joined: Tue May 03, 2016 1:47 pm

Re: PHP cURL - REST API - get already generated AccessToken/BhRestToken

Post by dfuller » Mon Aug 15, 2016 10:33 am

maryjohn wrote:Could you please hep me , how to generate the access token using refresh token?
Hi Mary,

This was covered by Colin earlier in the thread:
Plugging the refresh token, client ID, and client secret into the appropriate spots (minus the brackets) will allow you to get an access token.
How to I check the first access token was expired ?
The above code is returned error like Invalid, expired, or revoked refresh token.
Hi Maheswari,

There is not call to check and see if an access token is expired - it will just tell you once it is. My recommendation would be to re-run the auth process if the token turns out to be expired.

Warm regards,
Dan
Dan Fuller | Enterprise Support Analyst

Post Reply