Connection to Google Sheets

Google Sheets is part of Google Office. Since it already contains an ‘Import XML’ function, the toolbox API data can be imported quickly and easily. We will show you how it works in this document.

Google Sheets, formerly known as Google Docs, is Google’s web-based answer to Microsoft Excel. It runs fully in your browser and saves all data to the Google Cloud. Therefore, it is not locked to one platform and a document can be viewed and edited by many users at the same time.

Create a new Sheets documents

In the first step, we will create a new Sheets document in Google Docs. To do that, go to the following URL in your browser:

https://docs.google.com/spreadsheets/u/0/

Now click on the big red plus button in the bottom right corner of your browser. A new Sheets document is created and you can start editing right away.

Linking the API using importXML

With the importXML function, Google Sheets gives you the option of importing external XML content into your Sheets document. Since the SISTRIX API also delivers the data in XML format, it is easy to link both systems.

To use this function, simply type into a cell beginning with an equals sign and add two data points:

=importXML("URL"; "XPath-Request")

In the URL field, you must enter the exact URL of the SISTRIX API including your API key and all parameters. You can request or view your API key on this site. An overview of all API methods is available in the existing documentation. In order to retrieve the domain overview for the domain sistrix.de, for example, enter this URL:

https://api.sistrix.com/domain.overview?api_key=YOURAPIKEY&domain=sistrix.de

The second field of the function describes the exact data from the XML response that should be copied into your Google spreadsheet. This description is given as an XPath definition. XPath may look a bit cryptic at first, but you will pick it up very quickly and the answers to the SISTRIX API only contain simple XML.

With an XPath tester like the one from Codebeautify.org, you can achieve results quickly. On that page, you can load the XML of the API with the button “Load URL” and test possible XPath variations at the bottom. You will then see the result on the right hand side.

In the above example, you get the domain overview of the page with this expression:

//@value

Put together, you can enter this function into the spreadsheet cell:

=importXML("https://api.sistrix.com/domain.overview?api_key=YOURAPIKEY&domain=sistrix.de"; "//@value")

After entering the function, Google will execute the API request for you and insert the current data from the SISTRIX API into your Google spreadsheet. All other API methods can be incorporated analogously to this process.

Further Sources