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
Requirements
- Use
POSTorPUTtohttps://@logitApiEndpoint/v2to 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 sameLogType. - For a JSON object or array, use
Content-Type: application/json. The API also acceptsapplication/*+json, such asapplication/example+json. For NDJSON, useapplication/x-ndjson,application/ndjsonorapplication/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 Logstashtypefield and can select a downstream filter branch. The default isgeneral, which parses the JSON object's fields into the document root.
Use one of these credential methods, listed in order of precedence.
ApiKey: @apikey(recommended)Api-Key: @apikeyAuthorization: Splunk @apikeyor HTTP Basic with any username and the API key as the password. For Basic, Base64-encode the entireanything:@apikeycredential.?token=@apikeyas 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.jsonSending 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 status | Response or action |
|---|---|
| 202 Accepted | All 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 Unauthorized | Missing 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 5xx | Retry 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 DashboardsHow 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.