This API allows you to send and load data into Axiom. You can use different methods to ingest logs depending on your requirements and log format.
Authorization and Headers
The only expected headers are the Authorization: Bearer
, which is your API or personal token. Learn more about API Token and Org ID.
Using Axiom JS library to ingest data
Axiom maintains the axiom-js to provide official Javascript bindings for the Axiom API.
Install using npm install
:
If you use the Axiom CLI, run eval $(axiom config export -f)
to configure your environment variables.
Otherwise create a personal token in the Axiom settings and export it as AXIOM_TOKEN
. Set AXIOM_ORG_ID
to the organization ID from the settings page of the organization you want to access.
You can also configure the client using options passed to the constructor of the Client:
const client = new Client({
token: process.env.AXIOM_TOKEN,
orgId: process.env.AXIOM_ORG_ID,
});
Create and use a client like this:
import { Axiom } from '@axiomhq/js';
async function main() {
const axiom = new Axiom({
token: process.env.AXIOM_TOKEN,
orgId: process.env.AXIOM_ORG_ID,
});
await axiom.ingest('my-dataset', [{ foo: 'bar' }]);
const res = await axiom.query(`['my-dataset'] | where foo == 'bar' | limit 100`);
}
These examples send an API event to Axiom. Before getting started with Axiom API, you need to create a Dataset and API Token.
Ingest Events using JSON
The following example request contains grouped events. The structure of the JSON
payload should have the scheme of [ { "labels": { "key1": "value1", "key2": "value12" } }, ]
, in which the array comprises of one or more JSON objects describing Events.
Example Request using JSON
curl -X 'POST' 'https://api.axiom.co/v1/datasets/$DATASET_NAME/ingest' \
-H 'Authorization: Bearer $API_TOKEN' \
-H 'Content-Type: application/json' \
-d '[
{
"time":"2021-23-04302:11:23.222Z",
"data":{"key1":"value1","key2":"value2"}
},
{
"data":{"key3":"value3"},
"labels":{"key4":"value4"}
}
]'
Example Response
A successful POST Request returns a 200
response code JSON with details:
{
"ingested": 2,
"failed": 0,
"failures": [],
"processedBytes": 219,
"blocksCreated": 0,
"walLength": 8
}
Example Request using Nested Arrays
curl -X 'POST' 'https://api.axiom.co/v1/datasets/$DATASET_NAME/ingest' \
-H 'Authorization: Bearer $API_TOKEN' \
-H 'Content-Type: application/json' \
-d '[
{
"axiom": [{
"logging":[{
"observability":[{
"location":[{
"credentials":[{
"datasets":[{
"first_name":"axiom",
"last_name":"logging",
"location":"global"
}],
"work":[{
"details":"https://app.axiom.co/",
"tutorials":"https://www.axiom.co/blog",
"changelog":"https://www.axiom.co/changelog",
"documentation": "https://www.axiom.co/docs"
}]
}],
"social_media":[{
"details":[{
"twitter":"https://twitter.com/AxiomFM",
"linkedin":"https://linkedin.com/company/axiomhq",
"github":"https://github.com/axiomhq"
}],
"features":[{
"datasets":"view logs",
"stream":"live_tail",
"explorer":"queries"
}]
}]
}]
}],
"logs":[{
"apl": "functions"
}]
}],
"storage":[{}]
}]}
]'
Example Response
A successful POST Request returns a 200
response code JSON with details:
{
"ingested":1,
"failed":0,
"failures":[],
"processedBytes":1509,
"blocksCreated":0,
"walLength":6
}
Example Request using Objects, Strings, and Arrays
curl -X 'POST' 'https://api.axiom.co/v1/datasets/$DATASET_NAME/ingest' \
-H 'Authorization: Bearer $API_TOKEN' \
-H 'Content-Type: application/json' \
-d '[{ "axiom": {
"logging": {
"observability": [
{ "apl": 23, "function": "tostring" },
{ "apl": 24, "operator": "summarize" }
],
"axiom": [
{ "stream": "livetail", "datasets": [4, 0, 16], "logging": "observability", "metrics": 8, "dashboard": 10, "alerting": "kubernetes" }
]
},
"apl": {
"reference":
[[80, 12], [30, 40]]
}
}
}]'
Example Response
A successful POST Request returns a 200
response code JSON with details:
{
"ingested":1,
"failed":0,
"failures":[],
"processedBytes":432,
"blocksCreated":0,
"walLength":7
}
Example Response
A successful POST Request returns a 200
response code JSON with details:
{
"ingested": 6,
"failed": 0,
"failures": [],
"processedBytes": 236,
"blocksCreated": 0,
"walLength": 6
}
Ingest Events using CSV
The following example request contains events. The structure of the CSV
payload uses a comma to separate values 'value1, value2, value3'
.
Example Request using CSV
curl -X 'POST' 'https://api.axiom.co/v1/datasets/$DATASET_NAME/ingest' \
-H 'Authorization: Bearer $API_TOKEN' \
-H 'Content-Type: text/csv' \
-d 'user, name
foo, bar'
Example Response
A successful POST Request returns a 200 response code JSON with details:
{
"ingested": 1,
"failed": 0,
"failures": [],
"processedBytes": 28,
"blocksCreated": 0,
"walLength": 2
}
Datasets names are usually case sensitive, Dataset names must be between 1-128 characters, and may only contain ASCII alphanumeric characters and the ’-’ character.