I am working on a Next.js 14 project combined with Ghost. I have used the include
parameter in the browse
function of posts
, but I am not receiving the response of each post item, including arrays of authors and tags. Below is my code snippet:
import GhostContentAPI from "@tryghost/content-api";
const api = new GhostContentAPI({
url: process.env.CMS_GHOST_API_URL as string,
key: process.env.CMS_GHOST_API_KEY as string,
// for NextJS version >= 14
makeRequest: async ({ url, method, params, headers }) => {
const apiUrl = new URL(url);
Object.keys(params).map((key) =>
apiUrl.searchParams.set(key, encodeURIComponent(params[key]))
);
try {
const response = await fetch(apiUrl.toString(), { method, headers });
const data = await response.json();
return { data };
} catch (error) {
console.error(error);
}
},
version: "v5.0",
});
export async function getPosts() {
return await api.posts
.browse({
limit: "all",
include: ["authors", "tags"],
})
.catch((err) => {
console.error(err);
});
}
export default api;
And this is the item in the array response:
{
id: '660e587bd742a80dc8800d57',
uuid: 'c269e884-b1ea-4040-af0a-d7927ba19b75',
title: 'My first post',
slug: 'my-first-post',
html: `<p><strong>Lorem Ipsum</strong> is simply dummy text of the printing and typesetting industry.</p>`,
comment_id: '660e587bd742a80dc8800d57',
feature_image: 'https://images.unsplash.com/photo-1599708153386-62bf3f035c78?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3wxMTc3M3wwfDF8c2VhcmNofDN8fGhhbm9pfGVufDB8fHx8MTcxMjIxNjI0Mnww&ixlib=rb-4.0.3&q=80&w=2000',
featured: false,
visibility: 'public',
created_at: '2024-04-04T07:36:27.000+00:00',
updated_at: '2024-04-09T03:05:13.000+00:00',
published_at: '2024-04-04T07:38:04.000+00:00',
custom_excerpt: null,
codeinjection_head: null,
codeinjection_foot: null,
custom_template: null,
canonical_url: null,
url: 'http://localhost:2368/my-first-post/',
excerpt: "Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
reading_time: 1,
access: true,
comments: false,
og_image: null,
og_title: null,
og_description: null,
twitter_image: null,
twitter_title: null,
twitter_description: null,
meta_title: null,
meta_description: null,
email_subject: null,
frontmatter: null,
feature_image_alt: null,
feature_image_caption: '<span style="white-space: pre-wrap;">Photo by </span><a href="https://unsplash.com/@anhlh?utm_source=ghost&utm_medium=referral&utm_campaign=api-credit"><span style="white-space: pre-wrap;">Hoang Anh</span></a><span style="white-space: pre-wrap;"> / </span><a href="https://unsplash.com/?utm_source=ghost&utm_medium=referral&utm_campaign=api-credit"><span style="white-space: pre-wrap;">Unsplash</span></a>'
}
Thanks for your time!