phpcloudconvert

CloudConvert API v2 The tasks field is required


I'm trying to set up the CUI, but when I try to send a request, I get a code error

Uncaught CloudConvert\Exceptions\HttpClientException: tasks: The tasks field is required

I need to send a file for conversion from my computer and receive html in response. Where is my error? Thank you in advance!

$job = (new Job())
   ->addTask(
       (new Task('import/upload', 'import-my-file'))
       ->set('file', fopen($DocumentPath, 'r'))
     )
   ->addTask(
       (new Task('convert', 'convert-doc-to-html'))
         ->set('input_format', 'doc')
         ->set('output_format', 'html')
         ->set('engine', 'office')
         ->set('input', ["import-my-file"])
     )
   ->addTask(
       (new Task('export/url', 'export-my-file'))
         ->set('input', ["convert-doc-to-html"])
         ->set('inline', false)
         ->set('archive_multiple_files', false)
     ); 
     
$cloudconvert->jobs()->create($job);
$uploadTask = $job->getTasks()->whereName('import-my-file')[0];

$cloudconvert->tasks()->upload($uploadTask, fopen($DocumentPath, 'r'), 'myfile.doc');

Solution

  • I had the same issue and it turned out it was the file I opened, I had to do the following for it to work:

    $file = rtrim(file_get_contents($file, FILE_TEXT)); $file = mb_convert_encoding($file, 'UTF-8', mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true));

    and then put $file in to ->set('file', $file)

    You can see, what I found out here: cloundconvert api v2 in php return The tasks field is required