New to Telerik Reporting? Download free 30-day trial

Connecting to Google Books APIs

Environment

Product Progress® Telerik® Reporting
Version Q2 2012 and later
Report Viewers WinForms, WPF, ASP.NET

Description

How can I create a report which retrieves data from the Google Books APIs by using the WebServiceDataSource component?

Solution

To create a report and retrieve data from the Google Books APIs:

  1. Get access to the API by acquiring and using an API key according to the official Google documentation on using the API.

    Google Books Api Key

  2. After the API key is acquired, enable the Google Books API inside the Library menu or follow the direct Google Books API link.

  3. Create a new report by using the report designer of your choice. For the purposes of this guide, you will use the Standalone Report Designer.
  4. Select the DataSource property of the report and click the Add New Data Source... link. Choose the WebServiceDataSource component.

    Web Service Data Source Component

  5. Set up the web service HTTP request properties. For the purposes of this guide, you will retrieve books data from the APIs according to the search terms that are input as parameters in the report. Use the GET https://www.googleapis.com/books/v1/volumes?q={search terms} endpoint. You need to enter the exact service URL in the wizard page and select the appropriate HTTP request method. Since you will be using an API key, no authentication type is required at this point.

    Google Books Url

  6. Configure the HTTP request parameters. You need to send the API key with the query parameters, so add a key parameter with type Query and enter its Value from the first step.

    The Design-Time Value in this case will be the same key. It is used to retrieve the data schema and for the live preview of some data items during design-time. In addition, you will add a q and a maxResults query parameter according to the API reference which will be used to send the search terms and max number of results to the API.

    These API parameters will be connected to corresponding report parameters which you can control at run-time. To do that select <New Report Parameter> in the drop-down for the Value of the query parameter and follow the wizard to configure it.

    Google Books Params

  7. Preview the data source results. Click the Download button to retrieve the data according to the current settings and design-time parameters. The preview shows raw JSON data returned from the service. When the service returns a JSON array, the preview displays multiple rows of raw data. The Google Books API returns a single JSON object containing the items, kind, and totalItems properties. Note the items property which contains an array of the returned books filtered by the search terms.

    Google Books Download

  8. The data source of the report is now set and you can display the total count of books in the query result by dragging the totalItems data field from the Data Explorer to the Detail section on the report design surface. To create a more sophisticated message, use the following embedded expression:

    Found {Fields.totalItems} books related to "{Parameters.q.Value}".

  9. Since the data for the actual books is inside the items data field, you need to use a nested data item to display the inner book objects. Insert a new Table item into the Detail section of the report. Instead of creating a new data source for this table, reuse the already retrieved data from the data source of the report by adding a new Binding to the Table item:

    Google Books Binding

  10. Now that the binding for the data source is set, you can start writing expressions in the table cells to display the books data. Note that for the book authors, this scenario uses a Join()built-in function. The authors value is an array of strings and you can render all of the contained strings concatenated by a comma.

    When using Bindings for the data source, the data schema will not be available at design-time. You are required to manually write the data fields in expressions according to the used web service API.

    Google Books Table

  11. Preview the report to see the results.

    Google Books Preview

In this article