Custom Visualization to backend REST API

visualizations

(Pratik Khadloya) #1

Is it possible to call a backend REST api to get data for a custom visualization? Is there an example of the same?


(leticia.esparza) #2

Hey @tispratik,

I hope all is well! If the custom visualization is saved as a Look, we can utilize the run_look(look_id, result_format) endpoint to run the query via the API and retrieve the data in the format we declare. There is more information about this endpoint here. The only required information that we have to provide and pass through this endpoint is the Look ID of the corresponding custom visualization Look and the format we would like our results to be in. Let me know if I can clarify anything about this on my end!

Best,

Leticia


(Pratik Khadloya) #3

Thanks for your response Leticia. By REST API i mean our own custom data source, not Looker’s REST API.

I would want to fetch data from our backend API service.


(quinn.morrison) #4

Hi @tispratik,

Looker only supports data retrieval from a SQL-based database. In order to incorporate data from this custom data source into Looker, you would need to include it in your ETL. This workflow would generally take the form of a table(s) in your database that pulls data from the given API, and then gets queries by Looker to populate your custom visualization.

I hope that clarifies things!

Quinn


(Pratik Khadloya) #5

Not sure why my sentence is not clear, or i am getting replies from non-developers!! Its quite frustrating. Let me try it again:

I want to fetch data from our backend API service through a Jquery AJAX call from a custom visualization to fetch data and then call “update” or “updateAsync” function in the custom visualization to update data.

Is that possible?


(Max Corbin) #6

Hey @tispratik, I can help out here. Please keep your responses to other users and Looker support team members courteous. This space is a public user forum and Looker support team folks who reply to posts here are going above and beyond.

AJAX calls originating from inside of the visualization will be subject to the same constraints as any other client-side request. I think that this should work fine as long as you are not attempting to make any changes to the DOM outside of the iframe, and as long as you are not adding any prohibited HTML tags to the DOM inside of the iframe (like a <script> tag for example)

I double checked with one of our front-end developers and they couldn’t think of any reason why this would not work. They recommend putting your AJAX (or XMLHttpRequest) call in the updateAsync callback that you register in your custom viz code, which will be run by Looker every time the visualization needs to be refreshed for the user.

I’m sure you found our docs on custom visualizations already, but just in case, you can find the documentation for version 2 of the API here. Let me know if you have any further questions.