I'm making a web app using Wix and the API data won't display because of this error: Cannot read properties of undefined (reading 'orgao'). "Orgao" is one type of data the API provides. Here's the code:
FRONT-END
import {getCryptoCurrencyInfo} from 'backend/serviceModule';
$w.onReady(function () {
// Write your JavaScript here
});
export function button1_click(event, $w) {
getCryptoCurrencyInfo($w('#currencyInput').value)
.then(currencyInfo => {
$w('#result').text = "Orgao: " + currencyInfo[0].orgao + "\n"
+ "Evento: " + currencyInfo[0].evento + "\n"
});
}
BACK-END serviceModule.jsw
import {fetch} from 'wix-fetch';
export function getCryptoCurrencyInfo(month) {
const url = 'https://transparencia.tce.sp.gov.br/api/json/despesas/2018/1';
console.log("Url: " + url);
return fetch(url, {method: 'get'})
.then(response => response.json())
}
By the way, the names are a mix between a tutorial and my project, so don't get caught up on variables' names context. And the API doesn't require a token.
Help is much appreciated!