Created
November 26, 2024 05:37
-
-
Save ipanardian/c96a25f0d1a6f9ee6c919c613ee29b7b to your computer and use it in GitHub Desktop.
Looker API Custom Connector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getAuthType() { | |
| return { | |
| type: "NONE", | |
| }; | |
| } | |
| function getConfig() { | |
| var cc = DataStudioApp.createCommunityConnector(); | |
| var config = cc.getConfig(); | |
| config.newTextInput() | |
| .setId("apiEndpoint") | |
| .setName("API Endpoint") | |
| .setHelpText("Insert your API."); | |
| return config.build(); | |
| } | |
| function getSchema() { | |
| return { | |
| schema: [ | |
| { name: "id", label: "Product ID", dataType: "NUMBER" }, | |
| { name: "title", label: "Product Title", dataType: "STRING" }, | |
| { name: "description", label: "Description", dataType: "STRING" }, | |
| { name: "category", label: "Category", dataType: "STRING" }, | |
| { name: "price", label: "Price", dataType: "NUMBER" }, | |
| { name: "discountPercentage", label: "Discount Percentage", dataType: "NUMBER" }, | |
| { name: "rating", label: "Rating", dataType: "NUMBER" }, | |
| { name: "stock", label: "Stock", dataType: "NUMBER" }, | |
| { name: "tags", label: "Tags", dataType: "STRING" }, | |
| { name: "brand", label: "Brand", dataType: "STRING" }, | |
| { name: "sku", label: "SKU", dataType: "STRING" }, | |
| { name: "weight", label: "Weight", dataType: "NUMBER" } | |
| ] | |
| }; | |
| } | |
| function getData(request) { | |
| var url = request.configParams.apiEndpoint; | |
| var response = UrlFetchApp.fetch(url); | |
| var json = JSON.parse(response.getContentText()); | |
| var rows = []; | |
| json.products.forEach(function (product) { | |
| rows.push({ | |
| values: [ | |
| product.id, | |
| product.title, | |
| product.description, | |
| product.category, | |
| product.price, | |
| product.discountPercentage, | |
| product.rating, | |
| product.stock, | |
| product.tags.join(", "), | |
| product.brand, | |
| product.sku, | |
| product.weight | |
| ] | |
| }); | |
| }); | |
| return { | |
| schema: getSchema().schema, | |
| rows: rows | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment