Get Categories for JobOrder PHP Script

Forum for users and developers of Bullhorn's Webservices API suite

Moderators: StaffingSupport, s.emmons, BullhornSupport

Post Reply
Posts: 1
Joined: Wed Apr 24, 2013 1:42 am

Get Categories for JobOrder PHP Script

Post by lxjam » Wed Apr 24, 2013 2:07 am

This took me forever but I finally got there! I don't care if the PHP code is not great as after hours of trying it works!!

I hope this helps someone!

(You'll need SOAP installed on your webserver and PHP's SimpleXML extension - which I think SimpleXML is part of PHP now as standard).

Code: Select all

		// Create a new instance of the SoapClient class.
		$params = array(
			'trace' => 1,
			'soap_version' => SOAP_1_1);
		$BHclient = new SoapClient("",$params);
		// To run this code, you will need a valid username, password, and API key.
		$username = "xxxxxxxxxxxxx";
		$password = "xxxxxxxxxxxx";
		$apiKey = "xxxxxxxx-xxxxxxxxx-xxxxxxxxx-xxxxxxxxxx";
		// Start a new session
		$session_request = new stdClass();
		$session_request->username = $username;
		$session_request->password = $password;
		$session_request->apiKey = $apiKey;
		$API_session = $BHclient->startSession($session_request);
		$API_currentSession = $API_session->return;

		// Put nto a request object
		$findId = new SoapVar('PUT_YOUR_JOB_ID_HERE', XSD_INTEGER,"int","");
		$request_array = array (
		//new SoapHeader('','Identity token="123456789"',null),
		'session' => $API_currentSession,
		'entityName' => 'JobOrder',
		'associationName' => 'categories'
	   // print_r($request_array);
		$SOAP_request = new SoapVar($request_array, SOAP_ENC_OBJECT, "getAssociationIDs", "");
		// Use the query method to return the candidate ids
		try {
		$queryResult = $BHclient->getAssociationIDs($SOAP_request);
		} catch (SoapFault $fault) {
			/*echo '<pre>';
    		echo "REQUEST:\n" . $BHclient->__getLastRequest();
    		echo '</pre>';*/
		/*echo '<pre>';
    		echo "REQUEST:\n" . $BHclient->__getLastResponse();
    		echo '</pre>';*/
		$element = $BHclient->__getLastResponse();
                //Get rid of the nasty parts that PHP's SimpleXML does not like-long winded buy hey....
                $xmlstr = str_replace("S:Body","SBody",$element);
		$xmlstr = str_replace("S:Envelope","SEnvelope",$xmlstr);
		$xmlstr = str_replace(' xmlns:S=""',"",$xmlstr);
		$xmlstr = str_replace('ns2:getAssociationIdsResponse',"getAssociationIdsResponse",$xmlstr);
		$xmlstr = str_replace(' xmlns:ns2=""',"",$xmlstr);
		$xmlstr = str_replace(' xmlns:xsi="" xmlns:xs="" xsi:type="xs:int"',"",$xmlstr);
		//Replace return node as it's PHP code!!
		$xmlstr = str_replace('return',"returnthis",$xmlstr);
		$xml = new SimpleXMLElement($xmlstr);
		$catID = $xml->SBody->getAssociationIdsResponse->returnthis->ids;
		//I am presuming that if we have more than one Category Id that they would be passed as an array i.e seperated by a comma.
		$catID = explode(",",$catID);
		echo $catID[0];

Posts: 333
Joined: Wed Dec 31, 1969 8:00 pm

Re: Get Categories for JobOrder PHP Script

Post by s.emmons » Mon Apr 29, 2013 9:47 am

Thanks for posting lxjam!
Sam Emmons
Enterprise Team Lead
US Support 617-478-9126

Post Reply