02 - Reporting API - Tutorial

This tutorial explains how to:

  • install a Google Chrome extension to send REST request
  • send a POST request with a JSON to generate a report
  • send multiple GET requests to check if the report is generated
  • send a GET request to retrieve the generated report

Before you start

You need a valid Smart AdServer account, which is enabled for API use. Request it from your service contact.

Installing a REST client extension on Google Chrome

Installing a REST client extension on Google Chrome
  • Open Google Chrome and install the DHC REST Client extension
  • Click Add to Chrome

Entry points

For this tutorial you will need these entry points:

Entry point description HTTP
method
URI
Generation of a report POST https://reporting.smartadserverapis.com/[NETWORK_ID]/reports
Get a task status GET https://reporting.smartadserverapis.com/[NETWORK_ID]/reports/[TASK_ID]
Get the last file generated by a report GET https://reporting.smartadserverapis.com/[NETWORK_ID]/reports/[TASK_ID]/file

Opening the REST client

Opening the REST client

Click on the extension's icon

Authorization

Authorization

Click Set an authorization and enter user name and password.

The base64 encoding is done DHC REST client - no manual encoding required

Generating a report

URI and method

URI and method
  • Copy the URI for the Generation of a report entry point
https://reporting.smartadserverapis.com/[NETWORK_ID]/reports
  • Replace [NETWORK_ID] by your network ID
  • Paste it into the URI field (1)
  • select the POST method (2)
  • this will open the Body field (3)

Request body

  • Specify the JSON for the report you wish to generate
  • Paste the JSON into the Body field
  • Click Send

The following example JSON requests the number of impressions per site name on 25 August 2016:

{ "startDate": "2016-08-25T00:00:00", "endDate": "2016-08-26T00:00:00", "fields": [{ "Impressions": {} }, { "SiteName": {} }] }

Response body

In the response body you will find:

  • a taskId; represents the task you created; in this example the taskId is: 49E8A149-C4DB-4547-922E-02ECCBB78C92
  • an instanceId; references the requested report
Response body

Getting task status

URI and method

URI and method

To check the status of the task:

  • Copy the URI for the Get a task status entry point:
https://reporting.smartadserverapis.com/[NETWORK_ID]/reports/[TASK_ID]
  • Replace [NETWORK_ID] by your network ID
  • Replace [TASK_ID] by the task ID received when the report was generated
  • Paste the URI into the URI field (1)
  • select the GET method (2)
  • click Send (3)

Response body

Below is an example response body. The instanceStatus of the lastTaskInstance shows "SUCCESS".

{
	"taskId": "49E8A149-C4DB-4547-922E-02ECCBB78C92",
	"status": "COMPLETE",
	"creationDateUTC": "Oct 4, 2016 3:59:17 PM",
	"taskStartDate": {
		"relativeDateBase": "FIXED_DATE",
		"modifier": 0,
		"fixedDate": "Aug 25, 2016 12:00:00 AM"
	},
	"taskEndDate": {
		"relativeDateBase": "FIXED_DATE",
		"modifier": 0,
		"fixedDate": "Aug 26, 2016 12:00:00 AM"
	},
	"originalJson": "{\n\t\"startDate\": \"2016-08-25T00:00:00\",\n\t\"endDate\": \"2016-08-26T00:00:00\",\n\t\"fields\": [{\n\t\t\"Impressions\": {}\n\t}, {\n\t\t\"SiteName\": {}\n\t}]\n}",
	"nbTaskInstance": 1,
	"lastTaskInstance": {
		"taskInstanceId": "6166BEDB-8F91-4A5E-824D-53F3345C5AE3",
		"instanceStatus": "SUCCESS",
		"creationDateUtc": "Oct 4, 2016 3:59:17 PM",
		"completionDateUTC": "Oct 4, 2016 3:59:18 PM",
		"statsMinDateUTC": "Aug 25, 2016 12:00:00 AM",
		"statsMaxDateUTC": "Aug 26, 2016 12:00:00 AM",
		"nbOutputLines": 5,
		"reportingTaskOutput": []
	}
}

If the status is not "SUCCESS", wait a few minutes and try again.

Getting latest report file

URI and method

URI and method

To retrieve the latest report file:

  • Copy the URI for the Get the last file generated by a report entry point
https://reporting.smartadserverapis.com/[NETWORK_ID]/reports/[TASK_ID]/file
  • Replace [NETWORK_ID] by your network ID
  • Replace [TASK_ID] by the task ID received when the report was generated
  • Paste the URI into the URI field (1)
  • select the GET method (2)
  • click Send to get the report file

Response body

Example of a response body:

Impressions;SiteName
428517;
79970;iplabel
74889;monsite
66;VideoTeam
1435;Smartadserver-IAB-Germany

Adjusting body view

Adjusting body view

If the response body reads "BINARY CONTENT" or "UNKNOWN CONTENT", make sure you change the view from preview to raw.

Was this article helpful?
1 out of 1 found this helpful
Powered by Zendesk