Convert File
In this example, an imported file is converted from jpg to png. The import task ID must be provided as the input so that FreeConvert uses the correct imported file for the conversion.
You can retrieve the possible conversion formats for an operation from the following API endpoint: GET /query/view/options
See Tasks > List Operations in the left menu for the parameters and usage of this endpoint.
Most file conversions support advanced options that allow you to control the output file. The available advanced options for a specific input and output combination, including hints, can be retrieved from the advanced options endpoint.
curl -X POST https://api.freeconvert.com/v1/process/convert \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer {access_token}'
# Body Parameter
{
"input": "import_task_id",
"input_format": "jpg",
"output_format": "png",
"options": {
# …advanced options…
},
}
POST https://api.freeconvert.com/v1/process/convert HTTP/1.1
Host: api.freeconvert.com
Content-Type: application/json
Accept: application/json
# Body Parameter
{
"input": "import_task_id",
"input_format": "jpg",
"output_format": "png",
"options": {
<!-- …advanced options… -->
},
}
const inputBody = {
input: import_task_id,
input_format: "jpg",
output_format: "png",
options: {
// …advanced options…
},
};
const headers = {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${access_token}`,
};
fetch("https://api.freeconvert.com/v1/process/convert", {
method: "POST",
body: inputBody,
headers: headers,
})
.then(function (res) {
return res.json();
})
.then(function (body) {
console.log(body);
});
import requests
request_body = {
'input': import_task_id,
'input_format': 'jpg',
'output_format': 'png',
'options': {
# …advanced options…
}
}
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer' + access_token
}
result = requests.post(
'https://api.freeconvert.com/v1/process/convert',
data = request_body,
headers = headers
)
print(result.json())
require 'rest-client'
require 'json'
request_body = {
'input' => import_task_id,
'input_format' => 'jpg',
'output_format' => 'png',
'options': {
# …advanced options…
}
}
headers = {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer' + access_token
}
result = RestClient.post(
'https://api.freeconvert.com/v1/process/convert',
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(
'input' => import_task_id,
'input_format' => 'jpg',
'output_format' => 'png',
'options' => {
// …advanced options…
},
)
try {
$response = $client->request(
'POST',
'https://api.freeconvert.com/v1/process/convert',
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/convert");
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{
"input": string{import_task_id},
"input_format": string{"jpg"},
"output_format": string{"png"},
"options": map[string[]]string{
// …advanced options…
}
}
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/convert",
data
)
req.Header = headers
client := &http.Client{}
resp, err := client.Do(req)
// ...
}