Bonusly

Webhooks

Webhooks allow you to receive updates (via HTTP POSTs to the URL of your choosing) when certain events occur in Bonusly, such as when a bonus is given or an achievement is earned.

List Webhooks

Open in API Explorer
GET /webhooks

See a summary of all webhooks your company is currently subscribed to.

Example Request

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

url = URI("https://bonus.ly/api/v1/webhooks?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/webhooks?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/webhooks?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/webhooks?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/webhooks?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))

}

Responses

200 Success

An array of webhook objects.

Webhooks List
[
  "id": "5b16ba789fb5ba5d06f5e001",
String

The ID of the webhook.

  "url": "https://foobarbaz.com",
String

The URL you want Bonusly to POST updates to.

  "event_types": [
    "foo",
    "foo",
    "foo"
  ]
Array

The Bonusly events you want to be notified of.

]

Create Webhook

Open in API Explorer
POST /webhooks

Subscribe to updates about Bonusly events by creating a new webhook.

Example Request

Format:
curl --request POST \
  --url 'https://bonus.ly/api/v1/webhooks?access_token=YOUR%20API%20KEY%20HERE' \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"event_types": ["bonus.created","achievement_event.created"], "url": "https://foobarbaz.com"}'
require 'uri'
require 'net/http'

url = URI("https://bonus.ly/api/v1/webhooks?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"] = 'application/json'
request.body = '{"url": "https://foobarbaz.com", "event_types": ["bonus.created","achievement_event.created"]}'

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

var options = {
  "method": "POST",
  "hostname": "bonus.ly",
  "port": null,
  "path": "/api/v1/webhooks?access_token=YOUR%20API%20KEY%20HERE",
  "headers": {
    "accept": "application/json",
    "content-type": "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.write('{"url": "https://foobarbaz.com", "event_types": ["bonus.created","achievement_event.created"]}');
req.end();
import http.client

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

payload = '{"url": "https://foobarbaz.com", "event_types": ["bonus.created","achievement_event.created"]}'

headers = {
    'accept': "application/json",
    'content-type': "application/json"
    }

conn.request("POST", "/api/v1/webhooks?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/webhooks?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 => '{"url": "https://foobarbaz.com", "event_types": ["bonus.created","achievement_event.created"]}',
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "content-type: application/json"
  ),
));

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

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
"strings"
	"net/http"
	"io/ioutil"
)

func main() {

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

	payload := strings.NewReader("{\"url\": \"https://foobarbaz.com\", \"event_types\": [\"bonus.created\",\"achievement_event.created\"]}")

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

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

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

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

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

}

Request Body

Name Type Required Description Example
url Object Required

The URL you want Bonusly to POST to, eg "https://foobarbaz.com". Ignore the "{}" example Gelato provides, it's not correct and apparently can't be changed.

{}
event_types Object Optional

The Bonusly events you want to be notified of. Defaults to ["bonus.created", "achievement_event.created"], and can only contain some combination of those strings.

[
]

Responses

200 Success

Returns the string ID of the newly created webhook.

Webhooks Id
{
  "id": "12345"
String
}

Update Webhook

Open in API Explorer
PUT /webhooks/:webhook_id

Update the URL or event types of an existing webhook.

Example Request

Format:
curl --request PUT \
  --url 'https://bonus.ly/api/v1/webhooks/:webhook_id?access_token=YOUR%20API%20KEY%20HERE' \
  --header 'accept: application/json' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data '{"url": "https://foobarbaz.com", "event_types": ["bonus.created"]}'
require 'uri'
require 'net/http'

url = URI("https://bonus.ly/api/v1/webhooks/:webhook_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::Put.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'application/x-www-form-urlencoded'
request.body = '{"url": "https://foobarbaz.com", "event_types": ["bonus.created"]}'

response = http.request(request)
puts response.read_body
var options = {
  "method": "PUT",
  "hostname": "bonus.ly",
  "port": null,
  "path": "/api/v1/webhooks/:webhook_id?access_token=YOUR%20API%20KEY%20HERE",
  "headers": {
    "accept": "application/json",
    "content-type": "application/x-www-form-urlencoded"
  }
};

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.write(JSON.stringify('{"url": "https://foobarbaz.com", "event_types": ["bonus.created"]}'));
req.end();
import http.client

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

payload = '{"url": "https://foobarbaz.com", "event_types": ["bonus.created"]}'

headers = {
    'accept': "application/json",
    'content-type': "application/x-www-form-urlencoded"
    }

conn.request("PUT", "/api/v1/webhooks/:webhook_id?access_token=YOUR%20API%20KEY%20HERE", payload, headers)

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

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

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://bonus.ly/api/v1/webhooks/:webhook_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 => "PUT",
  CURLOPT_POSTFIELDS => '{"url": "https://foobarbaz.com", "event_types": ["bonus.created"]}',
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "content-type: application/x-www-form-urlencoded"
  ),
));

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

curl_close($curl);

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

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

func main() {

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

	payload := strings.NewReader("{\"url\": \"https://foobarbaz.com\", \"event_types\": [\"bonus.created\"]}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("accept", "application/json")
	req.Header.Add("content-type", "application/x-www-form-urlencoded")

	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 ID of the webhook you want to update.

5b16ba789fb5ba5d06f5e001

Request Body

Name Type Required Description Example
url Object Optional

The URL you want Bonusly to POST to, eg "https://foobarbaz.com". This cannot be an empty string if it's present. Ignore the "{}" example Gelato provides, it's not correct and apparently can't be changed.

{}
event_types Object Optional

The array of event types you want to be notified of. If present, it can only contain the strings "bonus.created" and/or "achievement_event.created".

[
]

Responses

200 Success

Returns the ID of the updated webhook.

Webhooks Id
{
  "id": "12345"
String
}

Remove Webhook

Open in API Explorer
DELETE /webhooks/:webhook_id

Remove a webhook to unsubscribe from Bonusly events.

Example Request

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

url = URI("https://bonus.ly/api/v1/webhooks/:webhook_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/webhooks/:webhook_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/webhooks/:webhook_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/webhooks/:webhook_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/webhooks/:webhook_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
webhook_id String Required

The ID of the webhook to remove.

5b16ba789fb5ba5d06f5e001

Responses

200 Success

The ID of the removed webhook.

Webhooks Id
{
  "id": "12345"
String
}