Asynchronously Ingest Usage Data
curl --request POST \
--url https://api.justpaid.io/api/v1/usage/ingest-async \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"events": [
{
"customer_id": "123e4567-e89b-12d3-a456-426614174000",
"event_name": "purchase_made",
"timestamp": "2023-10-01T12:00:00Z",
"idempotency_key": "unique-key-1",
"event_value": 49.99,
"properties": {
"item_id": "A100",
"quantity": 2
}
},
{
"customer_id": "123e4567-e89b-12d3-a456-426614174001",
"event_name": "subscription_started",
"timestamp": "2023-10-02T15:30:00Z",
"idempotency_key": "unique-key-2",
"event_value": 0,
"properties": {
"plan": "premium",
"duration": "12_months"
}
}
]
}
'import requests
url = "https://api.justpaid.io/api/v1/usage/ingest-async"
payload = { "events": [
{
"customer_id": "123e4567-e89b-12d3-a456-426614174000",
"event_name": "purchase_made",
"timestamp": "2023-10-01T12:00:00Z",
"idempotency_key": "unique-key-1",
"event_value": 49.99,
"properties": {
"item_id": "A100",
"quantity": 2
}
},
{
"customer_id": "123e4567-e89b-12d3-a456-426614174001",
"event_name": "subscription_started",
"timestamp": "2023-10-02T15:30:00Z",
"idempotency_key": "unique-key-2",
"event_value": 0,
"properties": {
"plan": "premium",
"duration": "12_months"
}
}
] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
events: [
{
customer_id: '123e4567-e89b-12d3-a456-426614174000',
event_name: 'purchase_made',
timestamp: '2023-10-01T12:00:00Z',
idempotency_key: 'unique-key-1',
event_value: 49.99,
properties: {item_id: 'A100', quantity: 2}
},
{
customer_id: '123e4567-e89b-12d3-a456-426614174001',
event_name: 'subscription_started',
timestamp: '2023-10-02T15:30:00Z',
idempotency_key: 'unique-key-2',
event_value: 0,
properties: {plan: 'premium', duration: '12_months'}
}
]
})
};
fetch('https://api.justpaid.io/api/v1/usage/ingest-async', 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.justpaid.io/api/v1/usage/ingest-async",
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([
'events' => [
[
'customer_id' => '123e4567-e89b-12d3-a456-426614174000',
'event_name' => 'purchase_made',
'timestamp' => '2023-10-01T12:00:00Z',
'idempotency_key' => 'unique-key-1',
'event_value' => 49.99,
'properties' => [
'item_id' => 'A100',
'quantity' => 2
]
],
[
'customer_id' => '123e4567-e89b-12d3-a456-426614174001',
'event_name' => 'subscription_started',
'timestamp' => '2023-10-02T15:30:00Z',
'idempotency_key' => 'unique-key-2',
'event_value' => 0,
'properties' => [
'plan' => 'premium',
'duration' => '12_months'
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: 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"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.justpaid.io/api/v1/usage/ingest-async"
payload := strings.NewReader("{\n \"events\": [\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"event_name\": \"purchase_made\",\n \"timestamp\": \"2023-10-01T12:00:00Z\",\n \"idempotency_key\": \"unique-key-1\",\n \"event_value\": 49.99,\n \"properties\": {\n \"item_id\": \"A100\",\n \"quantity\": 2\n }\n },\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174001\",\n \"event_name\": \"subscription_started\",\n \"timestamp\": \"2023-10-02T15:30:00Z\",\n \"idempotency_key\": \"unique-key-2\",\n \"event_value\": 0,\n \"properties\": {\n \"plan\": \"premium\",\n \"duration\": \"12_months\"\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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("https://api.justpaid.io/api/v1/usage/ingest-async")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"events\": [\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"event_name\": \"purchase_made\",\n \"timestamp\": \"2023-10-01T12:00:00Z\",\n \"idempotency_key\": \"unique-key-1\",\n \"event_value\": 49.99,\n \"properties\": {\n \"item_id\": \"A100\",\n \"quantity\": 2\n }\n },\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174001\",\n \"event_name\": \"subscription_started\",\n \"timestamp\": \"2023-10-02T15:30:00Z\",\n \"idempotency_key\": \"unique-key-2\",\n \"event_value\": 0,\n \"properties\": {\n \"plan\": \"premium\",\n \"duration\": \"12_months\"\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.justpaid.io/api/v1/usage/ingest-async")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"events\": [\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"event_name\": \"purchase_made\",\n \"timestamp\": \"2023-10-01T12:00:00Z\",\n \"idempotency_key\": \"unique-key-1\",\n \"event_value\": 49.99,\n \"properties\": {\n \"item_id\": \"A100\",\n \"quantity\": 2\n }\n },\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174001\",\n \"event_name\": \"subscription_started\",\n \"timestamp\": \"2023-10-02T15:30:00Z\",\n \"idempotency_key\": \"unique-key-2\",\n \"event_value\": 0,\n \"properties\": {\n \"plan\": \"premium\",\n \"duration\": \"12_months\"\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"job_id": "a4f8e9be-3d5b-4f8e-8b4d-9b4e5c9f5a2d",
"status": "PENDING",
"total_events": 2,
"created_at": "2023-10-10T10:00:00Z"
}{
"detail": "Invalid customer_id format."
}{
"detail": "Authentication credentials were not provided."
}{
"detail": "An unexpected error occurred."
}Usage
Asynchronously Ingest Usage Data
Submit usage data for asynchronous processing. This endpoint accepts a list of customer events and processes them asynchronously as a batch job. The response includes a job ID that can be used to check the status of the batch job.
POST
/
api
/
v1
/
usage
/
ingest-async
Asynchronously Ingest Usage Data
curl --request POST \
--url https://api.justpaid.io/api/v1/usage/ingest-async \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"events": [
{
"customer_id": "123e4567-e89b-12d3-a456-426614174000",
"event_name": "purchase_made",
"timestamp": "2023-10-01T12:00:00Z",
"idempotency_key": "unique-key-1",
"event_value": 49.99,
"properties": {
"item_id": "A100",
"quantity": 2
}
},
{
"customer_id": "123e4567-e89b-12d3-a456-426614174001",
"event_name": "subscription_started",
"timestamp": "2023-10-02T15:30:00Z",
"idempotency_key": "unique-key-2",
"event_value": 0,
"properties": {
"plan": "premium",
"duration": "12_months"
}
}
]
}
'import requests
url = "https://api.justpaid.io/api/v1/usage/ingest-async"
payload = { "events": [
{
"customer_id": "123e4567-e89b-12d3-a456-426614174000",
"event_name": "purchase_made",
"timestamp": "2023-10-01T12:00:00Z",
"idempotency_key": "unique-key-1",
"event_value": 49.99,
"properties": {
"item_id": "A100",
"quantity": 2
}
},
{
"customer_id": "123e4567-e89b-12d3-a456-426614174001",
"event_name": "subscription_started",
"timestamp": "2023-10-02T15:30:00Z",
"idempotency_key": "unique-key-2",
"event_value": 0,
"properties": {
"plan": "premium",
"duration": "12_months"
}
}
] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
events: [
{
customer_id: '123e4567-e89b-12d3-a456-426614174000',
event_name: 'purchase_made',
timestamp: '2023-10-01T12:00:00Z',
idempotency_key: 'unique-key-1',
event_value: 49.99,
properties: {item_id: 'A100', quantity: 2}
},
{
customer_id: '123e4567-e89b-12d3-a456-426614174001',
event_name: 'subscription_started',
timestamp: '2023-10-02T15:30:00Z',
idempotency_key: 'unique-key-2',
event_value: 0,
properties: {plan: 'premium', duration: '12_months'}
}
]
})
};
fetch('https://api.justpaid.io/api/v1/usage/ingest-async', 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.justpaid.io/api/v1/usage/ingest-async",
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([
'events' => [
[
'customer_id' => '123e4567-e89b-12d3-a456-426614174000',
'event_name' => 'purchase_made',
'timestamp' => '2023-10-01T12:00:00Z',
'idempotency_key' => 'unique-key-1',
'event_value' => 49.99,
'properties' => [
'item_id' => 'A100',
'quantity' => 2
]
],
[
'customer_id' => '123e4567-e89b-12d3-a456-426614174001',
'event_name' => 'subscription_started',
'timestamp' => '2023-10-02T15:30:00Z',
'idempotency_key' => 'unique-key-2',
'event_value' => 0,
'properties' => [
'plan' => 'premium',
'duration' => '12_months'
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: 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"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.justpaid.io/api/v1/usage/ingest-async"
payload := strings.NewReader("{\n \"events\": [\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"event_name\": \"purchase_made\",\n \"timestamp\": \"2023-10-01T12:00:00Z\",\n \"idempotency_key\": \"unique-key-1\",\n \"event_value\": 49.99,\n \"properties\": {\n \"item_id\": \"A100\",\n \"quantity\": 2\n }\n },\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174001\",\n \"event_name\": \"subscription_started\",\n \"timestamp\": \"2023-10-02T15:30:00Z\",\n \"idempotency_key\": \"unique-key-2\",\n \"event_value\": 0,\n \"properties\": {\n \"plan\": \"premium\",\n \"duration\": \"12_months\"\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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("https://api.justpaid.io/api/v1/usage/ingest-async")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"events\": [\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"event_name\": \"purchase_made\",\n \"timestamp\": \"2023-10-01T12:00:00Z\",\n \"idempotency_key\": \"unique-key-1\",\n \"event_value\": 49.99,\n \"properties\": {\n \"item_id\": \"A100\",\n \"quantity\": 2\n }\n },\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174001\",\n \"event_name\": \"subscription_started\",\n \"timestamp\": \"2023-10-02T15:30:00Z\",\n \"idempotency_key\": \"unique-key-2\",\n \"event_value\": 0,\n \"properties\": {\n \"plan\": \"premium\",\n \"duration\": \"12_months\"\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.justpaid.io/api/v1/usage/ingest-async")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"events\": [\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174000\",\n \"event_name\": \"purchase_made\",\n \"timestamp\": \"2023-10-01T12:00:00Z\",\n \"idempotency_key\": \"unique-key-1\",\n \"event_value\": 49.99,\n \"properties\": {\n \"item_id\": \"A100\",\n \"quantity\": 2\n }\n },\n {\n \"customer_id\": \"123e4567-e89b-12d3-a456-426614174001\",\n \"event_name\": \"subscription_started\",\n \"timestamp\": \"2023-10-02T15:30:00Z\",\n \"idempotency_key\": \"unique-key-2\",\n \"event_value\": 0,\n \"properties\": {\n \"plan\": \"premium\",\n \"duration\": \"12_months\"\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"job_id": "a4f8e9be-3d5b-4f8e-8b4d-9b4e5c9f5a2d",
"status": "PENDING",
"total_events": 2,
"created_at": "2023-10-10T10:00:00Z"
}{
"detail": "Invalid customer_id format."
}{
"detail": "Authentication credentials were not provided."
}{
"detail": "An unexpected error occurred."
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Represents a list of customer events.
Attributes: events (list[CustomerEvent]): A list of customer events. Each event should be a dictionary with at-least the following keys: event_name, timestamp, idempotency_key.
Show child attributes
Show child attributes
Response
Successfully submitted the usage data for asynchronous processing.
Was this page helpful?
⌘I
