Connecting via the API

Using curl to connect with an API key

A quick and easy way to get started exploring bit.io is with cURL.

First, grab your API key by clicking "Connect" and then "API / SDK", as shown below.

800800

Then try running a command against one of our REST endpoints.
A list of supported endpoints can be found here: https://docs.bit.io/reference

As an example, let's query the API for information about all of your repos:

API_KEY=<your-api-key>
curl --request GET \
  --url https://api.bit.io/api/v1beta/repos/ \
  --header "Authorization: Bearer ${API_KEY}" \
  --header "Accept: application/json"

where API_KEY is set to your personal bit.io API key, as shown in the first line of the above snippet.

You can pipe the output of the above command to jq to optionally add JSON output formatting, as shown below:

650650

The following curl example demonstrates how you could use the /query/ API endpoint run an arbitrary query against one of your repos:

API_KEY=<your-api-key>
curl --request POST \
     --url https://api.bit.io/api/v1beta/query/ \
     --header "Authorization: Bearer ${API_KEY}" \
     --header "Accept: application/json" \
     --header "Content-Type: application/json" \
     --data '{"query_string":"SELECT count(*) FROM \"adam/FCC\".\"spectrum auction\" WHERE auction_id=107;"}'

Note the use of \ characters to escape double quotes embedded in the SQL query itself.

The JSON response for this API call includes the requested query, as well as the desired result:

{
  "query_string": "SELECT count(*) FROM \"adam/FCC\".\"spectrum auction\" WHERE auction_id=107;",
  "fields": {
    "count": "BIGINT"
  },
  "data": [
    [
      134912
    ]
  ]
}

Did this page help you?