Validation error bad request using PHP/curl
I want to use the Acrobat Services API to extract text from a pdf.
First 2 steps works fine, but I get error in step 3, extract from pdf.
{"reason":"Validation error Request id: G7ueJEPebxWy6evaToK3LHrih1hyymVC.","message":"Bad Request"}
Have used Postman sample in SDK and Postman php curl code.
The code is on a commercial web site running FreeBSD.
$client_id and $client_secret is set directly before this code.
File apitest.txt follws after code. Any suggestions?
// Step 1 - Get token - from Postman
$fp = fopen("apitest.txt", "w");
$curl = curl_init();
$postfield = "client_id=".$client_id."&client_secret=".$client_secret;
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://pdf-services.adobe.io/token',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_HEADER => FALSE,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $postfield,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded'
),
));
$response1 = curl_exec($curl);
fwrite($fp, "Postfield:\n".$postfield);
fwrite($fp, "\nResponse1:\n".$response1);
if(curl_error($curl)) fwrite($fp, "\ncurl error:".curl_error($curl)."\n");
curl_close($curl);
$result = explode("\"", $response1);
$token = $result[3];
// Step 2a - Upload Presigned Uri - from Postman
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://pdf-services.adobe.io/assets',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"mediaType":"application/pdf"
}',
CURLOPT_HTTPHEADER => array(
'X-API-Key:'.$client_id,
'Authorization: Bearer '.$token,
'Content-Type: application/json'
),
));
$response2a = curl_exec($curl);
fwrite($fp, "\nResponse2a:\n".$response2a);
if(curl_error($curl)) fwrite($fp, "\ncurl error:".curl_error($curl)."\n");
curl_close($curl);
$result = explode("\"", $response2a);
$uploadUri = $result[3];
$assetID = $result[7];
// Step 2b - Upload Document - from Postman
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $uploadUri,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => file_get_contents("Vattenfall.pdf"),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/pdf'
),
));
$response2b = curl_exec($curl);
fwrite($fp, "\nResponse2b:\n".$response2b);
if(curl_error($curl)) fwrite($fp, "\ncurl error:".curl_error($curl)."\n");
curl_close($curl);
// Step 3 - Extract PDF - from Postman
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://pdf-services.adobe.io/operation/extractpdf/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"assetID": $assetID,
"getCharBounds": "false",
"includeStyling": "false",
"elementsToExtract": [
"text",
"tables"
],
"tableOutputFormat": "xlsx",
"renditionsToExtract": [
"tables",
"figures"
]
}',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$token,
'x-api-key: '.$client_id,
'Content-Type: application/json'
),
));
$response3 = curl_exec($curl);
fwrite($fp, "\nResponse3:\n".$response3);
if(curl_error($curl)) fwrite($fp, "\ncurl error:".curl_error($curl)."\n");
curl_close($curl);
Response1:
{"access_token":"eyJhbGciOiJSUzI1NiIsIng1dSI6Imltc19uYTEta2V5LWF0LTEuY2VyIiwia2lkIjoiaW1zX25hMS1rZXktYXQtMSIsIml0dCI6ImF0In0.eyJpZCI6IjE3MzY5Njc2MDQ1NzNfN2ZjZTY1NWUtNzU1OC00MWFkLTliNzEtYzE1YzU1YzQxZGQxX3VlMSIsIm9yZyI6IjYwMTcxRUQ4Njc4MjU4Q0IwQTQ5NUZCREBBZG9iZU9yZyIsInR5cGUiOiJhY2Nlc3NfdG9rZW4iLCJjbGllbnRfaWQiOiIyZjQzYjljNmEzYjM0YzkwYjBmZDNlYmRlZmRiYzI1NiIsInVzZXJfaWQiOiI2MTk2MUY1RTY3ODI1QjUyMEE0OTVGRDZAdGVjaGFjY3QuYWRvYmUuY29tIiwiYXMiOiJpbXMtbmExIiwiYWFfaWQiOiI2MTk2MUY1RTY3ODI1QjUyMEE0OTVGRDZAdGVjaGFjY3QuYWRvYmUuY29tIiwiY3RwIjozLCJtb2kiOiJhZTc3MmJiIiwiZXhwaXJlc19pbiI6Ijg2NDAwMDAwIiwic2NvcGUiOiJEQ0FQSSxvcGVuaWQsQWRvYmVJRCIsImNyZWF0ZWRfYXQiOiIxNzM2OTY3NjA0NTczIn0.Gzei15AUQV3srIC5v-qgm_qtM3QMka6OoqFK32lAgxsqMPSj-u2aGXNfqSL4LnynNqxE7djszP0gfSArC-Q5diZ-dyJ74UIMJwgmwi2GPBi0nrF0IR0xHAjaDiaH8SYhYqssW4VpZTKul0NDQBPUCmgye63j0eCNQkEghM_MbsZbqkuClMPJ_xMuH9RdBJPCEzenUGeANfc3e18MnD8zUAIn4b-rUAw6jCHK8f-7OvlOMe8ZZbNGnp6LFzXJua8nJ7sKT9lE09YNabjmXrTTb0NRliLzTTR0g583R6BKiTM_IfZIsHXMll8kL1O3dEIEh4twZoymxMfnbtwgk_JzAQ","token_type":"bearer","expires_in":86399}
Response2a:
{"uploadUri":"https://dcplatformstorageservice-prod-us-east-1.s3-accelerate.amazonaws.com/2f43b9c6a3b34c90b0fd3ebdefdbc256_61961F5E67825B520A495FD6%40techacct.adobe.com/71d59918-c6ec-40fa-89e6-20158ed30e3e?X-Amz-Security-Token=IQoJb3JpZ2luX2VjEDoaCXVzLWVhc3QtMSJGMEQCIGNSaJE%2BKxM%2BCMZ92tbSLbgPXfVpn2iqknBSEFnSN08qAiBs4Shm6cW5ABmbarMvhZhTApl%2Fe3vwrlaUfQE9zDWqHyqYBQgzEAAaDDQyMDUzMzQ0NTk4MiIMCGGG%2FnZscmnm0NmcKvUEZ5dGtP6VKCpIg0rwBIREgZEdFwazvEirG3T%2BiJVzhoK7eQxj5DiaAdAIivh%2FktbV9uxatcO0JEEOWAbdX48rwKoa0ItP%2FvxsxfYr4fh0eOHwwnn9qc%2B4M4LYyo5gANT%2FUZ6K6L1WXIHPzeiwEavEQuOxlpZHWhR8l%2BYGaAf6Bab%2BgthbVwV46bjOfKVEWIJ%2FWgoaEJpU6PDt2pMHoYoo9V%2Fe4pMGVck8ZnBvjqiI5NW9iXpAa3VrNGcQmPnVro2Kf9K6mHvPFL1KjIG8UX1cUuCJLhhH9%2F%2BsiznQnhInfW1nr2wOflPpN8rSK%2Be8KS1Y8VRQLjzfJuEhMWdWxr7ZRH5o9Z6AwExWfkN%2Fe8Oly%2FBKLf1HaRW2f7Udux5RvxhvFXjcC2XAnnYSumNfbc6YxS8LrzcvDfu5xxPgyTi3Gq2A943fGNRzGNLMe9k1kCwoja7WSWrg2s97xiPoRn2U4oF9uCT4UFJPHDSkUsbe3g56PpdluuNlB9s%2FTTrLFZAy0C%2BZJ478iYGu098RgIjwpmhRv48U7osdvXViozQFpipbuXSLJOiJKUkcuREBDVTGxhyT670Rwf%2FaH4mYl4tOVVTAda4b9I52iRcU%2F9mhsDTQHRs0nrhlUsoxyOjFwASFf1sbZZpuxrL9CnIt3EeThJ2cpFRqU0Mzkx3QULmo3%2B%2FmaNQj2HXTJksj7oOiHzjo65N8zqRctycomoA2s4UTPGCXLQsNLfcvQwVYs8b90b84mk7%2Bbgk%2F3pFwTDfg8zuojawRocNJKfF8DBwLaKvKna9w18yZLhu%2BY0dWzl0Pqci82H%2B8qmsZFoPFPYjy1kjcKFxAtjMw8eOfvAY6nAFPM28F5inip2dm4TOtVjsx%2BSfQk4KGsUmCWA8wPdXE711ny2IaaI%2Bn%2BfUyuji1dBA8vj6PpB5%2BKILAxMmW4mEgN8kWkrtcBLErdhd2uCl2J%2BOWSw3s%2BPu7D%2BYONO3qJS%2F5korTXUnwBLmU7PWm2fzHjSWQe3xs9sIusomrNxRYDHRxUebHiWBoyqZiqgNse2Ti1rTrYfA43GPzmoA%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20250115T190004Z&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Expires=3600&X-Amz-Credential=ASIAWD2N7EVPLC3VZLL2%2F20250115%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=c9dfd723893bb5e1400f17aaa5e46d7491d6a7a63e91de1591d0a5acfd1b29af","assetID":"urn:aaid:AS:UE1:336eafed-1087-4224-936c-7305570bd6f1"}
Response2b:
Response3:
{"reason":"Validation error Request id: G7ueJEPebxWy6evaToK3LHrih1hyymVC.","message":"Bad Request"}
