Retrieve contract current usage
curl --request GET \
--url https://api.getlago.com/api/v2/contracts/{external_id}/current_usage \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.getlago.com/api/v2/contracts/{external_id}/current_usage"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.getlago.com/api/v2/contracts/{external_id}/current_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_URL => "https://api.getlago.com/api/v2/contracts/{external_id}/current_usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$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"
)
func main() {
url := "https://api.getlago.com/api/v2/contracts/{external_id}/current_usage"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.getlago.com/api/v2/contracts/{external_id}/current_usage")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.getlago.com/api/v2/contracts/{external_id}/current_usage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"current_usage": {
"external_contract_id": "contract_123",
"external_customer_id": "customer_123",
"currency": "USD",
"amount_cents": 1000,
"taxes_amount_cents": 200,
"total_amount_cents": 1200,
"rate_cards": [
{
"rate_card_code": "compute_usd",
"rate_card_name": "Compute USD",
"product_code": "api_requests",
"product_name": "API requests",
"product_category_code": "compute",
"product_category_name": "Compute",
"product_filter_code": "eu",
"product_filter_name": "EU",
"invoice_display_name": "API requests",
"product_type": "metered",
"billable_metric_code": "api_requests",
"billing_timing": "arrears",
"rate_phase_code": "default",
"rate_phase_name": "Default",
"rate_source": "rate",
"units": "1.5",
"events_count": 42,
"amount_cents": 1000,
"from_datetime": "2022-04-29T08:59:51.123456Z",
"to_datetime": "2022-04-29T08:59:51.123456Z",
"segments": [
{
"rate_model": "standard",
"rate_properties": {},
"units": "1.5",
"events_count": 42,
"amount_cents": 1000,
"from_datetime": "2022-04-29T08:59:51.123456Z",
"to_datetime": "2022-04-29T08:59:51.123456Z"
}
]
}
]
}
}{
"code": "invalid_expand",
"details": [
{
"code": "malformed",
"field": "expands",
"meta": {
"allowed_values": []
}
}
]
}{
"code": "unauthorized",
"details": []
}{
"code": "feature_unavailable",
"details": []
}{
"code": "resource_not_found",
"details": [
{
"code": "resource_not_found",
"field": "base",
"meta": {
"resource": "resource_name"
}
}
]
}{
"code": "validation_errors",
"details": [
{
"code": "value_is_mandatory",
"field": "name",
"meta": {}
}
]
}Current usage
Retrieve current usage
Returns usage across the open billing windows of the active or pending contract.
GET
/
contracts
/
{external_id}
/
current_usage
Retrieve contract current usage
curl --request GET \
--url https://api.getlago.com/api/v2/contracts/{external_id}/current_usage \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.getlago.com/api/v2/contracts/{external_id}/current_usage"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.getlago.com/api/v2/contracts/{external_id}/current_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_URL => "https://api.getlago.com/api/v2/contracts/{external_id}/current_usage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$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"
)
func main() {
url := "https://api.getlago.com/api/v2/contracts/{external_id}/current_usage"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.getlago.com/api/v2/contracts/{external_id}/current_usage")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.getlago.com/api/v2/contracts/{external_id}/current_usage")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"current_usage": {
"external_contract_id": "contract_123",
"external_customer_id": "customer_123",
"currency": "USD",
"amount_cents": 1000,
"taxes_amount_cents": 200,
"total_amount_cents": 1200,
"rate_cards": [
{
"rate_card_code": "compute_usd",
"rate_card_name": "Compute USD",
"product_code": "api_requests",
"product_name": "API requests",
"product_category_code": "compute",
"product_category_name": "Compute",
"product_filter_code": "eu",
"product_filter_name": "EU",
"invoice_display_name": "API requests",
"product_type": "metered",
"billable_metric_code": "api_requests",
"billing_timing": "arrears",
"rate_phase_code": "default",
"rate_phase_name": "Default",
"rate_source": "rate",
"units": "1.5",
"events_count": 42,
"amount_cents": 1000,
"from_datetime": "2022-04-29T08:59:51.123456Z",
"to_datetime": "2022-04-29T08:59:51.123456Z",
"segments": [
{
"rate_model": "standard",
"rate_properties": {},
"units": "1.5",
"events_count": 42,
"amount_cents": 1000,
"from_datetime": "2022-04-29T08:59:51.123456Z",
"to_datetime": "2022-04-29T08:59:51.123456Z"
}
]
}
]
}
}{
"code": "invalid_expand",
"details": [
{
"code": "malformed",
"field": "expands",
"meta": {
"allowed_values": []
}
}
]
}{
"code": "unauthorized",
"details": []
}{
"code": "feature_unavailable",
"details": []
}{
"code": "resource_not_found",
"details": [
{
"code": "resource_not_found",
"field": "base",
"meta": {
"resource": "resource_name"
}
}
]
}{
"code": "validation_errors",
"details": [
{
"code": "value_is_mandatory",
"field": "name",
"meta": {}
}
]
}API v2 is in beta. Endpoints return the
X-Lago-Endpoint-Status: beta header.Authorizations
Query Parameters
Code of the contract to select. Required when multiple contracts share the external ID, including canceled and terminated contracts. Otherwise, it can be omitted. Omitting it when the external ID is ambiguous returns 422 value_is_mandatory on contract_code; a blank value returns 422 value_is_invalid. Exact contract code.
Minimum string length:
1Example:
"initial"