API Basics – REST API

To get started, the owner of an account must first generate a new API key from the website.
Settings > Account > API Key

Libib rate limits requests to the API. Currently you may hit the API once every 2 seconds.

In the basic sample code below, you would replace YOUR_API_KEY and YOUR_API_USER with the generated user id and API key from your account.

All sample code will be in PHP.

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.libib.com",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_CONNECTTIMEOUT => 5,
  CURLOPT_TIMEOUT => 15,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "x-api-key: YOUR_API_KEY",
    "x-api-user: YOUR_API_USER"
  ),
));

$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  // Valid responses are always in JSON, so we convert to an object here.
  $obj = json_decode($response);
}

The code above doesn’t do very much, but it will allow you to test the connection and confirm access.

Was this article helpful?

Related Articles