Skip to main content
POST
/
ingestBatch
Ingest events to Togai in batch
curl --request POST \
  --url https://api.togai.com/ingestBatch \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "events": [
    {
      "timestamp": "2022-06-15T07:30:35.123",
      "schemaName": "travelCompletedEvent",
      "id": "c0b1306d-f506-43a6-856b-69221efaee6b",
      "accountId": "1",
      "attributes": [
        {
          "name": "distanceTravelled",
          "value": "50",
          "unit": "Miles"
        },
        {
          "name": "timeSpent",
          "value": "60",
          "unit": "Minutes"
        }
      ],
      "dimensions": {
        "location": "Seattle",
        "costCenterCode": "1234",
        "travelType": "Business"
      }
    },
    {
      "timestamp": "2022-06-15T07:30:35.123",
      "schemaName": "sendMessageEvent",
      "id": "c0b1306d-f506-43a6-856b-69221efaee6c",
      "accountId": "1",
      "attributes": [
        {
          "name": "messageSentCount",
          "value": "50",
          "unit": "None"
        },
        {
          "name": "sizeOfMessage",
          "value": "60",
          "unit": "KiloBytes"
        }
      ],
      "dimensions": {
        "location": "Seattle",
        "costCenterCode": "1234",
        "messageProviderName": "Twilio"
      }
    }
  ]
}
'
import requests

url = "https://api.togai.com/ingestBatch"

payload = { "events": [
{
"timestamp": "2022-06-15T07:30:35.123",
"schemaName": "travelCompletedEvent",
"id": "c0b1306d-f506-43a6-856b-69221efaee6b",
"accountId": "1",
"attributes": [
{
"name": "distanceTravelled",
"value": "50",
"unit": "Miles"
},
{
"name": "timeSpent",
"value": "60",
"unit": "Minutes"
}
],
"dimensions": {
"location": "Seattle",
"costCenterCode": "1234",
"travelType": "Business"
}
},
{
"timestamp": "2022-06-15T07:30:35.123",
"schemaName": "sendMessageEvent",
"id": "c0b1306d-f506-43a6-856b-69221efaee6c",
"accountId": "1",
"attributes": [
{
"name": "messageSentCount",
"value": "50",
"unit": "None"
},
{
"name": "sizeOfMessage",
"value": "60",
"unit": "KiloBytes"
}
],
"dimensions": {
"location": "Seattle",
"costCenterCode": "1234",
"messageProviderName": "Twilio"
}
}
] }
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: [
{
timestamp: '2022-06-15T07:30:35.123',
schemaName: 'travelCompletedEvent',
id: 'c0b1306d-f506-43a6-856b-69221efaee6b',
accountId: '1',
attributes: [
{name: 'distanceTravelled', value: '50', unit: 'Miles'},
{name: 'timeSpent', value: '60', unit: 'Minutes'}
],
dimensions: {location: 'Seattle', costCenterCode: '1234', travelType: 'Business'}
},
{
timestamp: '2022-06-15T07:30:35.123',
schemaName: 'sendMessageEvent',
id: 'c0b1306d-f506-43a6-856b-69221efaee6c',
accountId: '1',
attributes: [
{name: 'messageSentCount', value: '50', unit: 'None'},
{name: 'sizeOfMessage', value: '60', unit: 'KiloBytes'}
],
dimensions: {location: 'Seattle', costCenterCode: '1234', messageProviderName: 'Twilio'}
}
]
})
};

fetch('https://api.togai.com/ingestBatch', 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.togai.com/ingestBatch",
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' => [
[
'timestamp' => '2022-06-15T07:30:35.123',
'schemaName' => 'travelCompletedEvent',
'id' => 'c0b1306d-f506-43a6-856b-69221efaee6b',
'accountId' => '1',
'attributes' => [
[
'name' => 'distanceTravelled',
'value' => '50',
'unit' => 'Miles'
],
[
'name' => 'timeSpent',
'value' => '60',
'unit' => 'Minutes'
]
],
'dimensions' => [
'location' => 'Seattle',
'costCenterCode' => '1234',
'travelType' => 'Business'
]
],
[
'timestamp' => '2022-06-15T07:30:35.123',
'schemaName' => 'sendMessageEvent',
'id' => 'c0b1306d-f506-43a6-856b-69221efaee6c',
'accountId' => '1',
'attributes' => [
[
'name' => 'messageSentCount',
'value' => '50',
'unit' => 'None'
],
[
'name' => 'sizeOfMessage',
'value' => '60',
'unit' => 'KiloBytes'
]
],
'dimensions' => [
'location' => 'Seattle',
'costCenterCode' => '1234',
'messageProviderName' => 'Twilio'
]
]
]
]),
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.togai.com/ingestBatch"

