Creating BlogPost via Backend Code

Hello Community,

I’m facing a problem referred to creating a Blogpost via Backend Code. I tried different ways to do this.

I tried to add a new Database Entry using this library ‘wix-data’ without any progress. I can read a existing Blogpost, but I´m not able to create a new one.

My Code looks something like that:

async function createBlogPost(title, content, keywords) {
// Das relevanteste Keyword auswählen
const relevantKeyword = getRelevantKeyword(keywords);

// Bilder von Pixabay abrufen
const imageURLs = await fetchImageURLPIXABay(relevantKeyword);

// Bilder in den Text einbetten
const newContent = await embedImagesInText(content, imageURLs);

// Blogbeitrag erstellen
const postToCreate = {
title: title,
plaincontent: content,
//excerpt: content,
richcontent: content, //newContent.split(‘\n’).map(p => <p>${p}</p>).join(‘’), // Formatierung für Wix Blog
//coverimage: imageURLs[0] || ‘’, // Erstes Bild als Hauptbild verwenden
tags: keywords // Keywords als Tags hinzufügen
};

try {
const createdPost = await wixData.insert(‘Blog/Posts’, postToCreate);

return createdPost;
console.log(‘Blogbeitrag erstellt:’, createdPost);
} catch (err) {
console.error(‘Fehler beim Erstellen des Blogbeitrags:’, err);
}

My second approach was to use the library ‘wix-blog-backend’. Here I cant find any method like createPost or addPost in the class posts. What can I do to create a new Blogpost via Backend Code. If its only possibility to create a draft, before it can be converted into a Blogpost this is fine for me.

Any suggestions are very appreciated.

Thanks in advance. :slightly_smiling_face:
Kind Regards
Michael

Thanks for your reply. Can you give me a concrete example or a hint where I can find some examples.