Quickstart
In order to create a simple conversion of a file located at an external URL, the following request is made.
POST /v2/jobs HTTP/1.1
Host: https://api.api2convert.com
X-Oc-Api-Key: <your API key here>
Content-Type: application/json
{
"input": [{
"type": "remote",
"source": "https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg"
}],
"conversion": [{
"target": "png"
}]
}
curl -X POST \
https://api.api2convert.com/v2/jobs \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'x-oc-api-key: <your API key here>' \
-d '{
"input": [{
"type": "remote",
"source": "https://example-files.online-convert.com/raster%20image/png/example_small.png"
}],
"conversion": [{
"category": "image",
"target": "png"
}],
"callback": "https://my.domain.test/apiCallback"
}'
<?php
$endpoint = 'https://api.api2convert.com/v2/jobs';
$apikey = '<your API key here>';
$debug = TRUE;
$json_resquest = '{
"input": [{
"type": "remote",
"source": "https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg"
}],
"conversion": [{
"target": "png"
}]
}';
// No need to change parameters below this line.
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_resquest);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Oc-Api-Key: '.$apikey,
'Content-Type: application/json',
'cache-control: no-cache'
));
if ($debug) {
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
}
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$error = curl_error($ch);
curl_close($ch);
if ($debug) {
var_dump($info);
}
echo $response."\n";
if (!empty($error)) {
echo $error;
}
?>
require 'uri'
require 'net/http'
url = URI("https://api.api2convert.com/v2/jobs")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["x-oc-api-key"] = '<your API key here>'
request["content-type"] = 'application/json'
request["cache-control"] = 'no-cache'
request.body = "{\"input\":[{\"type\":\"remote\",\"source\":\"https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg\"}],\"conversion\":[{\"category\":\"image\",\"target\":\"png\"}]}"
response = http.request(request)
puts response.read_body
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"input\":[{\"type\":\"remote\",\"source\":\"https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg\"}],\"conversion\":[{\"category\":\"image\",\"target\":\"png\"}]}");
Request request = new Request.Builder()
.url("https://api.api2convert.com/v2/jobs")
.post(body)
.addHeader("x-oc-api-key", "<your API key here>")
.addHeader("cache-control", "no-cache")
.build();
Response response = client.newCall(request).execute();
import requests
url = "https://api.api2convert.com/v2/jobs"
payload = "{\"input\":[{\"type\":\"remote\",\"source\":\"https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg\"}],\"conversion\":[{\"category\":\"image\",\"target\":\"png\"}]}"
headers = {
'x-oc-api-key': "<your API key here>",
'content-type': "application/json",
'cache-control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
var client = new RestClient("https://api.api2convert.com/v2/jobs");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("x-oc-api-key", "<your API key here>");
request.AddParameter("application/json", "{\"input\":[{\"type\":\"remote\",\"source\":\"https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg\"}],\"conversion\":[{\"category\":\"image\",\"target\":\"png\"}]}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
var http = require("http");
var options = {
"method": "POST",
"hostname": "api.api2convert.com",
"port": null,
"path": "/v2/jobs",
"headers": {
"x-oc-api-key": "<your API key here>",
"content-type": "application/json",
"cache-control": "no-cache"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write(JSON.stringify({ input: [ { type: 'remote', source: 'https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg' } ],
conversion: [ { category: 'image', target: 'png' } ] }));
req.end();
var data = JSON.stringify({
"input": [
{
"type": "remote",
"source": "https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg"
}
],
"conversion": [
{
"category": "image",
"target": "png"
}
]
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://api.api2convert.com/v2/jobs");
xhr.setRequestHeader("x-oc-api-key", "<your API key here>");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(data);
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.api2convert.com/v2/jobs");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "cache-control: no-cache");
headers = curl_slist_append(headers, "content-type: application/json");
headers = curl_slist_append(headers, "x-oc-api-key: <your API key here>");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"input\":[{\"type\":\"remote\",\"source\":\"https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg\"}],\"conversion\":[{\"category\":\"image\",\"target\":\"png\"}]}");
CURLcode ret = curl_easy_perform(hnd);
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.api2convert.com/v2/jobs"
payload := strings.NewReader("{\"input\":[{\"type\":\"remote\",\"source\":\"https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg\"}],\"conversion\":[{\"category\":\"image\",\"target\":\"png\"}]}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-oc-api-key", "<your API key here>")
req.Header.Add("content-type", "application/json")
req.Header.Add("cache-control", "no-cache")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
import Foundation
let headers = [
"x-oc-api-key": "<your API key here>",
"content-type": "application/json",
"cache-control": "no-cache"
]
let parameters = [
"input": [
[
"type": "remote",
"source": "https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg"
]
],
"conversion": [
[
"category": "image",
"target": "png"
]
]
]
let postData = NSJSONSerialization.dataWithJSONObject(parameters, options: nil, error: nil)
var request = NSMutableURLRequest(URL: NSURL(string: "https://api.api2convert.com/v2/jobs")!,
cachePolicy: .UseProtocolCachePolicy,
timeoutInterval: 10.0)
request.HTTPMethod = "POST"
request.allHTTPHeaderFields = headers
request.HTTPBody = postData
let session = NSURLSession.sharedSession()
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
println(error)
} else {
let httpResponse = response as? NSHTTPURLResponse
println(httpResponse)
}
})
dataTask.resume()
The only required elements to start the conversion are input and conversion. Take into account that both input and conversion field are an array of objects.
The API will respond with a 201 status code and the content of the newly created job. The information missing in the request will be populated with default values.
{
"id": "407c9fcd-1b36-11e5-8f2b-002590da1f50",
"token": "52b099c5d8e127278280873343add213",
"type": "job",
"status": {
"code": "completed",
"info": "The file has been successfully converted."
},
"process": true,
"conversion": [{
"id": "407ced1d-1b36-11e5-8f2b-002590da1f50",
"category": "image",
"target": "png",
"options": []
}],
"input": [{
"id": "407cd2df-1b36-11e5-8f2b-002590da1f50",
"type": "remote",
"source": "https://example-files.online-convert.com/raster%20image/jpg/example_small.jpg",
"filename": "example_small.jpg",
"size": 0,
"created_at": "2017-03-25T14:32:32",
"modified_at": "2017-03-25T14:32:32"
}],
"output": [{
"id": "142de18d-1a4b-11e5-8f2b-002590da1f50",
"source": {
"conversion": "407ced1d-1b36-11e5-8f2b-002590da1f50",
"input": [
"407cd2df-1b36-11e5-8f2b-002590da1f50"
]
},
"uri": "https://www30.api2convert.com/v2/dl/web1/download-file/142de18d-1a4b-11e5-8f2b-002590da1f50/example_small.png",
"size": 364,
"created_at": "2017-03-25T14:33:06",
"status": "enabled",
"content_type": "image/png",
"downloads_counter": 0,
"checksum": "d77971e8628bd71013f37866783d7942"
}],
"callback": "",
"server": "https://www7.api2convert.com/v2/dl/web1",
"created_at": "2017-03-25T14:32:32",
"modified_at": "2017-03-25T14:32:32"
}
To obtain the download link of the converted file, you can also have a look at Download the converted file.
A detailed Howto has been written to show you step by step on how you can convert a file using the API.