• Hi there,

    I am having some issues with the REST API. Whenever I use ‘GET’ method, it works fine. However, ‘POST’ method results in following error.
    {“code”:”rest_no_route”,”message”:”No route was found matching the URL and request method”,”data”:{“status”:404}}

    My server is NGINX with php7.1 wordpress version: 4.9.6

    Here is the action hook I used.
    //rest api init

    add_action('rest_api_init', function () {
                register_rest_route('test-url', '/submit-links', aarray(
                    'methods' => 'POST',//works perfect if GET method is used.
                    'callback' => array($this, submit_links_to_db),
                ));
            });
    

    Nginx URL rewrite:
    try_files $uri $uri/ /index.php$is_args$args;

    There is noting in the error logs. Please let me know if you need more information. I would really appreciate any help.

    Thank you

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The code you posted has a typo in line 2: aarray( instead of array(

    The code in your installation must be OK, as this would generate an error log entry, but such an error would cause an API request to 404. Double check your actual code just to be sure.

    I’ve no experience with POST endpoints. That said, maybe you should try adding a ‘permission_callback’. I don’t know if it’s actually required, but it would make sense if it were. Not just anyone authenticated should be allowed to add data, there are usually further restrictions that need to be checked.

Viewing 1 replies (of 1 total)
  • The topic ‘Rest API using POST method not working PHP 7.1 NGINX’ is closed to new replies.