cloudconvert

API CloudConvert curl request PHP


I would like to test a very simple case with the API CloudConvert with a curl request. I want to import the file essaiFichier.txt with a curl request. I get a response in Json with a status "waiting". I have no idea if the request was well done. If someone has faced the same problem it would be great to have some Below my code in order to fix the issue.

$authorization ="Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOi";
$url ="https://api.cloudconvert.com/v2/jobs";
$post = '{
    "tasks": {
        "import-1": {
            "operation": "import/url",
            "url": "http://localhost/biere/essaiFichier.txt",
            "filename": "essaiFichier.txt"
       }
    }
}';

$ch=curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$info = curl_getinfo($ch);

Solution

  • I'm also new to cloudconvert, though it looks to me like you aren't following the 'rules' for using the service - at least, not to get anything useful out of it....

    You need to do THREE things (at least):

    1. Import (you have that)
    2. Task (like 'convert'...)
    3. Export (get your modified file back)

    I find their 'Job Builder' to be a simple way to get the code - at least for starting out. See https://cloudconvert.com/api/v2/jobs/builder

    I entered your 'Import' into the 'Job Builder' (note - I think you don't need the 'filename' in there, or you should break apart the 'url' and only have the file named in the 'filename' section - again, I'm new at it, but that is how I read it) and it still shows me this in the blue box at the top (the 'hints')

    How to build a job

    Add a processing task, for example a convert task.

    Add an export task. You can use the export/url task to generate a URL for the output file.

    Which tells me you just need to do the other parts so you have a complete request.

    As for the 'waiting' response, yes, that is what you will get on the initial request. Again, see the docs on the Job Builder page - you can either do another request for the 'wait' response (which should get you the link for the 'export' part) or you can do a webhook that will be your trigger to download the file (which would make things more automatic).

    Following your code and the Job Builder, I just finished my first conversion - worked great and now I can move on with my project (yeah!)