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

Explorer ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

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!

Views

52

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources