We are happy to announce that the JSLogger API has been released, and now you can integrate the logs and statistics in your own application. In the previous article, we discussed how to easily setup JSLogger for logging in the browser. Today, we’ll show you how to use the Client API. All you need is a free JSLogger account and the Postman - REST Client (Chrome extension).
To authenticate to the JSLogger API, send a POST request to /login endpoint with your email and account password:
POST /login HTTP/1.1
You’ll get back a secret token associated with the account. Use this token as a GET or POST parameter in all subsequent requests. You can also find this token on the code page when you are logged in.
JSLogger treats every domain that you register as a new project, so, the JSON response will contain an ID, email, and a viewed_project_id. (see the image above)
Viewed_project_id is the “active domain” (the one that you are performing the data query on), and most of the operations use this id if the project_id parameter is omitted.
Sending a GET request to /manage/projects.json will give you a list of projects associated with your account. You can reuse the id of each project to query more data about it later on:
GET /manage/projects.json?token=218g2b14gfs1d321f308gd223f675ef0 HTTP/1.1
You’ll get back an array of projects, with the domain, membership information, daily log count and daily log limit (see the image above).
If you want to change the current project (viewed_project_id property), so you can query the data for another project by default, send a PUT request to /manage/profile.json/:id with viewed_project_id = new project id:
PUT /manage/profile.json/503f8f029892a54b44000030 HTTP/1.1
A GET request to /manage/stats.json will give you the total count of logs and events logged for the current project (viewed_project_id). (see the image bellow)
GET /manage/stats.json?token=218g2b14gfs1d321f308gd223f675ef0 HTTP/1.1
To view summary information about each log entry, such as the number of hits, the referrals and information about the browsers and operating systems, send a GET request to /manage/summaries.json:
GET /manage/summaries.json?token=218g2b14gfs1d321f308gd223f675ef0&type=log&q=script error&project_id=507b2244f962f49b21000034 HTTP/1.1
This will query all log entries that contain the term “script error” from the specified project. (see the image above) Please, keep in mind that if project_id is omitted, the viewed_project_id will be used. Check out the API reference for a description of the available URL parameters.
So far, we have covered only a part of the available operations. For more information, check out the JSLogger API reference. You have a bunch of other awesome things that you can do with it, like:
- register an account
- create a new project for a domain
- retrieve logs and events count
- retrieve, filter and sort log summaries
- show or hide log entries
- delete log entries
We’ve built a sample implementation of the JSLogger API on Rails for you as a proof of concept. Feel free to fork the source on GitHub: https://github.com/jslogger/jslogger-api-on-rails-example.
Tell us about the apps you would like to build on the JSLogger API, we are really curious to hear more about them. And if you have some feedback or suggestion on how to improve the API, please visit our Contact page and we’ll be glad to hear from you.