Custom REST API endpoint returns rest_no_route when called via wp-json permalink

The problem is with the bbe_sortables&replace in the permalink:

<My URL>/wp-json/bridge/v1/test-data/process/bbe_sortables&replace&_wpnonce=<thenonce>

which results in an invalid route, where the supposedly query string is seen as part of the route:

/bridge/v1/test-data/process/bbe_sortables&replace&_wpnonce=<thenonce>

(the valid route for that URL is /bridge/v1/test-data/process/bbe_sortables)

and eventually the REST API throws the rest_no_route error.

To fix the problem, use add_query_arg() when generating the URL, to append the proper query string; e.g. with rest_url():

$url = add_query_arg( array(
    'replace'  => 'VALUE',
    '_wpnonce' => 'VALUE',
), rest_url( 'bridge/v1/test-data/process/bbe_sortables/' ) );

/* Sample $url output:

a) Permalinks enabled
http://example.com/wp-json/bridge/v1/test-data/process/bbe_sortables/?replace=VALUE&_wpnonce=VALUE

b) Permalinks *not* enabled
http://example.com/index.php?rest_route=%2Fbridge%2Fv1%2Ftest-data%2Fprocess%2Fbbe_sortables%2F&replace=VALUE&_wpnonce=VALUE
*/

Or if you’re certain that permalinks are always enabled on the site, then this would be fine:

rest_url( 'bridge/v1/test-data/process/bbe_sortables/?replace=VALUE&_wpnonce=VALUE' )

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)