Skip to main content
Participating Frequently
July 15, 2022
Question

Call API using PHP cURL. What's wrong with my code?

  • July 15, 2022
  • 1 reply
  • 889 views
I have been trying to create a php function to call PDF extract API. I always got the following error:
{"requestId":"IEt94LRYdvDw4Xd9rzzcTqYt4dwWa1Sc","type":"Bad Request","title":"Not a multipart request. Aborting.","status":400,"report":"{\"error_code\":\"INVALID_MULTIPART_REQUEST\"}"}
 
My code is below:
$cfile = curl_file_create($pdf_file);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://cpf-ue1.adobe.io/ops/:create");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("fileInput1"=>$cfile,"contentAnalyzerRequests"=>"{ \"cpf:engine\": { \"repo:assetId\": \"urn:aaid:cpf:58af6e2c-1f0c-400d-9188-078000185695\" }, \"cpf:inputs\": { \"documentIn\": { \"cpf:location\": \"fileInput1\", \"dc:format\": \"application/pdf\" }, \"params\": { \"cpf:inline\": { \"elementsToExtract\": [ \"text\", \"tables\" ], \"renditionsToExtract\": [ \"tables\", \"figures\"] } } }, \"cpf:outputs\": { \"elementsInfo\": { \"cpf:location\": \"jsonoutput\", \"dc:format\": \"application/json\" }, \"elementsRenditions\": { \"cpf:location\": \"fileoutpart\", \"dc:format\": \"text/directory\" } } }"));
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Accept: application/json, text/plain";
$headers[] = "Authorization: Bearer $token";
$headers[] = "x-api-key: $client_id";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
 
Can anybody help me? Thanks!
    This topic has been closed for replies.

    1 reply

    Kyle Julé24692827
    Adobe Employee
    Adobe Employee
    July 18, 2022

    The error code seems to suggest you are failing to create a multi-part request. I would recommed not re-inventing the wheel and simply using one of our SDKs -- we support multiple languages (not PHP, however). Some of the endpoints are a little involved, and in general we've created the SDKs to make your life easier.

    https://developer.adobe.com/document-services/docs/overview/pdf-services-api/#sdk

     

    ilshAuthor
    Participating Frequently
    July 22, 2022

    Thank you! Do you have any plans to make an SDK in PHP?