Send a job with remote file

In order to create a simple conversion of a file located on an external URL, the following request is made.

POST /jobs HTTP/1.1
Host: https://api2.online-convert.com
X-Oc-Api-Key: <your API key here>
Content-Type: application/json
{
    "input": [{
        "type": "remote",
        "source": "http://static.online-convert.com/example-file/raster%20image/jpg/example_small.jpg"
    }],
    "conversion": [{
        "target": "png"
    }]
}
curl -X POST \
    https://api2.online-convert.com/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": "http://cdn.online-convert.com/example-file/raster%20image/png/example_small.png"
           }],
           "conversion": [{
               "category": "image",
               "target": "png"
           }],
           "callback": "http://my.domain.test/apiCallback"
       }'
<?php
    $endpoint = 'https://api2.online-convert.com/jobs';
    $apikey = '<your API key here>';
    $debug = TRUE;

    $json_resquest = '{
        "input": [{
            "type": "remote",
            "source": "http://static.online-convert.com/example-file/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("http://api2.online-convert.com/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\":\"http://static.online-convert.com/example-file/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\":\"http://static.online-convert.com/example-file/raster%20image/jpg/example_small.jpg\"}],\"conversion\":[{\"category\":\"image\",\"target\":\"png\"}]}");
Request request = new Request.Builder()
    .url("http://api2.online-convert.com/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 = "http://api2.online-convert.com/jobs"

payload = "{\"input\":[{\"type\":\"remote\",\"source\":\"http://static.online-convert.com/example-file/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("http://api2.online-convert.com/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\":\"http://static.online-convert.com/example-file/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": "api2.online-convert.com",
    "port": null,
    "path": "/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: 'http://static.online-convert.com/example-file/raster%20image/jpg/example_small.jpg' } ],
conversion: [ { category: 'image', target: 'png' } ] }));
req.end();
var data = JSON.stringify({
    "input": [
        {
            "type": "remote",
            "source": "http://static.online-convert.com/example-file/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", "http://api2.online-convert.com/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, "http://api2.online-convert.com/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\":\"http://static.online-convert.com/example-file/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 := "http://api2.online-convert.com/jobs"

    payload := strings.NewReader("{\"input\":[{\"type\":\"remote\",\"source\":\"http://static.online-convert.com/example-file/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": "http://static.online-convert.com/example-file/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: "http://api2.online-convert.com/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()

This request will return a response similar to this one:

{
    "id": "xxxxxxx-027b-483e-bac9-9311fe4764b9",
    "token": "xxxxxxxee5a986b35b96c78f60eab8c2",
    "type": "job",
    "status": {
        "code": "downloading",
        "info": "The file is currently downloading from the source URL."
    },
    "errors": [],
    "process": true,
    "conversion": [
        {
            ... information about conversion ...
        }
    ],
    "input": [
        {
            ... information about the input ...
        }
    ],
    "output": [],
    "callback": "",
    "notify_status": false,
    "server": "https://www27.online-convert.com/dl/web2",
    "spent": 0,
    "created_at": "2017-08-15T17:20:55",
    "modified_at": "2017-08-15T17:20:55"
}

results matching ""

    No results matching ""