Request to REST endpoint works fine in browser and curl, but fails from WP_REST_Request

The route should not include the /wp-json part, and there should be no trailing slash (/) at the end:

  • Wrong: /wp-json/wp/v2/pages/499/

  • Correct: /wp/v2/pages/499

So:

$request = new WP_REST_Request( 'GET', '/wp/v2/pages/499' );