API reference
List payments
Returns your payments, newest first, a page at a time.
GET
https://api.takaelo.com/v1/paymentsQuery
statusstringinitiated,pending,completed,pending_review,failedorrefunded.created[gte]integer- Created at or after this unix time (seconds).
created[lte]integer- Created at or before this unix time (seconds).
limitinteger- 1–100, default 20.
starting_afterstring- A payment id: return the page after it. Use the last id of the page you have.
# Completed payments since a moment (unix seconds), 100 per page.
curl -G https://api.takaelo.com/v1/payments \
-H "Authorization: Bearer $TAKAELO_SECRET_KEY" \
-d status=completed \
-d limit=100 \
--data-urlencode "created[gte]=1791100000"
# Next page: pass the last id you received.
# -d starting_after=pay_3kT9xQm2LrV8nB4cW7yZ1aPd<?php
// Every completed payment of the last 7 days, page by page.
$since = time() - 7 * 24 * 3600;
$startingAfter = null;
do {
$query = ['status' => 'completed', 'limit' => 100, 'created[gte]' => $since];
if ($startingAfter !== null) {
$query['starting_after'] = $startingAfter;
}
$ch = curl_init('https://api.takaelo.com/v1/payments?' . http_build_query($query));
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('TAKAELO_SECRET_KEY')],
]);
$body = json_decode(curl_exec($ch), true);
if (empty($body['success'])) {
throw new RuntimeException($body['code'] . ': ' . $body['message']);
}
$page = $body['data'];
foreach ($page['data'] as $payment) {
echo "{$payment['id']} {$payment['amount']} {$payment['reference']}" . PHP_EOL;
}
$startingAfter = $page['has_more'] ? end($page['data'])['id'] : null;
} while ($startingAfter !== null);// Every completed payment of the last 7 days, page by page.
const since = Math.floor(Date.now() / 1000) - 7 * 24 * 3600;
let startingAfter;
do {
const query = new URLSearchParams({ status: "completed", limit: "100", "created[gte]": String(since) });
if (startingAfter) query.set("starting_after", startingAfter);
const res = await fetch(`https://api.takaelo.com/v1/payments?${query}`, {
headers: { Authorization: `Bearer ${process.env.TAKAELO_SECRET_KEY}` },
});
const body = await res.json();
if (!body.success) throw new Error(`${body.code}: ${body.message}`);
const page = body.data;
for (const payment of page.data) console.log(payment.id, payment.amount, payment.reference);
startingAfter = page.has_more ? page.data.at(-1).id : undefined;
} while (startingAfter);import json
import os
import time
import urllib.parse
import urllib.request
# Every completed payment of the last 7 days, page by page.
since = int(time.time()) - 7 * 24 * 3600
starting_after = None
while True:
query = {"status": "completed", "limit": 100, "created[gte]": since}
if starting_after:
query["starting_after"] = starting_after
request = urllib.request.Request(
"https://api.takaelo.com/v1/payments?" + urllib.parse.urlencode(query),
headers={"Authorization": "Bearer " + os.environ["TAKAELO_SECRET_KEY"]},
)
with urllib.request.urlopen(request) as response:
page = json.load(response)["data"]
for payment in page["data"]:
print(payment["id"], payment["amount"], payment["reference"])
if not page["has_more"]:
break
starting_after = page["data"][-1]["id"]package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"os"
"strconv"
"time"
)
type Payment struct {
ID string `json:"id"`
Amount float64 `json:"amount"`
Reference string `json:"reference"`
}
// Every completed payment of the last 7 days, page by page.
func main() {
since := time.Now().Add(-7 * 24 * time.Hour).Unix()
startingAfter := ""
for {
query := url.Values{"status": {"completed"}, "limit": {"100"}, "created[gte]": {strconv.FormatInt(since, 10)}}
if startingAfter != "" {
query.Set("starting_after", startingAfter)
}
req, _ := http.NewRequest(http.MethodGet, "https://api.takaelo.com/v1/payments?"+query.Encode(), nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("TAKAELO_SECRET_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
var body struct {
Success bool `json:"success"`
Code string `json:"code"`
Message string `json:"message"`
Data struct {
Data []Payment `json:"data"`
HasMore bool `json:"has_more"`
} `json:"data"`
}
err = json.NewDecoder(res.Body).Decode(&body)
res.Body.Close()
if err != nil {
log.Fatal(err)
}
if !body.Success {
log.Fatalf("%s: %s", body.Code, body.Message)
}
for _, p := range body.Data.Data {
fmt.Println(p.ID, p.Amount, p.Reference)
}
if !body.Data.HasMore {
break
}
startingAfter = body.Data.Data[len(body.Data.Data)-1].ID
}
}require "json"
require "net/http"
# Every completed payment of the last 7 days, page by page.
since = Time.now.to_i - 7 * 24 * 3600
starting_after = nil
loop do
uri = URI("https://api.takaelo.com/v1/payments")
query = { "status" => "completed", "limit" => 100, "created[gte]" => since }
query["starting_after"] = starting_after if starting_after
uri.query = URI.encode_www_form(query)
request = Net::HTTP::Get.new(uri, "Authorization" => "Bearer #{ENV.fetch("TAKAELO_SECRET_KEY")}")
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
body = JSON.parse(response.body)
raise "#{body["code"]}: #{body["message"]}" unless body["success"]
page = body["data"]
page["data"].each { |payment| puts "#{payment["id"]} #{payment["amount"]} #{payment["reference"]}" }
break unless page["has_more"]
starting_after = page["data"].last["id"]
endimport com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
// Every completed payment of the last 7 days, page by page.
public class ListPayments {
public static void main(String[] args) throws Exception {
HttpClient http = HttpClient.newHttpClient();
ObjectMapper json = new ObjectMapper();
long since = Instant.now().getEpochSecond() - 7 * 24 * 3600;
String startingAfter = null;
do {
String query = "status=completed&limit=100&" + URLEncoder.encode("created[gte]", StandardCharsets.UTF_8) + "=" + since;
if (startingAfter != null) query += "&starting_after=" + startingAfter;
HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.takaelo.com/v1/payments?" + query))
.header("Authorization", "Bearer " + System.getenv("TAKAELO_SECRET_KEY"))
.build();
JsonNode body = json.readTree(http.send(request, HttpResponse.BodyHandlers.ofString()).body());
if (!body.path("success").asBoolean()) {
throw new IllegalStateException(body.path("code").asText() + ": " + body.path("message").asText());
}
JsonNode page = body.get("data");
for (JsonNode payment : page.get("data")) {
System.out.println(payment.get("id").asText() + " " + payment.get("amount").asText());
startingAfter = payment.get("id").asText();
}
if (!page.get("has_more").asBoolean()) startingAfter = null;
} while (startingAfter != null);
}
}using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("TAKAELO_SECRET_KEY"));
// Every completed payment of the last 7 days, page by page.
var since = DateTimeOffset.UtcNow.AddDays(-7).ToUnixTimeSeconds();
string? startingAfter = null;
do
{
var url = $"https://api.takaelo.com/v1/payments?status=completed&limit=100&created%5Bgte%5D={since}";
if (startingAfter != null) url += $"&starting_after={startingAfter}";
var body = await http.GetFromJsonAsync<JsonElement>(url);
var page = body.GetProperty("data");
foreach (var payment in page.GetProperty("data").EnumerateArray())
{
Console.WriteLine($"{payment.GetProperty("id")} {payment.GetProperty("amount")}");
startingAfter = payment.GetProperty("id").GetString();
}
if (!page.GetProperty("has_more").GetBoolean()) startingAfter = null;
} while (startingAfter != null);{
"success": true,
"message": "Payments retrieved",
"data": {
"object": "list",
"data": [
{ "id": "pay_3kT9xQm2LrV8nB4cW7yZ1aPd", "object": "payment", "status": "completed", "amount": 1250, "…": "…" },
{ "id": "pay_9pQ2wE7rT4yU1iO6aS3dF8gH", "object": "payment", "status": "completed", "amount": 640, "…": "…" }
],
"has_more": true
}
}