WP API post__not_in is not working

It is a bit more complicated to achieve. It needs too filters :

  • one to allow the new REST parameter
  • another to set the WP_Query argument
add_filter( 'rest_post_collection_params', 'collection_params', null, 2 );
add_filter( 'rest_post_query', 'query', null, 2 );

function collection_params( array $query_params, \WP_Post_Type $post_type ): array {
    $query_params['post__not_in'] = [
        'description' => 'Excludes posts.',
        'type'        => 'array',
        'default'     => [],
    ];

    return $query_params;
}

function query( $args, \WP_REST_Request $request ) {
    if ( isset( $request['post__not_in'] ) && count( $request['post__not_in'] ) ) {
        $args ['post__not_in'] = $request['post__not_in'];
    }
    return $args;
}