WP REST API Custom POST Endpoint Not Working, 404 error
-
0
I’m writing a plugin, and I’m having some trouble with the custom endpoint that takes in data from the front-end of the app (Angular), and will pass it another function to filter some data. I have the GET request to the product database working just fine, but the POST just returns a 404 error (an empty array if I test the endpoint in Insomnia). Solutions I’ve tried include making sure that pretty permalinks were set, switching themes, all to no avail. I have also checked the wp-json file, and it is showing up in there. The code for this endpoint:
function get_awesome_params(WP_REST_Request $request) { // question attributes from angular code $parameters = $request->get_params(); return new WP_REST_Response($parameters, 200); } add_action('rest_api_init', function() { register_rest_route('awesome/v1', '/awesomeparams', array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => 'get_awesome_params', 'permission_callback' => function () { return true; } )); }); EDIT: Error message on visiting page is: { code: "rest_no_route", message: "No route was found matching the URL and request method", data: { status: 404 } }Is it because I don’t have a custom content type set up for the $request argument? Also, any guidance towards resources/tutorials that cover advanced WP REST API custom endpoint would be really appreciated, because I’m having a hard time finding examples beyond the most basic uses
The topic ‘WP REST API Custom POST Endpoint Not Working, 404 error’ is closed to new replies.