Hi,
I’m not able to understand where I’m doing wrong i tried everything but still not able to understand why it is happening. I already read the Wix data reference, get() & article but not able to figure out.
Website based on 3rd party API
Calling from backend to frontend using database stored value
My backend code:
import { fetch } from 'wix-fetch';
import wixData from 'wix-data';
export async function getData() {
const apiKey = "myAPIKey";
let id = await wixData.get('myDatabaseName', 'title') // database field key - 'title' where i store all the values to call vai API
.then((results) => {
let item = results;
})
.catch((err) => {
let errorMsg = err;
});
const response = await fetch("urlgoeshere.com/example/par&id=" + id.title + "&key=" + apiKey, {
method: 'get'
});
if (response.status >= 200 && response.status < 300) {
const res = await response.json();
return res;
}
let res = await response.json();
return res;
}
My front end code:
import { getData } from 'backend/datub.jsw';
$w.onReady(function () {
getData()
.then((response) => {
let chName = response.items[0].snip.example;
$w("#chtName").text = chName;
});
});