问题
I'm trying to save and update a candidate in Bullhorn through the REST API with PHP.
I've loaded a candidate from BullHorn and my categories are shown this way:
["categories"]=>
object(stdClass)#632 (2) {
["total"]=>
int(2)
["data"]=>
array(0) {
}
}
["category"]=>
object(stdClass)#654 (1) {
["id"]=>
int(1123135)
}
I can see that my id is equal to 1123135
. But how can I know which categories these are? I've selected two categories in BullHorn and my id is now 1123135... . I have categories like "E-marketing Expert, Data Science, ...".
But how can I update these categories based on the user's selected choices?
回答1:
Categories in Bullhorn are similar to most other entities. This is the way I do it
function BHGetCategoryData($entity_type, $entity_id) {
$url = $_SESSION['restUrl'].'entity/'.$entity_type.'/'.$entity_id.'?BhRestToken='.$_SESSION['BhRestToken'].'&fields=id,name';
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$data = curl_exec( $ch );
$obj = json_decode($data, true);
curl_close( $ch );
return $obj;
}
function BHQueryCategory() {
$url = $_SESSION["restUrl"]."/query/Category?where=enabled=true%20AND%20id>1&fields=id,name&orderBy=id&count=100&BhRestToken=".$_SESSION["BhRestToken"];
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$data = curl_exec( $ch );
$obj = json_decode($data, true);
return $obj;
}
// This dumps a list of categories
var_dump(BHQueryCategory());
$entity_id= 1123135;
$entity_type='Category';
// This will query one category for the name and id
var_dump(BHGetCategoryData($entity_type, $entity_id));
This of course assumes that you have your rest url and rest token and all that stuff taken care of.
Because of time delays in dynamically pulling all your categories, I would probably suggest that you download the full list and populate it client side - rather than calling the query every-time you want to populate a dropdown.
Also here is a confusing bit. There is "Category" which can be written as a single value to a Candidate record. There is also "Categories" which is a "To-Many" relationship and cant be written with the main entity, it must be called separately. Below is a function that will do that.
function BHCreateCandidateToMany($candid,$codegroup,$codestring) {
$url = $_SESSION['restUrl'].'entity/Candidate/'.$candid.'/'.$codegroup.'/'.$codestring.'?BhRestToken='.$_SESSION['BhRestToken'];
echo $url;
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => Array("Content-Type: application/json"),
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$data = curl_exec( $ch );
$obj = json_decode($data, true);
curl_close( $ch );
return $obj;
}
The documentation is found here - http://developer.bullhorn.com/documentation/rest-api-1-1-update
(Please tidy up the code as needed - just a rough draft to get you on your way)
来源:https://stackoverflow.com/questions/29072074/insert-candidate-with-categories-bullhorn