Skip to main content
All CollectionsReporting
API- Get A Visualization Data
API- Get A Visualization Data
Astrato Support avatar
Written by Astrato Support
Updated over a month ago

Introduction

The Astrato SQL engine creates optimized queries to load the data into visualizations.
Using API calls, it's easy to get the data behind any visualization and use it in external tools.

The article covers getting the data from a visualization using an API Call.



Retrieve Visualization Data

  • Generate token

    The personal access token will authenticate the call to Astrato's API.
    To generate a token, follow this article.

  • Build the call in the API

    • We'll use Postman in this example.

    • Open the astrato app and navigate to the visualization that should be the source.

    • Open the developer tools in the browser (F12)

    • Refresh the page in the developer tool in the network tab, look for a query item

    • Click on the query, in the window that opens, select Headers from the top menu,
      Copy the request URL

    • Open Postman, paste the URL in the top input box and select POST as the call method.

    • In the menu, select Authorization and then choose the option from Bearer token.
      Paste the personal access token in the token window.

    • Go back to Astrato app, In the developer tools select Payload from the top menu and copy all the content from there, right click on the first line and select copy value.

    • Go back to Postman, navigate to Body, select Raw as the body type,
      Paste the Astrato payload in the body.
      The result should be similar to the image below.

    • Run the request in Postman, and the response will look like this:
      (the response includes additional parts and not just the data.


  • Get the visualization data.

    Using the response from the previous step, we can visualize the data in the response,
    To create a table that shows the data, add the script below to the Postman request in the script tab.

    <style type="text/css">
    .tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
    .tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
    .tftable tr {background-color:#ffffff;}
    .tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
    .tftable tr:hover {background-color:#e0ffff;}
    </style>
    <table class="tftable" border="1"> <tr> <th>Region</th> <th>Occupation</th> <th>Revenue Current YTD</th> <th>Revenue Previous YTD</th> <th>Revenue YOY%</th> </tr> {{#each response.response.data}} <tr> <td>{{0}}</td> <td>{{1}}</td> <td>{{2}}</td> <td>{{3}}</td> <td>{{4}}</td> </tr> {{/each}}</table>`;function constructVisualizerPayload() { return { response: pm.response.json() }}pm.visualizer.set(template, constructVisualizerPayload());

Select the option to visualize in the response and see the data.




Did this answer your question?