Log In Sign Up

Docs

Code samples

Working code for submitting a website capture job in Ruby, Python, PHP, Node.js, Go, Java, and C#. The same pattern works for /convert.

Every example below submits a POST /jobs request to render https://en.wikipedia.org/wiki/Airplane to PDF at A4 size. The API key is read from a CONVERTERER_API_KEY environment variable. For the file-conversion API (POST /convert), swap the URL and use input + output_format form fields instead of url + page_size.

Ruby (standard library)

require "uri"
require "net/http"

endpoint = URI.parse("https://api.converterer.com/jobs")
http = Net::HTTP.new(endpoint.host, endpoint.port)
http.use_ssl = true

request = Net::HTTP::Post.new(endpoint.request_uri)
request.basic_auth(ENV.fetch("CONVERTERER_API_KEY"), "")
request.set_form_data(
  "url" => "https://en.wikipedia.org/wiki/Airplane",
  "page_size" => "A4"
)

response = http.request(request)
puts response.body

Ruby (HTTP gem)

The HTTP gem is a friendlier API than the standard library:

# gem install http
require "http"

response = HTTP.basic_auth(user: ENV.fetch("CONVERTERER_API_KEY"), pass: "").post(
  "https://api.converterer.com/jobs",
  json: { url: "https://en.wikipedia.org/wiki/Airplane", page_size: "A4" }
)

puts response.body

Python

# pip install requests
import os
import requests

response = requests.post(
    "https://api.converterer.com/jobs",
    auth=(os.environ["CONVERTERER_API_KEY"], ""),
    data={"url": "https://en.wikipedia.org/wiki/Airplane", "page_size": "A4"},
)

print(response.json())

PHP

<?php
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => 'https://api.converterer.com/jobs',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => [
        'url' => 'https://en.wikipedia.org/wiki/Airplane',
        'page_size' => 'A4',
    ],
    CURLOPT_USERPWD => getenv('CONVERTERER_API_KEY') . ':',
]);

$response = curl_exec($curl);
curl_close($curl);

echo $response;

Node.js (native fetch, Node 18+)

const auth = 'Basic ' + Buffer
  .from(process.env.CONVERTERER_API_KEY + ':')
  .toString('base64');

const response = await fetch('https://api.converterer.com/jobs', {
  method: 'POST',
  headers: {
    Authorization: auth,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://en.wikipedia.org/wiki/Airplane',
    page_size: 'A4',
  }),
});

console.log(await response.json());

Go

package main

import (
    "fmt"
    "io"
    "log"
    "net/http"
    "net/url"
    "os"
    "strings"
)

func main() {
    apiKey := os.Getenv("CONVERTERER_API_KEY")
    endpoint := "https://api.converterer.com/jobs"
    formData := url.Values{
        "url":       {"https://en.wikipedia.org/wiki/Airplane"},
        "page_size": {"A4"},
    }.Encode()

    req, err := http.NewRequest("POST", endpoint, strings.NewReader(formData))
    if err != nil {
        log.Fatal(err)
    }
    req.SetBasicAuth(apiKey, "")
    req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        log.Fatal(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Java (Apache HttpComponents)

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class CreateJob {
    public static void main(String[] args) throws Exception {
        String apiKey = System.getenv("CONVERTERER_API_KEY");
        byte[] authEncoded = Base64.encodeBase64((apiKey + ":").getBytes(StandardCharsets.ISO_8859_1));
        String authHeader = "Basic " + new String(authEncoded);

        HttpPost request = new HttpPost("https://api.converterer.com/jobs");
        request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);

        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("url", "https://en.wikipedia.org/wiki/Airplane"));
        params.add(new BasicNameValuePair("page_size", "A4"));
        request.setEntity(new UrlEncodedFormEntity(params));

        HttpClient httpClient = HttpClientBuilder.create().build();
        HttpResponse response = httpClient.execute(request);
        HttpEntity entity = response.getEntity();
        System.out.println(response.getStatusLine().getStatusCode());
        System.out.println(EntityUtils.toString(entity, "UTF-8"));
    }
}

C# (.NET)

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;

class CreateJob
{
    static async Task Main()
    {
        string apiKey = Environment.GetEnvironmentVariable("CONVERTERER_API_KEY");
        var auth = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(apiKey + ":"));

        var http = new HttpClient { BaseAddress = new Uri("https://api.converterer.com") };
        http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);

        var body = JsonSerializer.Serialize(new {
            url = "https://en.wikipedia.org/wiki/Airplane",
            page_size = "A4",
        });

        var request = new HttpRequestMessage(HttpMethod.Post, "/jobs") {
            Content = new StringContent(body, System.Text.Encoding.UTF8, "application/json"),
        };

        var response = await http.SendAsync(request);
        Console.WriteLine(response.StatusCode);
        Console.WriteLine(await response.Content.ReadAsStringAsync());
    }
}

Don’t see your language?

Any HTTP client in any language works. The pattern is always the same:

  1. Build a POST request to https://api.converterer.com/jobs (or /convert).
  2. Set Authorization: Basic <base64(api_key:)>.
  3. Send url + any other parameters as form-encoded or JSON.
  4. Parse the JSON response for the job id.

If you want a snippet added for a specific language, get in touch.