Record an Usage Event
curl --request POST \
--url http://127.0.0.1:8080/v1/c/usage \
--header 'Content-Type: application/json' \
--header 'wb-key: <api-key>' \
--data '
{
"customer_id": "Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670",
"feature_slug": "<string>",
"units": "<string>",
"is_absolute": true,
"metadata": {},
"timestamp": "2023-11-07T05:31:56Z"
}
'import requests
url = "http://127.0.0.1:8080/v1/c/usage"
payload = {
"customer_id": "Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670",
"feature_slug": "<string>",
"units": "<string>",
"is_absolute": True,
"metadata": {},
"timestamp": "2023-11-07T05:31:56Z"
}
headers = {
"wb-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'wb-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customer_id: 'Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670',
feature_slug: '<string>',
units: '<string>',
is_absolute: true,
metadata: {},
timestamp: '2023-11-07T05:31:56Z'
})
};
fetch('http://127.0.0.1:8080/v1/c/usage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "8080",
CURLOPT_URL => "http://127.0.0.1:8080/v1/c/usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer_id' => 'Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670',
'feature_slug' => '<string>',
'units' => '<string>',
'is_absolute' => true,
'metadata' => [
],
'timestamp' => '2023-11-07T05:31:56Z'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"wb-key: <api-key>"
],
]);
$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"
)
func main() {
url := "http://127.0.0.1:8080/v1/c/usage"
payload := strings.NewReader("{\n \"customer_id\": \"Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670\",\n \"feature_slug\": \"<string>\",\n \"units\": \"<string>\",\n \"is_absolute\": true,\n \"metadata\": {},\n \"timestamp\": \"2023-11-07T05:31:56Z\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("wb-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("http://127.0.0.1:8080/v1/c/usage")
.header("wb-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"customer_id\": \"Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670\",\n \"feature_slug\": \"<string>\",\n \"units\": \"<string>\",\n \"is_absolute\": true,\n \"metadata\": {},\n \"timestamp\": \"2023-11-07T05:31:56Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://127.0.0.1:8080/v1/c/usage")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["wb-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customer_id\": \"Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670\",\n \"feature_slug\": \"<string>\",\n \"units\": \"<string>\",\n \"is_absolute\": true,\n \"metadata\": {},\n \"timestamp\": \"2023-11-07T05:31:56Z\"\n}"
response = http.request(request)
puts response.read_bodyUsage
Report Single Event
Increment the usage counters for a specific feature and customer within the current billing period.
POST
/
v1
/
c
/
usage
Record an Usage Event
curl --request POST \
--url http://127.0.0.1:8080/v1/c/usage \
--header 'Content-Type: application/json' \
--header 'wb-key: <api-key>' \
--data '
{
"customer_id": "Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670",
"feature_slug": "<string>",
"units": "<string>",
"is_absolute": true,
"metadata": {},
"timestamp": "2023-11-07T05:31:56Z"
}
'import requests
url = "http://127.0.0.1:8080/v1/c/usage"
payload = {
"customer_id": "Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670",
"feature_slug": "<string>",
"units": "<string>",
"is_absolute": True,
"metadata": {},
"timestamp": "2023-11-07T05:31:56Z"
}
headers = {
"wb-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'wb-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customer_id: 'Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670',
feature_slug: '<string>',
units: '<string>',
is_absolute: true,
metadata: {},
timestamp: '2023-11-07T05:31:56Z'
})
};
fetch('http://127.0.0.1:8080/v1/c/usage', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "8080",
CURLOPT_URL => "http://127.0.0.1:8080/v1/c/usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer_id' => 'Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670',
'feature_slug' => '<string>',
'units' => '<string>',
'is_absolute' => true,
'metadata' => [
],
'timestamp' => '2023-11-07T05:31:56Z'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"wb-key: <api-key>"
],
]);
$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"
)
func main() {
url := "http://127.0.0.1:8080/v1/c/usage"
payload := strings.NewReader("{\n \"customer_id\": \"Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670\",\n \"feature_slug\": \"<string>\",\n \"units\": \"<string>\",\n \"is_absolute\": true,\n \"metadata\": {},\n \"timestamp\": \"2023-11-07T05:31:56Z\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("wb-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("http://127.0.0.1:8080/v1/c/usage")
.header("wb-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"customer_id\": \"Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670\",\n \"feature_slug\": \"<string>\",\n \"units\": \"<string>\",\n \"is_absolute\": true,\n \"metadata\": {},\n \"timestamp\": \"2023-11-07T05:31:56Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://127.0.0.1:8080/v1/c/usage")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["wb-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customer_id\": \"Cust_c40bea18-c0c9-44b1-bd0c-43f5283e1670\",\n \"feature_slug\": \"<string>\",\n \"units\": \"<string>\",\n \"is_absolute\": true,\n \"metadata\": {},\n \"timestamp\": \"2023-11-07T05:31:56Z\"\n}"
response = http.request(request)
puts response.read_body
This simplified, single-event usage reporting endpoint is suitable for logging individual events during testing. For production use, refer to the more powerful bulk endpoint designed to handle batches of multiple events.
Body
application/json
Structure to report Usage for Usage-based features in a Contract Currently the only reporting strategy supported is additive, meaning that all reported usage units are summed for the billing period. This requires additional care from the reporter to ensure that no double-reporting takes place
Response
200
Recorded