Looking for a function for generating posts. how in the sourcecode are posts generated? smth like testUtils.DataGenerator.forKnex.createPost

I want to have a post generated and added. I found in the source testUtils.DataGenerator.forKnex.createPost

is there a similar function for non test? for real life production environment.
So im looking for a function that takes some parameters like user id and post content and add this to the DB.
I’m sure there is a function like this and this can be done easily :slight_smile:

The Admin API has support for creating posts. I think you can specify the owner, but I’m not sure

When using an API Key authentication or user authentication with the editor/admin/owner role then you’re able to set the post authors to any users.

1 Like

yeah, i was thinking about this, but one functioncall like testUtils.DataGenerator.forKnex.createPost is easier and quicker then setting the whole API Key authentication and editor/admin/owner role thing up, that was exactly what i tried to omit :slight_smile:

or in the worst case something like:
but functioncalls would be nicer

const post = testUtils.DataGenerator.forKnex.createPost({
id: ObjectId.generate(),
title: ‘Post with email-only card’,
slug: ‘email-only-card’,
mobiledoc: ‘{“version”:“0.3.1”,“atoms”:,“cards”:[[“email”,{“html”:“

Hey {first_name \“there\”} {unknown}

Welcome to your first Ghost email!


Another email card with a similar replacement, {first_name, \“see?\”}

”}]],“markups”:,“sections”:[[10,0],[1,“p”,[[0,,0,“This is the actual post content…”]]],[10,1],[1,“p”,]]}’,
html: ‘

This is the actual post content…

plaintext: ‘This is the actual post content…’,
status: ‘draft’,
uuid: ‘d52c42ae-2755-455c-80ec-70b2ec55c904’
        return models.Post.add(post, {context: {internal: true}}).then(() => {`

this seems to do what im looking for