Example Request
In this very basic example, it is assumed that we are accessing the API from a web browser and we would like to get a timeline of the last 60 days showing the number of new, active, and lost users. Normally, the target URL should be used to set the target URL of an iframe, however, for testing, you may simply paste the URL in the browser address bar.
In this example, we are using cookie-based authentication. Since we are getting the data using GET requests, the API server will automatically redirect us to the login page if we are not already logged in. Therefore, we do not need to worry about authentication at this stage.
• | Building the JSON Request Object |
• | Encoding the Request and Getting the Data |
Building the JSON Request Object
The following is the JSON object which we will be sending as the request. For this example, we will be requesting data from the demo product account.
{
"productId": 2376158762,
"startDate": "NOW-60",
"stopDate": "NOW",
"dateSplit": "day",
"clientStatus": [
"new",
"active",
"lost"
],
"daysUntilDeclaredLost": 30,
"dateReportedLost": "dateDeclaredLost"
}
Encoding the Request and Getting the Data
The JSON object should be sent as part of the request URL in a parameter named “query”. In this case, the URL should be as follows:
https://api.revulytics.com/reporting/generic/dateRange?query={"productId":2376158762,"startDate":"NOW-60","stopDate":"NOW","dateSplit":"day","clientStatus":["new","active","lost"],"daysUntilDeclaredLost":30,"dateReportedLost":"dateDeclaredLost"}&resultFormat=highcharts&hcType=line
The “query” value needs to be URL encoded. All modern browsers automatically apply URL encoded to unencoded parameter values. However, it is always recommended to apply encoding before sending the URL. In such case, the encoded URL would be as follows:
https://api.revulytics.com/reporting/generic/dateRange?query=%7B%22productId%22%3A2376158762%2C%22startDate%22%3A%22NOW-60%22%2C%22stopDate%22%3A%22NOW%22%2C%22dateSplit%22%3A%22day%22%2C%22clientStatus%22%3A%5B%22new%22%2C%22active%22%2C%22lost%22%5D%2C%22daysUntilDeclaredLost%22%3A30%2C%22dateReportedLost%22%3A%22dateDeclaredLost%22%7D&resultFormat=highcharts&hcType=line