---
title: Ingest events
slug: amberflo-api/ingest-events
docTags: 
createdAt: 2024-11-07T15:10:16.968Z
---

{
  "id": "qkI0qTPy0xwVlD0hy6gV9",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://app.amberflo.io/ingest",
    "servers": [
      {
        "url": "https://app.amberflo.io/ingest"
      }
    ],
    "name": "Ingest events",
    "description": "<p>Use this endpoint to ingest meter records.</p>\n<p>You can also send an array of records. For instance:</p>\n<pre><code class=\"language-json\">[{\n     \"customerId\": \"customer-123\",\n     \"meterApiName\": \"ComputeHours\",\n     \"meterValue\": 5,\n     \"meterTimeInMillis\": 1619445706909,\n     \"dimensions\": {\n        \"region\": \"us-west-2\",\n        \"az\": \"az1\"\n     }\n}, {\n    ...\n}]\n</code></pre>\n<p>We also support the <a href=\"https://github.com/ndjson/ndjson-spec\" target=\"_blank\">NDJSON</a> format, where each record is separated by a newline. For instance:</p>\n<pre><code class=\"language-json\">{ \"customerId\": \"customer-123\", \"meterApiName\": \"ComputeHours\", \"meterValue\": 5, \"meterTimeInMillis\": 1619445706909 }\n{ \"customerId\": \"customer-321\", \"meterApiName\": \"ComputeHours\", \"meterValue\": 4, \"meterTimeInMillis\": 1619445712341 }\n{ \"customerId\": \"customer-123\", \"meterApiName\": \"ComputeHours\", \"meterValue\": 1, \"meterTimeInMillis\": 1619445783456 }\n</code></pre>",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "optional",
          "name": "body",
          "type": "array",
          "description": "",
          "customType": "ingestion.IngestMessage.in[]",
          "schema": [
            {
              "name": "uniqueId",
              "kind": "optional",
              "type": "string",
              "description": "Set this value in order to differentiate otherwise identical (same meter, customer, time, and dimensions) events.",
              "example": ""
            },
            {
              "name": "meterApiName",
              "kind": "optional",
              "type": "string",
              "description": "`meterApiName` as defined in [Meter API](ref:post_meters).\n\nRequired if `values` is not set or empty.",
              "example": ""
            },
            {
              "name": "meterValue",
              "kind": "optional",
              "type": "number",
              "description": "Meter value to be ingested. This will be used for aggregation.\n\nRequired if `values` is not set or empty.",
              "example": ""
            },
            {
              "name": "meterTimeInMillis",
              "kind": "required",
              "type": "integer<int64>",
              "description": "Meter event timestamp, in [Unix time](https://en.wikipedia.org/wiki/Unix_time) (milliseconds).",
              "example": 0
            },
            {
              "name": "customerId",
              "kind": "required",
              "type": "string",
              "description": "`customerId` as defined in [Customer API](ref:post_customers).",
              "example": ""
            },
            {
              "name": "dimensions",
              "kind": "optional",
              "type": "map",
              "description": "Dimension values for keys defined in `dimensions` in [Meter API](ref:post_meters).",
              "example": "",
              "customType": "map<string, string>",
              "schema": []
            },
            {
              "name": "variants",
              "kind": "optional",
              "type": "array",
              "description": "When set, each entry will be merged with the main fields to form the resulting ingest messages. This is a more flexible alternative to the `values` field.\n\nMay not be used together with the `values` field.",
              "modelRef": "#/components/schemas/ingestion.IngestMessage.Variant.in",
              "customType": "ingestion.IngestMessage.Variant.in[]",
              "schema": [
                {
                  "name": "meterApiName",
                  "kind": "optional",
                  "type": "string",
                  "description": "See the main `meterApiName` field.",
                  "example": ""
                },
                {
                  "name": "meterValue",
                  "kind": "optional",
                  "type": "number",
                  "description": "See the main `meterValue` field.",
                  "example": ""
                },
                {
                  "name": "dimensions",
                  "kind": "optional",
                  "type": "map",
                  "description": "See the main `dimension` field.",
                  "example": "",
                  "customType": "map<string, string>",
                  "schema": []
                }
              ]
            },
            {
              "name": "values",
              "kind": "optional",
              "type": "map",
              "description": "Map of `meterApiName` to `meterValue`. Use this field instead of the `meterApiName` and `meterValue` fields if you want to send multiple values in a single ingest message\n\nMay only be used if the fields `meterApiName`, `meterValue`, and `variants` are not.",
              "example": "",
              "customType": "map<string, number>",
              "schema": []
            }
          ],
          "modelRef": "#/components/schemas/ingestion.IngestMessage.in",
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": [
        {
          "id": "apiKey",
          "name": "X-API-KEY",
          "kind": "optional",
          "type": "apiKey",
          "in": "header"
        }
      ]
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "Successful request",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "string",
            "description": "",
            "isExpanded": true
          }
        ]
      }
    ],
    "examples": {
      "languages": [
        {
          "id": "9_1nvPYeCADdhJ_AyKyga",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://app.amberflo.io/ingest \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '[\n     {\n     \"meterTimeInMillis\": 0,\n     \"customerId\": \"\"\n     }\n     ]'"
        },
        {
          "id": "jUB88RZXOCmMg0ovCbDG7",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar raw = JSON.stringify([\n   {\n      \"meterTimeInMillis\": 0,\n      \"customerId\": \"\"\n   }\n]);\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://app.amberflo.io/ingest\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "Xv8-7-RwNT-LjuzTpAeTd",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://app.amberflo.io/ingest\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest.body = JSON.dump([\n   {\n      \"meterTimeInMillis\": 0,\n      \"customerId\": \"\"\n   }\n])\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "HIerIKA69zLPKxGseWLoZ",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://app.amberflo.io/ingest\"\n\npayload = json.dumps([\n   {\n      \"meterTimeInMillis\": 0,\n      \"customerId\": \"\"\n   }\n])\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "9_1nvPYeCADdhJ_AyKyga"
    },
    "results": {
      "languages": [
        {
          "id": "t2HPjTsMNekHFdWjwos2J",
          "language": "200",
          "code": "// Successful request\n\"\""
        }
      ],
      "selectedLanguageId": "t2HPjTsMNekHFdWjwos2J"
    }
  },
  "children": [
    {
      "id": "_ERUTdzjN1fq7xvFznJyU",
      "type": "paragraph",
      "children": [
        {
          "text": "Use this endpoint to ingest meter records."
        }
      ]
    },
    {
      "id": "3MrioT62CWq7ZdD00R8KX",
      "type": "paragraph",
      "children": [
        {
          "text": "You can also send an array of records. For instance:"
        }
      ]
    },
    {
      "id": "evzY2I8qrVBYAlHmY2bFy",
      "type": "code-editor-v2",
      "data": {
        "languages": [
          {
            "id": "5F6W-QJbbKNOFmd9wY3nQ",
            "language": "json",
            "code": "[{\n     \"customerId\": \"customer-123\",\n     \"meterApiName\": \"ComputeHours\",\n     \"meterValue\": 5,\n     \"meterTimeInMillis\": 1619445706909,\n     \"dimensions\": {\n        \"region\": \"us-west-2\",\n        \"az\": \"az1\"\n     }\n}, {\n    ...\n}]"
          }
        ],
        "selectedLanguageId": "5F6W-QJbbKNOFmd9wY3nQ"
      },
      "children": [
        {
          "text": ""
        }
      ]
    },
    {
      "id": "iVW0naOYpl0QvCA8KfW99",
      "type": "paragraph",
      "children": [
        {
          "text": "We also support the "
        },
        {
          "id": "hua-o5fOw-uEWaXBR1qmq",
          "type": "link",
          "data": {
            "href": "https://github.com/ndjson/ndjson-spec"
          },
          "children": [
            {
              "text": "NDJSON"
            }
          ]
        },
        {
          "text": " format, where each record is separated by a newline. For instance:"
        }
      ]
    },
    {
      "id": "r9IdS3zusun3cEGlDrBVs",
      "type": "code-editor-v2",
      "data": {
        "languages": [
          {
            "id": "bYaYLYzANc92yl4gC5Eo4",
            "language": "json",
            "code": "{ \"customerId\": \"customer-123\", \"meterApiName\": \"ComputeHours\", \"meterValue\": 5, \"meterTimeInMillis\": 1619445706909 }\n{ \"customerId\": \"customer-321\", \"meterApiName\": \"ComputeHours\", \"meterValue\": 4, \"meterTimeInMillis\": 1619445712341 }\n{ \"customerId\": \"customer-123\", \"meterApiName\": \"ComputeHours\", \"meterValue\": 1, \"meterTimeInMillis\": 1619445783456 }"
          }
        ],
        "selectedLanguageId": "bYaYLYzANc92yl4gC5Eo4"
      },
      "children": [
        {
          "text": ""
        }
      ]
    }
  ]
}