Discussions
Cant pass applicant data + applicant documents
Hello,
since the Personio API changed last year, we are not able to pass the applicant documents and applicant information to Personio. We are working with PHP and cURL.
From the documentation, we gather that we need to first transfer the attached documents to Personio and then link the applicant information using the UUIDs of the documents. In the old API, we were able to transmit everything collectively as multipart. Here is our current code:
add_action('gform_after_submission', function ($entry, $form) {
// Extraktion der Formularfelder
$jobId = rgar($entry, '1');
$firstName = rgar($entry, '2');
$lastName = rgar($entry, '8');
$phone = rgar($entry, '3');
$email = rgar($entry, '4');
$text = rgar($entry, '5');
$gender = rgar($entry, '9');
$salary = rgar($entry, '11');
$birthday = rgar($entry, '12');
$availableFrom = rgar($entry, '10');
$files = json_decode(rgar($entry, '7'), true);
// Formatieren der Daten
$birthday = date('Y-m-d', strtotime($birthday));
$availableFrom = date('Y-m-d', strtotime($availableFrom));
// Array für die UUIDs der hochgeladenen Dateien
$fileUuids = [];
foreach ($files as $file) {
$uploadedFilePath = str_replace(site_url(), $_SERVER['DOCUMENT_ROOT'], $file);
$uploadResponse = uploadFileToPersonio($uploadedFilePath);
if (empty($uploadResponse['uuid'])) {
// Fehlerbehandlung für Datei-Upload
sendErrorEmail('Fehler beim Dateiupload', $uploadResponse);
} else {
$fileUuids[] = $uploadResponse['uuid'];
}
}
// Vorbereiten und Senden der Bewerberdaten
$applicantData = [
'phase' => [
'type' => 'custom',
'id' => '316302'
],
'job_position_id' => $jobId,
'first_name' => $firstName,
'last_name' => $lastName,
'phone' => $phone,
'email' => $email,
'gender' => $gender,
'salary_expectations' => $salary,
'birthday' => $birthday,
'available_from' => $availableFrom,
'message' => $text,
'files' => $fileUuids
];
$applicantResponse = sendApplicantToPersonio($applicantData);
if (!$applicantResponse) {
// Fehlerbehandlung für die Übermittlung der Bewerberdaten
sendErrorEmail('Fehler bei der Übermittlung der Bewerberdaten', $applicantResponse);
}
}, 10, 2);
function uploadFileToPersonio($filePath) {
$boundary = uniqid();
$filename = basename($filePath);
$payload = "--$boundary\\r\\n";
$payload .= "Content-Disposition: form-data; name=\"file\"; filename=\"$filename\"\\r\\n";
$payload .= "Content-Type: application/pdf\\r\\n\\r\\n";
$payload .= file_get_contents($filePath);
$payload .= "\\r\\n--$boundary--\\r\\n";
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.personio.de/v1/recruiting/applications/documents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
"X-Company-ID: *sanitized*",
"Authorization: Bearer *sanitized*",
"Content-Type: multipart/form-data; boundary=$boundary"
],
]);
$response = curl_exec($curl);
curl_close($curl);
return json_decode($response, true);
}
function sendApplicantToPersonio($data) {
$curl = curl_init();
curl_setopt_array($curl, \[
CURLOPT_URL => "<https://api.personio.de/v1/recruiting/applications">,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
"X-Company-ID: *sanitized*",
"Authorization: Bearer *sanitized*",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
curl_close($curl);
return json_decode($response, true);
}
function sendErrorEmail($subject, $message) {
$to = '*sanitzied*';
$headers = 'From: *sanitized*' . "\\r\\n" .
'Reply-To: *sanitized*' . "\\r\\n";
mail($to, $subject, print_r($message, true), $headers);
}
Additional information:
We are collecting the data via a Gravity Forms Form on one of our WordPress websites.
If we skip the document upload, there are still some applicant information missing such as "available from"
The error handling function worked well but since the newest code, we don't even get an error response.
Thank you so much for your help.
Kind regards
Pascal