Your apiFetch()
usage is correct, but you’re getting the “No route was found” error because of the 'method' => 'POST'
part which should actually use methods
and not method
. (Note that an endpoint can allow one or more HTTP methods)
So when it’s method
, it’s not used and thus the HTTP method defaults to GET only.
And all you need to do is use 'methods' => 'POST'
(or 'methods' => 'GET,POST'
if you wanted to allow both GET and POST methods), and the error would be gone.