I am using the javascript admin api to upload content. It uploads fine as a draft, but I would like for it to have published status.
My api call looks like this:
api.posts
.add(
{ title: json["EventItemsx"]["EventBodyName"], html },
{ source: "html" },
{ status: "published"}
)
I got that last parameter from
where it gives this example below, but the result is still a draft post. On displaying the response from the api call, I get:
…
status: ‘draft’,
…
Which matches the status in the admin posts screen itself.
From API Documentation:
Required fields: title
Create draft and published posts with the add posts endpoint. All fields except title
can be empty or have a default that is applied automatically. Below is a minimal example for creating a published post with content:
// POST /admin/posts/
{
"posts": [
{
"title": "My test post",
"lexical": "{\"root\":{\"children\":[{\"children\":[{\"detail\":0,\"format\":0,\"mode\":\"normal\",\"style\":\"\",\"text\":\"Hello, beautiful world! 👋\",\"type\":\"extended-text\",\"version\":1}],\"direction\":\"ltr\",\"format\":\"\",\"indent\":0,\"type\":\"paragraph\",\"version\":1}],\"direction\":\"ltr\",\"format\":\"\",\"indent\":0,\"type\":\"root\",\"version\":1}}",
"status": "published"
}
]
}