Submitting Jobs
All tasks in FreeConvert are independent of one another; the flow and order of tasks can be customized as needed. Instead of executing tasks individually as shown in previous sections, the entire conversion workflow can be defined using a single Job.
Tip: You can use API Job Builder to conveniently construct your Job workflows.
Prepare Job Definition
The following job definition includes three tasks:
- Import a jpg file from a specified URL.
- Convert the file to png format.
- Export a download URL.
{
"tag": "conversion",
"tasks": {
"getmyfile": {
"operation": "import/url",
"url": "https://example.com/some.jpg",
"filename": "some.jpg" // optional
},
"convertmyfile": {
"operation": "convert",
"input": "getmyfile",
"output_format": "png",
"options": {
"png_compression_quality": 70
// ...any other advanced options...
}
},
"givemedownloadlink": {
"operation": "export/url",
"input": "convertmyfile",
"filename": "myresult.png"
}
}
}
As shown above, you can define your workflow using named tasks (eg. getmyfile) and refer to those tasks in subsequent tasks. Inside the processing tasks (eg. convertmyfile), you could define advanced options to fine-tune the behaviour of that task.
Submit Job
To execute your workflow, you simply need to submit your job definition to the Job creation endpoint. Upon submission, FreeConvert would automatically execute the workflow specified in the job.
curl -X POST https://api.freeconvert.com/v1/process/jobs \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer {access_token}'
# Body Parameter
{
...
# follow the sample job definition above
}
POST https://api.freeconvert.com/v1/process/jobs HTTP/1.1
Host: api.freeconvert.com
Content-Type: application/json
Accept: application/json
# Body Parameter
{
...
# follow the sample job definition above
}
inputBody = {
...
// follow the sample job definition above
};
const headers = {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${access_token}`,
};
fetch("https://api.freeconvert.com/v1/process/jobs", {
method: "POST",
body: inputBody,
headers: headers,
})
.then(function (res) {
return res.json();
})
.then(function (body) {
console.log(body);
});
import requests
request_body = {
...
# follow the sample job definition above
}
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer' + access_token
}
result = requests.post(
'https://api.freeconvert.com/v1/process/jobs',
data = request_body,
headers = headers
)
print(result.json())
require 'rest-client'
require 'json'
request_body = {
...
# follow the sample job definition above
}
headers = {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer' + access_token
}
result = RestClient.post(
'https://api.freeconvert.com/v1/process/jobs',
body: request_body,
headers: headers
)
JSON.parse(result)
<?php
require 'vendor/autoload.php';
$headers = array(
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer ' $access_token,
);
$client = new \GuzzleHttp\Client();
$request_body = array(
...
// follow the sample job definition above
)
try {
$response = $client->request(
'POST',
'https://api.freeconvert.com/v1/process/jobs',
array(
'headers' => $headers,
'content' => json_encode($request_body),
)
);
print_r($response->getBody()->getContents());
}
catch (\GuzzleHttp\Exception\BadResponseException $e) {
// handle exception or api errors.
print_r($e->getMessage());
}
// ...
URL obj = new URL("https://api.freeconvert.com/v1/process/jobs");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream())
);
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main
import (
"bytes"
"net/http"
)
func main() {
jsonReq := map[string][]string{
...
// follow the sample job definition above
}
headers := map[string][]string{
"Content-Type": string{"application/json"},
"Accept": string{"application/json"},
"Authorization": string{"Bearer" + access_token},
}
data := bytes.NewBuffer([]byte{jsonReq})
req, err := http.NewRequest(
"POST",
"https://api.freeconvert.com/v1/process/jobs",
data
)
req.Header = headers
client := &http.Client{}
resp, err := client.Do(req)
// ...
}