Getting Started

Authentication

The Kapost API requires the use of a user account. On your edit profile page in Kapost, there is an API Token section that contains the authentication token credential you need to authenticate when using the API. All actions taken by the API will appear to originate from this user account.

The Kapost API utilizes HTTP Basic Authentication. Using standard basic auth scheme, put the token string into the username field and "x" (or any value) for the password field. The password field is ignored.

URL Structure

https://your_instance.kapost.com/api/version/resource

  • SSL is required
  • API Version is the first part of the path

Response Format

All responses are in the json format.

Example

$ curl -u "token:x" "https://your_instance.kapost.com/api/version/resource"

Java Example

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class KapostApiExample
{
    public static void main(String[] args) throws Exception
    {
        HttpHost target = new HttpHost("your_instance.kapost.com", 443, "https");
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
            new AuthScope(target.getHostName(), target.getPort()),
            new UsernamePasswordCredentials("token", "x")
        );

        CloseableHttpClient httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider).build();

        AuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(target, basicAuth);

        HttpClientContext localContext = HttpClientContext.create();
        localContext.setAuthCache(authCache);

        try
        {
            HttpGet httpget = new HttpGet("https://your_instance.kapost.com/api/v1/content");
            httpget.addHeader("User-Agent", "Kapost Api Example Java");

            CloseableHttpResponse response = httpclient.execute(target, httpget, localContext);

            try
            {
                System.out.println(response.getStatusLine());
                System.out.println(EntityUtils.toString(response.getEntity()));
            }
            finally
            {
                response.close();
            }
        }
        finally
        {
            httpclient.close();
        }
    }
}