WordPress REST API rest_comment_invalid_author Sorry, you are not allowed to edit ‘author’ for comments

This is because you are sending unauthenticated anonymous requests, but still specifying an author. If what you were trying to do worked then it would be possible to impersonate any person on your site in a comment by specifying their author ID when creating the request.

With this in mind, the error message is quite clear.

Here you’re trying to edit the author property by setting it to 1:

    "author": 1,

And here the REST API is seeing this and saying No, you can’t do that, you don’t have permission:

    "code": "rest_comment_invalid_author",
    "message": "Sorry, you are not allowed to edit 'author' for comments.",

Anonymous logged out requests cannot edit other users comments or impersonate them.

So to fix this, either remove the author ID, or send an authenticated request, authenticated with that same user, or an administrator.


Additionally, the line you commented out was a filter:

$allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', true, $request );

Instead of modifying WordPres files, instead hook into the filter to return true in a theme or plugin:

add_filter( 'rest_allow_anonymous_comments', '__return_true' );

or

add_filter( 'rest_allow_anonymous_comments', '__return_false' );