API Documentation
Wanting to utilize your Loggly information outside of the Dashboard? You can access your information from Loggly via Loggly's API which allows you to:
- Send and Retrieve Events
- Add, View or Delete inputs
- Add, View, or Delete devices
Loggly's API allows for easy access to your log data. Creating and utilizing data for use in application development and deployment without having to mess around with the dashboard. If you're in need of a python API check out Python Logging and Hoover
Sending Events via the APIs
Events can be sent into Loggly via syslog or HTTP POSTs. If you need to configure your servers to send Loggly data via a syslog based service, please refer to the Logging Configuration page.
To send in events via the APIs, through HTTP POSTs, you'll use the hostname logs.loggly.com (instead of the [subdomain].loggly.com format used by the other API calls). The APIs on the proxy cluster support both HTTP and HTTPs, and use a SHA-2 key in the URL for validation. These keys can be generated by creating an HTTP input type from the Input Management page on your Loggly account. Here's an example input URL:
http://logs.loggly.com/inputs/83e527d7-fad3-4d93-89da-0c2d8c0bcd6c
If your servers are located on AWS US-East-1, you can use the host ec2.logs.loggly.com to send logs to us without incurring transfer charges. We'll be adding deployments in other regions soon.
To create an HTTP input, login to your account, then navigate to the inputs tab. Click on the add input button at the bottom of the page and then provide an input name and description for the input:
Once you create an HTTP input, you'll be taken to the input detail page, which will contain the URL you can use to send data to that particular input. If you need to rotate the SHA-2 key associated to a particular input, you can click on the generate new URL button at the bottom of the input detail page.
Testing
You can test the newly created input by sending in some test POST data via curl:
curl -H "content-type:text/plain" -d "127.0.0.1 - there's no place like home" http://logs.loggly.com/inputs/83e527d7-fad3-4d93-89da-0c2d8c0bcd6c
Keep in mind that the SHA-2 key above is an example, and you'll need your own key in there for it to work!
If you don't have curl, you can use wget instead:
wget --quiet -O - --header "content-type:text/plain" --post-data "127.0.0.1 - there's no place like earth" http://logs.loggly.com/inputs/83e527d7-fad3-4d93-89da-0c2d8c0bcd6c
The JSON result from a POST to an input contains a response and timestamp:
{ 'response': 'ok' }
Encoding
If you are sending us events via HTTP, you must correctly encode your POST data. If we see a header with 'application/x-www-form-urlencoded' as the content-type, we'll convert it to JSON it before storing it in your account. If we see a header with 'text/plain' as the content-type, we will leave the content alone and store it as regular text in your account.
Both curl and wget incorrectly set the content-type to 'application/x-www-form-urlencoded' by default. You'll need to set the content-type to 'text/plain' to store plain text events in your HTTP inputs.
Note: Some tools or libraries may add the urlencoded header even though they may not actually encode the POST data. If you don't encode your POST data, but the headers are set, you may see your data converted to a strange JSON format.
Retrieving Events via the APIs
Loggly APIs are accessed using your account's subdomain. An example of a subdomain+loggly.com address is pixlcloud.loggly.com. Loggly's APIs require authentication, and OAuth, BASIC Auth, and cookie-based authentication are supported.
Note: The APIs methods documented below are the 'offical' APIs, but there are other methods that you may discover by sniffing the UI's traffic from your browser. If you happen to find and use these, please do so at your own risk. We will be adding more API calls here as soon as they are ready for public consumption. While we are keen on not changing the calls around on users we may from time to time be required to update the methods.
Here's the the layout of the URLs used to access our APIs:
http://[subdomain].loggly.com/api/[endpoint]
You can also use HTTPS for the accessing the APIs:
https://[subdomain].loggly.com/api/[endpoint]
Search Methods
The search methods can return raw events, meta data we know about the events, and summary data (facets) on the events. By default, search contexts are constrained to the last 24 hours (relative time) and search across all inputs and devices.
Search URI
/search/
HTTP GET
Provides search results from an account.
Required
| Property | Description |
| q | String to search. See the Search Guide for reference on the Loggly query language. |
Optional
| Property | Description |
| rows | Number of rows returned by search. Defaults to 10, maximum of 2000. |
| start | Offset for starting row. Defaults to 0. |
| from | Start time for the search. Defaults to NOW-24HOURS. |
| until | End time for the search. Defaults to NOW. |
| order | Direction of results returned, either 'asc' or 'desc'. Defaults to 'desc'. |
| callback | JSONP callback to receive a JSONP response. |
| format | Output format, either 'json', 'xml', 'csv', or 'text'. Defaults to 'json' |
| fields | Which fields should be output. One or more of the following separated by commas: 'id', 'timestamp', 'ip', 'inputname', 'text'. |
Note: When passing in time differences such as 'NOW-1DAY+1MINUTE', be sure you encode the '+' as %2B.
Sample Query
curl -u [user]:[pass] 'http://[subdomain].loggly.com/api/search?q=404'
JSON Output
{
"data": [
{
"timestamp": "2010-02-17 02:08:45.912-0700",
"inputname": "solrclient",
"ip": "127.0.0.1",
"text": "btpool0-87 SolrCore.execute INFO: [repo_6] webapp=/solr path=/select/ params={sort=timestamp+desc&start=0&q=404&version=2.2&rows=100} hits=7182 status=0 QTime=0 \n",
},
{
"timestamp": "2010-02-17 02:08:29.123-0700",
"inputname": "solrclient",
"ip": "127.0.0.1",
"text": "btpool0-87 SolrCore.execute INFO: [repo_6] webapp=/solr path=/select/ params={sort=timestamp+desc&start=0&q=404&version=2.2&rows=100} hits=7182 status=0 QTime=3 \n",
}
],
"numFound": 2070,
"context": {
"rows": 10,
"from": "NOW-1DAY",
"until": "NOW",
"start": 0,
"query": "404",
"order": "desc"
}
}
Facet URIs
/facets/date/ /facets/ip/ /facets/input/
HTTP GET
Provides faceted results from an account on either date, ip, or input fields. Facets return counts of events over a time range.
Required Parameters
| Property | Description |
| q | String to search. See the Search Guide for reference on the Loggly query language. |
Optional Parameters
| Property | Description |
| from | Start time for the search. Defaults to NOW-1HOUR. |
| until | End time for the search. Defaults to NOW. |
| buckets | Number of buckets the results are split into for a given time range. Defaults to 50. |
| gap | Set the gap time between buckets. Defaults to +1HOUR |
| facetby | Field to use for faceting the results. One of 'ip', 'inputname' or 'text'. |
| callback | JSONP callback to receive a JSONP response. |
| format | Output format, either 'json', 'xml', or 'text'. Defaults to 'json' |
Note: When passing in time differences such as 'NOW-1DAY+1MINUTE', be sure you encode the '+' as %2B.
Sample Query
curl -u [user]:[pass] "content-type:text/plain" 'http://[subdomain].loggly.com/api/facets/date/?q=404'
JSON Output
{
"numFound": 1484,
"gap": "+30MINUTES",
"gmt_offset": "-0700",
"start": 0,
"context": {
"rows": null,
"from": "NOW-1DAY/HOUR",
"until": "NOW+1HOUR/HOUR",
"start": 0,
"query": "404",
"order": "desc"
},
"data": {
"2010-05-13 11:00:00.123-0700": 3060,
"2010-05-13 15:57:10.223-0700": 1457,
"2010-05-13 20:54:20.232-0700": 5772,
"2010-05-14 06:48:40.233-0700": 1347,
"2010-05-14 01:51:30.235-0700": 644,
"2010-05-14 11:45:50.345-0700": 0
}
}
Inputs APIs
Methods to manage inputs associated with your Loggly account.
Where [id] is specific to the input you set up within Loggly. To find the correct ID:
- Go to the inputs dashboard
- Click on the link to your 514 input
- Look at the URL, you'll find the [id] at the end of the URL (e.g. https://[subdomain].loggly.com/inputs/[id])
Input
/inputs/[id]/
HTTP GET
Provides an input or list of inputs for an account. Use an input id to return only that id's info.
Sample Query
curl -u <username>:<password> 'http://<subdomain>.loggly.com/api/inputs/'
JSON Output for a non HTTP input
[
{
"name": "syslog",
"service": {
"name": "syslogudp",
"display": "Syslog UDP"
},
"created": "2010-09-09 20:19:47",
"discover": false,
"discover_time": "2010-10-25 20:30:56",
"id": 147,
"port": 13261,
"description": "Syslog from all app servers",
"devices": [
{
"ip": "10.0.20.20",
"resource_uri": "/api/devices/13",
"name": "app-raffy-old",
"id": 13
}
]
}
]
JSON Output for an HTTP input
{
"name": "httptest",
"service": {
"name": "HTTP",
"display": "HTTP"
},
"created": "2011-01-07 19:41:33",
"input_token": "9076bdc4-9ed7-403a-9c85-f02da2404054",
"id": 337,
"description": "This is an HTTP input"
}
Querying specific inputs
You can either use the ID in the URI to query a specific input or you can use it's name to do so. Here are two examples:
curl -u <username>:<password> 'http://<subdomain>.loggly.com/api/inputs/10'
This example queries the input with ID 10. Make sure you use the right ID. You cannot look at other user's inputs.
curl -u <username>:<password> 'http://<subdomain>.loggly.com/api/inputs/?name=mytestinput'
This example queries the input with name 'mytestinput'. You can use this in case you do not know the ID of an input. The name parameter works for all GET calls on the input API.
HTTP POST
Creates a new input on your account.
POST Parameters:
- name .. input name
- description .. description
- service .. syslogudp|syslogtcp|http|syslog_tls|syslogtcp_strip|syslogudp_strip
Sample Query
curl -u <username>:<password> "content-type:text/plain" -d 'name=My Input' -d 'description=My new super input' -d 'service=syslogtcp' 'http://<subdomain>.loggly.com/api/inputs/'
JSON Output
{
"name": "myinput",
"service": {
"name": "syslogtcp",
"display": "Syslog TCP"
},
"created": "2011-02-10 19:05:06",
"discover": true,
"discover_time": "2011-02-10 19:05:06",
"id": 416,
"port": 18249,
"description": "My new super input"
}
Add Device to Input
/inputs/<id>/adddevice/
HTTP POST
Programmatically adds the calling device to an input, allowing it to send the input data. See the Cloud Deployment page for more information on automatically enabling a server to send Loggly data. This call uses the requesting host's IP for the added device. If you need to add a different device, use the /devices/ call.
Sample Query
curl -X POST http://<username>:<password>@<subdomain>.loggly.com/api/inputs/<id>/adddevice/
Add Device to Syslog 514 Input
/inputs/<id>/add514
HTTP GET
Adds the calling device to a 514 UDP input's device list to allow it to send data. Required for devices that don't support changing port or protocol for their syslog transport. If you need to add a device from somewhere besides the device itself, use the /device/ call.
The GET request should be done on an input that is a UDP port 514 input in your account. The call will fail if you try to run this on another type of input.
Sample Query
wget http://<username>:<password>@<subdomain>.loggly.com/api/inputs/<id>/add514
Remove Device from Input
/inputs/<id>/removedevice/
HTTP POST
Programmatically removes the calling device from an input. This call uses the requesting host's IP for it to be removed. If you need to remove a different device, use the /devices/ call.
Sample Query
curl -X POST http://<username>:<password>@<subdomain>.loggly.com/api/inputs/<id>/removedevice/
Put Input into discovery mode
/inputs/<id>/discover
HTTP POST
Puts the input with ID <id> into discovery mode.
Sample Query
curl -X POST http://<username>:<password>@<subdomain>.loggly.com/api/inputs/<id>/discover
HTTP DELETE
Takes an input out of discovery mode.
Sample Query
curl -X DELETE http://<username>:<password>@<subdomain>.loggly.com/api/inputs/<id>/discover
Devices APIs
Methods to manage devices associated with your Loggly account.
/devices/[id]/
HTTP GET
Provides a device or list of devices for an account.
Sample Query
curl -u [user]:[pass] 'http://[subdomain].loggly.com/api/devices/'
JSON Output
[
{
"name": "",
"ip": "24.4.108.196",
"input": [
{
"name": "zoto",
"id": 248
},
{
"name": "test",
"id": 501
}
],
"id": 393,
"launched": "2010-08-18 15:46:01",
"resource_uri": "/api/devices/393"
}
]
HTTP POST
Adds a device to an input.
Required
| Property | Description |
| input_id | Integer id for the input which will receive data from this device. |
| ip | Quad octet IP address of device which will send data to the input. |
Sample Query
curl -d "content-type:text/plain" input_id=314 -d ip=20.20.20.20 http://[username]:[password]@[subdomain].loggly.com/api/devices/
HTTP DELETE
Deletes a device from an input.
Required
Device ID or Device IP
Sample Query
curl -X DELETE http://[username]:[password]@[subdomain].loggly.com/api/devices/15 curl -X DELETE http://[username]:[password]@[subdomain].loggly.com/api/devices/10.0.20.233
Response Codes
These are fairly standard HTTP/RESTful response codes. From time to time we'll use them in our replies to your queries.
| Status | Message | Description |
| 200 | OK | Indicates that the request was successful. |
| 201 | Created | The object was successfully created. This is for a POST call. |
| 204 | Deleted | The object was deleted. This pertains to DELETE calls. |
| 400 | Bad Request | Check your request parameters. You might be using an unsupported parameter or have a malformed something or another. |
| 401 | Unauthorized | Either your credentials specified were invalid. |
| 403 | Forbidden | User does not have privileges to execute the action. |
| 404 | Not Found | The resource you have referenced could not be found. |
| 409 | Conflict/Duplicate | There was some conflict. Most likely you are trying to create a resource that already exists. |
| 410 | Gone | You have referenced an object that does not exist. |
| 500 | Internal Server Error | There has been an error from which Loggly could not recover. We are likely notified when this happens. |
| 501 | Not Implemented | You are trying to access functionality that is not implemented. Yet. |
| 503 | Throttled | Like a needy child, you are overloading us with requests for events. Try again later. |
