Bonusly

API Keys

Manage your API keys

List API Keys

Open in API Explorer
GET /api_keys

List ids and labels for your API keys

Example Request

Format:
curl --request GET \
  --url 'https://bonus.ly/api/v1/api_keys?user_id=foo&access_token=YOUR%20API%20KEY%20HERE' \
  --header 'accept: application/json'
require 'uri'
require 'net/http'

url = URI("https://bonus.ly/api/v1/api_keys?user_id=foo&access_token=YOUR%20API%20KEY%20HERE")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(url)
request["accept"] = 'application/json'

response = http.request(request)
puts response.read_body
var http = require("https");

var options = {
  "method": "GET",
  "hostname": "bonus.ly",
  "port": null,
  "path": "/api/v1/api_keys?user_id=foo&access_token=YOUR%20API%20KEY%20HERE",
  "headers": {
    "accept": "application/json"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end();
import http.client

conn = http.client.HTTPSConnection("bonus.ly")

headers = { 'accept': "application/json" }

conn.request("GET", "/api/v1/api_keys?user_id=foo&access_token=YOUR%20API%20KEY%20HERE", headers=headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://bonus.ly/api/v1/api_keys?user_id=foo&access_token=YOUR%20API%20KEY%20HERE",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "accept: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://bonus.ly/api/v1/api_keys?user_id=foo&access_token=YOUR%20API%20KEY%20HERE"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("accept", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}

Query Parameters

Name Type Required Description Example
user_id String Optional

If using an admin access_token, you can see other user's API keys (within your company)

foo

Responses

200 Success

List of API keys (id and label)

API Keys List
[
  "id": "583dfa500a149e402b4c8503",
String (Uuid)

The unique identifier of the API key

  "label": "Dashboard API key",
String

User-provided description of what the API key is for.

  "read_only": true
Boolean (Literals)

Indicates if the API key can be used to modify data or just read it

]
401 Failure

If no/invalid access token is provided.

API Keys Bad api key
{
  "success": false,
Boolean
  "message": "Bad or missing access token"
String
}

Create API Key

Open in API Explorer
POST /api_keys

Create a new API key

Example Request

Format:
curl --request POST \
  --url 'https://bonus.ly/api/v1/api_keys?label=foo&read_only=true&user_id=foo&access_token=YOUR%20API%20KEY%20HERE' \
  --header 'accept: application/json' \
  --header 'content-type: multipart/form-data; boundary=---011000010111000001101001'
require 'uri'
require 'net/http'

url = URI("https://bonus.ly/api/v1/api_keys?label=foo&read_only=true&user_id=foo&access_token=YOUR%20API%20KEY%20HERE")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001'

response = http.request(request)
puts response.read_body
var http = require("https");

var options = {
  "method": "POST",
  "hostname": "bonus.ly",
  "port": null,
  "path": "/api/v1/api_keys?label=foo&read_only=true&user_id=foo&access_token=YOUR%20API%20KEY%20HERE",
  "headers": {
    "accept": "application/json",
    "content-type": "multipart/form-data; boundary=---011000010111000001101001"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end();
import http.client

conn = http.client.HTTPSConnection("bonus.ly")

payload = ""

headers = {
    'accept': "application/json",
    'content-type': "multipart/form-data; boundary=---011000010111000001101001"
    }

conn.request("POST", "/api/v1/api_keys?label=foo&read_only=true&user_id=foo&access_token=YOUR%20API%20KEY%20HERE", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://bonus.ly/api/v1/api_keys?label=foo&read_only=true&user_id=foo&access_token=YOUR%20API%20KEY%20HERE",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "content-type: multipart/form-data; boundary=---011000010111000001101001"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://bonus.ly/api/v1/api_keys?label=foo&read_only=true&user_id=foo&access_token=YOUR%20API%20KEY%20HERE"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("accept", "application/json")
	req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}

Query Parameters

Name Type Required Description Example
label String Required

Label explaining the use case of this API key

foo
read_only Boolean (literals) Optional

If provided as "true", the created API key will only be able to read data from the API (not create/update/destroy)

true
user_id String Optional

Admins can specify a different user for which to create the API key.

foo

Responses

201 Success

API key created and access token will be returned in X-BONUSLY-Authentication-Token header

API Keys Created successfully
{
  "success": true,
Boolean
  "message": "New Access Token Created"
String
}
400 Failure

Will return a message including the failure reason.

API Keys Validation failure
{
  "success": false,
Boolean
  "message": "Label can't be blank"
String
}
401 Bad API key API Keys Bad api key
{
  "success": false,
Boolean
  "message": "Bad or missing access token"
String
}

Cancel API Key

Open in API Explorer
DELETE /api_keys/:id

Cancel an API key

Example Request

Format:
curl --request DELETE \
  --url 'https://bonus.ly/api/v1/api_keys/:id?access_token=YOUR%20API%20KEY%20HERE' \
  --header 'accept: application/json'
require 'uri'
require 'net/http'

url = URI("https://bonus.ly/api/v1/api_keys/:id?access_token=YOUR%20API%20KEY%20HERE")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Delete.new(url)
request["accept"] = 'application/json'

response = http.request(request)
puts response.read_body
var http = require("https");

var options = {
  "method": "DELETE",
  "hostname": "bonus.ly",
  "port": null,
  "path": "/api/v1/api_keys/:id?access_token=YOUR%20API%20KEY%20HERE",
  "headers": {
    "accept": "application/json"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end();
import http.client

conn = http.client.HTTPSConnection("bonus.ly")

headers = { 'accept': "application/json" }

conn.request("DELETE", "/api/v1/api_keys/:id?access_token=YOUR%20API%20KEY%20HERE", headers=headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://bonus.ly/api/v1/api_keys/:id?access_token=YOUR%20API%20KEY%20HERE",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "DELETE",
  CURLOPT_HTTPHEADER => array(
    "accept: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://bonus.ly/api/v1/api_keys/:id?access_token=YOUR%20API%20KEY%20HERE"

	req, _ := http.NewRequest("DELETE", url, nil)

	req.Header.Add("accept", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}

Path Parameters

Name Type Required Description Example
id String Required

The API key id

foo

Responses

200 Success API Keys Destroyed success
{
  "success": true,
Boolean (Literals)

Indicates success of action

  "message": "API Access Token has been destroyed"
String

Explanation for access

}
401 Failure

Provided access token is invalid

API Keys Bad api key
{
  "success": false,
Boolean
  "message": "Bad or missing access token"
String
}