Forum for users and developers of Bullhorn's API service.
Moderators: StaffingSupport, s.emmons, BullhornSupport
-
helloworld
- User
- Posts: 3
- Joined: Thu Nov 17, 2016 12:29 am
Post
by helloworld » Thu Nov 17, 2016 12:52 am
I'm trying to post to the Resume Parser service but keep getting a No file uploaded error. I have a feeling that I'm not properly formatted the post data. Any help will be appreciated.
URL:
../resume/parseToCandidate?BhRestToken=xxx&format=PDF"
PHP Code:
Code: Select all
$postfields = array(
"file" => '@' . $filedata // filedata is the file tmp_name
);
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array( "Content-type: multipart/form-data" ),
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
Error:
Code: Select all
HTTP/1.1 100 Continue
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Max-Age: 86400
Access-Control-Allow-Headers: Content-Type, X-Requested-With, *
Access-Control-Allow-Origin: *
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 17 Nov 2016 04:37:05 GMT
Connection: close
{
"errorCode" : 400,
"errorMessage" : "No File Uploaded!!"
}
-
lokuber
- User
- Posts: 35
- Joined: Wed Jul 20, 2016 5:20 am
Post
by lokuber » Thu Nov 17, 2016 6:01 am
Hello @helloworld
Is $filedata the result of file_get_contents(YOUR_FILE) ?
You should also set this :
Code: Select all
Content-Disposition: form-data
Content-Type: PDF (or DOC, DOCX ...)
Content-Transfer-Encoding: binary
I also add populateDescription=html in my URL
Keep in mind that you may have REX errors and should retry parse from BullHorn
-
helloworld
- User
- Posts: 3
- Joined: Thu Nov 17, 2016 12:29 am
Post
by helloworld » Thu Nov 17, 2016 8:34 pm
Hi @lokuber,
Thanks for your reply!
No $filedata was the 'tmp_name' property of the posted file. I've tried file_get_contents as well as adding the headers you've mentioned, but it's still not working.
Using Postman, I was able to get a valid response by simply posting to the API with default headers.
How are you posting your file to the API?
-
helloworld
- User
- Posts: 3
- Joined: Thu Nov 17, 2016 12:29 am
Post
by helloworld » Thu Nov 17, 2016 8:58 pm
@lokuber I figured it out... The issue was that for PHP5.5+, the function curl_file_create has to be used to post files.
Using the following post fields would work:
Code: Select all
if (function_exists('curl_file_create')) { // php 5.5+
$curl_file = curl_file_create($filetarget); // $filetarget is the real path of the file after it has been uploaded or copied to the server
} else {
$curl_file = '@' . realpath($filetarget);
}
$postfields = array('file_contents'=> $curl_file);
Hope this saves people trouble...
Note that the contents of the file doesn't need to be posted because we are using multipart/form-data uploads.