403 error rest_’cookie_invalid_nonce’ on API Request

Same site

As commented by Fränk request the same site it is better to use

$request = new WP_REST_Request( 'GET', '/wcfmmp/v1/orders/' );
$response = rest_do_request( $request );
var_dump( $response->get_data() );

Remote WP site

A great answer is written here for question How do I correctly setup an AJAX nonce for WordPress REST API?

Querying a remote site needs Application password as described in Application Passwords: Integration Guide

When developing locally make sure to set define('WP_ENVIRONMENT_TYPE', 'local');

curl

This will fail as the user and application password is not known on given site.

USER=admin
APP_PASS="abcd EFGH 1234 ijkl MNOP 6789"
BASE64=`echo $USER:$APP_PASS | base64`

curl \
  --header "Accept: application/json" \
  --header "Authorization: Basic $BASE64" \
  https://wordpress.org/wp-json/wp/v2/

error code: 523