payload := strings.NewReader("{\n \"events\": [\n {\n \"timestamp\": \"2022-06-15T07:30:35.123\",\n \"schemaName\": \"travelCompletedEvent\",\n \"id\": \"c0b1306d-f506-43a6-856b-69221efaee6b\",\n \"accountId\": \"1\",\n \"attributes\": [\n {\n \"name\": \"distanceTravelled\",\n \"value\": \"50\",\n \"unit\": \"Miles\"\n },\n {\n \"name\": \"timeSpent\",\n \"value\": \"60\",\n \"unit\": \"Minutes\"\n }\n ],\n \"dimensions\": {\n \"location\": \"Seattle\",\n \"costCenterCode\": \"1234\",\n \"travelType\": \"Business\"\n }\n },\n {\n \"timestamp\": \"2022-06-15T07:30:35.123\",\n \"schemaName\": \"sendMessageEvent\",\n \"id\": \"c0b1306d-f506-43a6-856b-69221efaee6c\",\n \"accountId\": \"1\",\n \"attributes\": [\n {\n \"name\": \"messageSentCount\",\n \"value\": \"50\",\n \"unit\": \"None\"\n },\n {\n \"name\": \"sizeOfMessage\",\n \"value\": \"60\",\n \"unit\": \"KiloBytes\"\n }\n ],\n \"dimensions\": {\n \"location\": \"Seattle\",\n \"costCenterCode\": \"1234\",\n \"messageProviderName\": \"Twilio\"\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.togai.com/ingestBatch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"events\": [\n {\n \"timestamp\": \"2022-06-15T07:30:35.123\",\n \"schemaName\": \"travelCompletedEvent\",\n \"id\": \"c0b1306d-f506-43a6-856b-69221efaee6b\",\n \"accountId\": \"1\",\n \"attributes\": [\n {\n \"name\": \"distanceTravelled\",\n \"value\": \"50\",\n \"unit\": \"Miles\"\n },\n {\n \"name\": \"timeSpent\",\n \"value\": \"60\",\n \"unit\": \"Minutes\"\n }\n ],\n \"dimensions\": {\n \"location\": \"Seattle\",\n \"costCenterCode\": \"1234\",\n \"travelType\": \"Business\"\n }\n },\n {\n \"timestamp\": \"2022-06-15T07:30:35.123\",\n \"schemaName\": \"sendMessageEvent\",\n \"id\": \"c0b1306d-f506-43a6-856b-69221efaee6c\",\n \"accountId\": \"1\",\n \"attributes\": [\n {\n \"name\": \"messageSentCount\",\n \"value\": \"50\",\n \"unit\": \"None\"\n },\n {\n \"name\": \"sizeOfMessage\",\n \"value\": \"60\",\n \"unit\": \"KiloBytes\"\n }\n ],\n \"dimensions\": {\n \"location\": \"Seattle\",\n \"costCenterCode\": \"1234\",\n \"messageProviderName\": \"Twilio\"\n }\n }\n ]\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.togai.com/ingestBatch")

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 \"timestamp\": \"2022-06-15T07:30:35.123\",\n \"schemaName\": \"travelCompletedEvent\",\n \"id\": \"c0b1306d-f506-43a6-856b-69221efaee6b\",\n \"accountId\": \"1\",\n \"attributes\": [\n {\n \"name\": \"distanceTravelled\",\n \"value\": \"50\",\n \"unit\": \"Miles\"\n },\n {\n \"name\": \"timeSpent\",\n \"value\": \"60\",\n \"unit\": \"Minutes\"\n }\n ],\n \"dimensions\": {\n \"location\": \"Seattle\",\n \"costCenterCode\": \"1234\",\n \"travelType\": \"Business\"\n }\n },\n {\n \"timestamp\": \"2022-06-15T07:30:35.123\",\n \"schemaName\": \"sendMessageEvent\",\n \"id\": \"c0b1306d-f506-43a6-856b-69221efaee6c\",\n \"accountId\": \"1\",\n \"attributes\": [\n {\n \"name\": \"messageSentCount\",\n \"value\": \"50\",\n \"unit\": \"None\"\n },\n {\n \"name\": \"sizeOfMessage\",\n \"value\": \"60\",\n \"unit\": \"KiloBytes\"\n }\n ],\n \"dimensions\": {\n \"location\": \"Seattle\",\n \"costCenterCode\": \"1234\",\n \"messageProviderName\": \"Twilio\"\n }\n }\n ]\n}"

response = http.request(request)
puts response.read_body
{
  "success": true
}
{
"success": true,
"statusCode": 123,
"name": "<string>",
"message": "<string>",
"code": "<string>",
"details": {}
}
{
"message": "<string>"
}
{
"message": "<string>"
}
{
"message": "<string>"
}
{
"message": "<string>"
}
{
"message": "<string>"
}
{
"message": "<Reason message>"
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Request body to ingest events in batch to Togai usage and billing management service.

Payload for ingesting batch events

events
object[]
required
Required array length: 1 - 1000 elements

Response

Successfully accepted to process all the events from payload.

success
boolean
Example:

true

statusCode
integer<int32>
name
string
message
string
Maximum string length: 500
code
string
details
object