{How To} read an array from API Connector

If you want to consume content from an API that is an array or JSON and don’t like to have it converted to a meaningless junk of text, it will be almost impossible with the API Connector plugin.

But If you have access to the API (your AWS Lambda Gateway) you can change the output of the array to text by using JSON.stringify and then to use it in your Bubble.is Google Chart s, you convert it back to an array by using JSON.parse(). :grinning:

5 Likes

Hey @g111, nice idea!

You can do the same thing by changing the API Connector response type from JSON to Text, without the need for an intermediary server.

2 Likes

hey man could is this “Bubble.is Google Chart s” a plugin? i could only find payed plugins.

I ended up uisng Google Charts js code like this:

google.charts.load(‘visualization’, ‘1’, {

'packages': ['corechart', 'linechart']

});;

google.charts.setOnLoadCallback(drawChart);

function drawChart() {

var testet ='Result of step 1 (Lambda API - API_…)‘s body’;

console.log("Funkar det? "+testet);

var testetArray = JSON.parse(testet);

console.log("Array: "+testetArray);

  var dataTable = new google.visualization.arrayToDataTable(testetArray);

var options = {

chartArea: { left: 80, top: 10, width: '70%', height: '75%' },

hAxis: {

  title: 'Månad'

},

vAxis: {

  title: 'Öppningskurs'

},

backgroundColor: '#f1f8e9',

‘width’: 400,

    'height': 300

};

  var chart = new google.visualization.LineChart(document.getElementById('piechart'));

  chart.draw(dataTable, options);

};

But my API connector has stoped working for some unkown reason.