JSON via HTTP/S

JSON via HTTP/S

Ship JSON logs using HTTP/S to your Logit.io Stack

Use the HTTP/S API to send individual JSON logs or batches from your applications to a Logit.io Stack.

For managing stacks and alerts programmatically, see the Developer API.

Logs

Install Integration

Please click on the Install Integration button to configure your stack for this source.

Requirements

  • Use POST or PUT to https://@logitApiEndpoint/v2 to send one JSON object, a JSON array of objects, or newline-delimited JSON (NDJSON). Send 1 to 1,000 events per request. Each event becomes a separate log with the same LogType.
  • For a JSON object or array, use Content-Type: application/json. The API also accepts application/*+json, such as application/example+json. For NDJSON, use application/x-ndjson, application/ndjson or application/jsonl. Send one UTF-8 JSON object per line. The API ignores blank lines.
  • Send an uncompressed body. Invalid bodies, including gzip-compressed bodies sent with a supported content type, return HTTP 400 with {"message":"Invalid request body"}. A missing or unsupported content type returns HTTP 415 with {"message":"You didn't send application/json"}.
  • Authenticate with your stack's API key, a UUIDv4. The examples populate the key and endpoint when you sign in and select a stack.
  • Optionally set LogType. It sets the Logstash type field and can select a downstream filter branch. The default is general, which parses the JSON object's fields into the document root.

Use one of these credential methods, listed in order of precedence.

  1. ApiKey: @apikey (recommended)
  2. Api-Key: @apikey
  3. Authorization: Splunk @apikey or HTTP Basic with any username and the API key as the password. For Basic, Base64-encode the entire anything:@apikey credential.
  4. ?token=@apikey as a query parameter. Prefer a header to keep credentials out of URLs.

If the selected header supplies no key, the API falls back to ?token=. Bearer authentication is unsupported.

Send a single JSON log

curl -i "https://@logitApiEndpoint/v2" \
  -H "ApiKey: @apikey" \
  -H "Content-Type: application/json" \
  --data-binary '{"message":"Application started","level":"info"}'

Send JSON log files

Send the whole file in one request. Use --data-binary to preserve line endings, which separate events in NDJSON.

Save this as events.json.

[
  {"id":"example-1","message":"Application started"},
  {"id":"example-2","message":"Application stopped"}
]
curl -i "https://@logitApiEndpoint/v2" \
  -H "ApiKey: @apikey" \
  -H "Content-Type: application/json" \
  --data-binary @events.json

Sending many logs (batching)

Send JSON arrays or NDJSON to /v2. Split larger files into separate requests, each with at most 1,000 events and within the byte limit below. If you use a Splunk-compatible sender, you can use the Splunk HEC endpoint.

If you added a json_array split filter to your Logstash pipeline for JSON arrays, you can remove it and the LogType: json_array header. The API now splits arrays into individual logs.

Responses, limits and retries

A successful request returns HTTP 202. The API has queued all events for processing. They may take time to appear in OpenSearch.

HTTP/1.1 202 Accepted
Content-Type: application/json
 
{"message":"Message Received, Thanks"}
HTTP statusResponse or action
202 AcceptedAll events queued.
400 Bad Request{"message":"Invalid request body"}. The body is malformed JSON or contains an invalid NDJSON line, a non-object event, a JSON scalar where an object or array is required, or a non-standard number (NaN, Infinity or -Infinity). Empty bodies and batches also return 400.
401 UnauthorizedMissing authentication credentials or apikey not a valid GUID. Check the stack's API key and how you send it.
403 Forbidden{"message":"Logit.io stack disabled or cancelled - remove this log drain or shipper","code":"stack_disabled"}
413 Payload Too Large{"message":"The data value transmitted exceeds the capacity limit."} if the request body or an event serialised for processing exceeds 9,800,000 bytes. {"message":"Too many events"} if the batch exceeds 1,000 events.
415 Unsupported Media Type{"message":"You didn't send application/json"}. Set a supported Content-Type.
503 Service Unavailable{"message":"Service temporarily unavailable, retry later"} with Retry-After: 5 (seconds).
429 or other 5xxRetry with backoff. Honour Retry-After when present.

The HTTP 403 response above applies to /v2 and other non-HEC HTTPS ingestion routes. A well-formed API key that does not belong to an active stack gets the same response. If you used a newly created stack's key before the stack was ready, it may take up to 5 minutes for the API to accept the key.

The API validates the whole batch before queueing any events. A single invalid event rejects the batch.

Set connection and request timeouts where your client supports them. Start with a 3-second connection timeout and a 10-second request or read timeout. Retry connection errors, timeouts, HTTP 429 and 5xx (including 503). Honour Retry-After when present, limit retry attempts and use capped exponential backoff with jitter.

Fix HTTP 400, 401, 403, 413 and 415 errors before sending again. For HTTP 403, remove the log drain or shipper (for example, use heroku drains:remove for a Heroku drain) or update it with an active stack's API key.

For up to 5 attempts:
  Send with a timeout. On HTTP 202, finish.
  If this is the last attempt, report the failure and stop.
  If the failure is anything other than a connection error, timeout, HTTP 429 or HTTP 5xx, report it and stop.
  Wait a random time between 0 and min(30 seconds, 2^retry seconds).
  If Retry-After calls for a longer wait, use that delay.

A connection failure can occur after queueing, and HTTP 503 can occur after part of a batch has been queued. Retrying the request can duplicate events from either a /v2 or a HEC batch. Include a stable, unique ID in each event and use it to de-duplicate downstream.

Client examples

Set LOGIT_API_KEY in your environment to your stack's API key before running an example.

import os
 
import requests
 
response = requests.post(
    "https://@logitApiEndpoint/v2",
    headers={"ApiKey": os.environ["LOGIT_API_KEY"]},
    json={"message": "Application started", "level": "info"},
    timeout=(3, 10),
    allow_redirects=False,
)
if response.status_code != 202:
    raise RuntimeError(f"Logit.io returned HTTP {response.status_code}")

Launch OpenSearch Dashboards to View Your Data

Launch OpenSearch Dashboards

How to diagnose no data in Stack

If you don't see data appearing in your stack after following this integration, take a look at the troubleshooting guide for steps to diagnose and resolve the problem or contact our support team and we'll be happy to assist.