What i'm doing wrong?

#database #backend #corvid #repeater
My project is created with 3rd party API but the problem is when I declare const it will show the result in the frontend repeater but when I declare let val = wixData.get(“myDatabaseName”, ‘title’)
Error: Cannot read property ‘title’ of undefined

What I’m doing wrong please help me to understand this:
My backend Code

import { fetch } from 'wix-fetch';
import wixData from 'wix-data';

export async function getData() {

 const apiKey = "xxxxxxxxxxxxxxxxx";
 //const val = "xxxxxxxxx" it works when i decalre this
  
let val = await wixData.get('myDatabaseName', 'title') //title - myfieldkey where all values are saved to call in url 

        .then((results) => {
 let item = results;
        //console.log(item);
        })
        .catch((err) => {
 let errorMsg = err;
        });
const response = await fetch("url goes here &id=" + val.title + "&key=" + apiKey, {
        method: 'get'
    });

Front end code:

import { getData } from 'backend/getData.jsw';

$w.onReady(function () {

    getData()
        .then((response) => {
  let chName = response.items[0].title;
 //console.log(chName);
            $w("#chaName").text = chlName;
        });

});

Any idea @givemeawhisky

1 Like