Discussions
PHP Guzzle application document upload results in Error 400: "Invalid multipart request body and/or headers supplied"
Here is my implementation of an upload of a document:
$client = new \GuzzleHttp\Client(); // guzzlehttp/guzzle 7.5.0
$oResponse = $client->request('POST', 'https://api.personio.de/v1/recruiting/applications/documents', [
'multipart' => [
[
'name' => 'file',
'contents' => fopen($oUploadedFile->tempName, 'r'),
'filename' => $oUploadedFile->name,
'headers' => ['Content-Type' => $oUploadedFile->type]
]
],
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'multipart/form-data',
'X-Personio-App-ID' => self::APPLICATION_ID,
'X-Company-Id' => self::COMPANY_ID,
'Authorization' => 'Bearer ' . self::ACCESS_TOKEN
]
]);
I get an error "400 Bad Request" with the message "Invalid multipart request body and/or headers supplied". What is wrong?
Your PHP guzzle example misses the "multipart" part.