I am struggling to pull data from a Strapi API data object.
api.js
export async function apiConnect() {
let headersList = {
"Authorization": "Bearer ####"
}
let response = await fetch("####", {
method: "GET",
headers: headersList
});
let data = await response.text();
return data;
}
index.astro
---
import { apiConnect } from '../../lib/api';
const strapiPage = await apiConnect();
---
<main>
<p>Page loading...</p>
{ strapiPage }
</main>
This outputs an object of data. As shown in the image.
The problems come when I try to extract specific data from the object. Example…
{ strapiPage.data.attributes.clientCompany }
This returns an error Cannot read properties of undefined (reading 'attributes') (Second screen shot)
Help would be appreciated