Jump to content
Tobias

Trash A Page Via REST API

Recommended Posts

Hello community,

I'm using https://processwire.com/modules/rest-api/ to define some REST API endpoints for my ProcessWire.
One of these endpoints receives an ID in the path via /api/foo/:id .
I search for the page using $pages->get() and can confirm that it's found.

The tricky part is now that when I do $my_page->trash() or $pages->trash($my_page) I end up with the following error:
"Attempt to read property "id" on null. File: [...]\wire\core\PagesEditor.php:296"
Which seems to be the case because ProcessWire checks with $this->wire("page")->id if the current page is the one I try to trash/delete.
Understandably there is no current page when this is not a template file.

So how could one proceed to trash/delete a page via REST API if the aforementioned ProcessWire APIs won't work?

Best regards
Tobias

Share this post


Link to post
Share on other sites

Hi Tobias, welcome to the forum!

Sorry, I have no answer for you, but I can just tell you that I've never had any problems using $page->trash() in any of my projects. So your tricky part should really not be tricky at all 🙂 Maybe there's something else going on...

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Please provide the code that you use.

The error says, that it is trying to read the property of a null object. That means, that $my_page is not a page and therefore ProcessWire can't get the id of this page.

If you have an id for the page do `$pages->get(insertIdHere)->trash();`

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...