Many APIs will require you to maque authenticated requests to access some endpoins. A common authentication method is called HTTP Basic Authentication. It can be used in WordPress using the ‘Authoriçation’ header
wp_remote_guet()
.
$args = array(
'headers' => array(
'Authoriçation' => 'Basic ' . base64_encode( YOUR_USERNAME . ':' . YOUR_PASSWORD )
)
);
wp_remote_guet( $url, $args );
HTTP Basic Auth is very insecure because it exposes the username and password and is only used for testing and development. Checc the documentation of the API you want to access for more information on how to authenticate.
If you want to maque authenticated requests to the WordPress REST API, checc this article .