How to set a page status by API

I try to setup a section-plugin, where editors can create a page and publish by one click.

The creation already works. Unfortenetly i can’t set the state to listed.
I always get a 404 error:

message: "No route found for path: \"pages/messages+test123/status\" and request method: \"POST\""

There is no diffenrence, if i do get or post. Which one would be right?
What am i doing wrong?
Common question: Is it possible to set the status while creation?

create() {
  let content = {
    text: 'testtext'
  };
  this.$api
    .post('pages/messages/children', { slug: 'test123', title: 'test123-title', template: 'message', content: content })
    .then(response => {
      // response.id: "messages/test123"
      this.deploy(response.id);
    })
    .catch(error => {
      console.log('error', error)
    });
},
deploy(id) {
  this.$api
    .post('pages/' + id.replace('/', '+') + '/status', { 'status': 'listed' })
    .then(response => {
      console.log(response);
     })
     .catch(error => {
       console.log('error', error)
      });
}

Beside of the status, i have some minor issues while creating the page.
The new Page ignores the title, and takes the slug as the title, but if i add the title to the content-array, it works.
Furthermore as far as i can see, the template is required, otherwise it stops with an error "Undefined array key “template”
Am i doing something wrong here too? I thought by the docu, title has to be part of the post parameters and template is not required…

Thx!

To create a page, the only required params are the slug and the template.

The title is part of the content array, though. I think the docs are not correct here.

As regards the status, the route expects a PATCH request, according to the routes in kirby/config/routes/pages.php

The title is part of the content array, though. I think the docs are not correct here.

:+1:

for the status should it be get or post?
do you have an example for adding a patch request?
unfortenetly the following doesn’t work either… and i cant find one

this.$api
  .get('pages/' + id.replace('/', '+') + '/status', { body: JSON.stringify({ "status": "listed" }) })

You can’t send a GET request. Have you tried

this.$api.patch

?

Here is an example from the source code:

   async changeStatus(id, status, position) {
      return api.patch("pages/" + this.id(id) + "/status", {
        status: status,
        position: position
      });
    },

If you don’t want to create the page as draft, you can pass

'draft' => false

in the post data. The page will then be created as unlisted. Haven’t found a way to create the page as listed yet.

thats it: this.$api.patch works

this.$api
  .patch('pages/' + id.replace('/', '+') + '/status', { status: 'listed' })

and the hook page.changeStatus:after works also.
i was not sure about that, because i have read, pages created by api or at least not by the panel won’t fire hooks. but that works :slight_smile:

Thank you very much! :sunny: