Con Google Sheets y Google Apps Script podés crear funciones personalizadas que consuman APIs externas.
En este ejemplo vamos a obtener el valor del dólar oficial desde: https://dolarapi.com/v1/dolares/oficial
Crear la función:
1. Ir a Extensiones → Apps Script
2. Crear la siguiente función:
function DOLAR_OFICIAL() {
var url = "https://dolarapi.com/v1/dolares/oficial";
var response = UrlFetchApp.fetch(url);
var data = JSON.parse(response.getContentText());
return data.venta;
}
Cómo usarla en la hoja:
En cualquier celda:
=DOLAR_OFICIAL()
¿Qué está pasando?
UrlFetchApp.fetch(url) → hace la llamada HTTP
JSON.parse(...) → convierte la respuesta a objeto
data.venta → accede al valor de venta del dólar
Podemos devolver más datos (compra y venta):
function DOLAR_OFICIAL_COMPLETO() {
var url = "https://dolarapi.com/v1/dolares/oficial";
var response = UrlFetchApp.fetch(url);
var data = JSON.parse(response.getContentText());
return [
["Compra", "Venta"],
[data.compra, data.venta]
];
}
Uso:
=DOLAR_OFICIAL_COMPLETO()
Esto va a llenar dos columnas automáticamente.
