In order to make API calls, you need to set up an API Key for your database and an API Endpoint for the table you want to write to or read from. Check the Quick start guide for instructions on how to do so.

Composing your API call

Given an API Key and an API Endpoint, this is how you can compose a valid API call.

Headers

You will need to pass your API Key within an auth header, and set your Content-Type to application/vnd.hibase.v1+json.api:

  {
    "Content-Type": "application/vnd.hibase.v1+json.api",
    "auth": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOm51bGwsInN1YiI6Imk3eGg3WnMzdjVGYmtrd5N2OFKpWkNDVVExdHhnU02RIiwic3ViZG9tYWluIjoiaGliYXNlIn0.Mb_2e9Y27VOqK1VKrPXKKuCgUVT16ugYVsmFiKnDxuI"
  }

Routes

You can reach the API Endpoint you created above as follows:

  https://{ your company subdomain }.hibase.co/hooks/v1/{ endpoint }

Here, the following routes are available with their corresponding HTTP verb:

Route HTTP Verb Path Required Permissions
create POST :endpoint Write
mass-create POST :endpoint/. Write
update PUT/PATCH :endpoint/:record_id Write
mass-update PUT/PATCH :endpoint Write
delete DELETE :endpoint/:record_id Write
show GET :endpoint/:record_id Read
index GET :endpoint Read

Payload and parameters

create / update

The payload for modifying actions (create / update) must be passed within a data root element in your JSON. The payload itself must be a key-value object matching the schema of the table you are writing to, for example.:

  {
    "data": {
      "id": 1,
      "column1":"value1", 
      "column2":"value2"
    }
  }

mass-create / mass-update

It is possible to insert multiple records at once through the mass-create and mass-update routes. In order to perform a mass import, you have to pass an array of key-value objects matching the schema of the table you are writing to:

  {
    "data": [
      {
        "id": 1,
        "column1":"value1", 
        "column2":"value2"
      },
      {
        "id": 2,
        "column1":"value1", 
        "column2":"value2"
      },
      // ...
    ]
  }

NB: mass-update will only work so long as the underlying database has upsert capabilities.

index

The index action is paginated, with a maximum page size of 250 records. It accepts the following sorting and pagination parameters:

Parameter Description Valid Values Default value
order Sorts the list of records before returning it. Any table column name Table Primary Key
direction Sorting direction if order is provided. asc, desc asc
page Returns records from the specified page. Positive integers 1
per_page Number of records to be returned per page. Positive integers (max 250) 25

Responses

Responses served by API Endpoints conform to the JSON API specification. As such, individual records are repredented as follows:

  {
    "data": {
      "id": 1,          // Unique record identifier, usually the Primary Key of the table
      "type": "record", // Pluralized name of the table
      "attributes": {   // Key-value object matching the table schema
        "column1": "value1",
        "column2": "value2"
      }
    }
  }

Collections of records follow the same individual structure, just served as an array within the root data key:

  {
    "data": [
      {
        "id": 1,
        "type": "record",
        "attributes": {
          "column1": "value1",
          "column2": "value2"
        }
      },
      {
        "id": 2,
        "type": "record",
        "attributes": {
          "column1": "value1",
          "column2": "value2"
        }
      }
    ]
  }

What to expect

Validations

By default, columns which cannot be NULL in your schema will be validated before an insert or update is performed. If an invalid payload was passed, the API call will return an error response.

Primary Keys

In order to update, show or delete a record, the associated table will need to have a single primary key that will be matched by the :record_id portion of the URL.

Tables without a primary key do not support show, update and delete at this time.

The index action will also not work in its vanilla form for tables which do not have a primary key (single or composite). This is because the API will not be able to determine how to sort the records on its own in the absence of a primary key.

Indexing can still be performed for tables without a primary key, but you will have to pass an order parameter to tell the API how to sort your records before returning them.

Permissions

API Key permissions are matched to the credentials you set for your database when you added it to hibase.

This means a read action will use your database's read credentials, while a write action will use your write credentials. If those credentials do not correspond to the right set of permissions within your database, you might experience failures.

In such cases, check that the credentials used by hibase to access your database do have the right permissions with regards to what you want to achieve through the API (select, insert/update or delete).