Use the Airfold API to send data directly to your workspace. No intermediary database, storage, or batching layer required!

Create a Source

Before you can send data to your workspace, you first need to create a Source and define its schema. Follow the instructions in the Sources section to create a Source using either the UI or CLI.

Ingest

Now that you have your Source, you can ingest data into it with a few lines of code.

Replace source_name and api_key with your actual Source name and API key. Define the data to ingest using the data variable:

const data = [
  {<key>:<value>}
];

fetch('https://api.us.airfold.co/v1/events/<source_name>', {
method: 'POST',
headers: {
Authorization: 'Bearer <api_key>',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});

Sources can ingest data in JSON format easily! Check out the page on JSON mapping to see how you can configure your Source schema to be able to ingest nested JSON.

Here are some examples in practice:

const data = [
  {
    "event_id": 1, "user_id": 117, "event_type": "purchase", "page_url": "/home", "timestamp": "2025-05-22 10:46:29Z", "referrer": "facebook.com"
  },
  {
    "event_id": 2, "user_id": 114, "event_type": "signup", "page_url": "/product/456", "timestamp": "2025-05-22 10:08:01Z", "referrer": "facebook.com"
  },
  {
    "event_id": 3, "user_id": 118, "event_type": "page_view", "page_url": "/product/123", "timestamp": "2025-05-22 10:43:25Z", "referrer": "/product/123"
  },
  {
    "event_id": 4, "user_id": 103, "event_type": "purchase", "page_url": "/product/456", "timestamp": "2025-05-22 10:41:53Z", "referrer": "twitter.com"
  },
];

fetch('https://api.us.airfold.co/v1/events/web_events', {
method: 'POST',
headers: {
Authorization: aft_3paEjG6XBXA0examplekn6auth7tokenKPHSymSP1E,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});

Get Data Schema

You may also get the data source schema with the following API call:

const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

fetch('https://api.us.airfold.co/v1/events/<source_name>', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));