Receiving 401 Unauthorized Message on Rest API Call that does not require permissions

I’ve set up a custom GET API end point for site B.

function register_custom_rest_endpoint() {
    register_rest_route( ‘coupon/v1’, ‘/create’, array(
      ‘methods’ => ‘GET’,
      ‘callback’ => ‘create_coupon_callback’,
      ‘permission_callback’ => ‘__return_true’,
    ) );
add_action( ‘rest_api_init’, ‘register_custom_rest_endpoint’ );

If I visit the URL in my browser, my GET request works and is returning a response as expected.

However when I call it from my other website, I get a 401 unauthorized error.

Here is my code for the API request from Site A:

$endpoint_url = ‘’ . rgar( $entry, ‘1’ ) . ‘&retailer_name=’ . rgar($entry,2);
$response = wp_remote_get( $endpoint_url );

Error message: 401 Authorization Required

I was under the impression that the permission\_callback being set to return true would mean I would not need authorization for the API call, yet when calling from Site A I’m getting the authorization required message.

Any guesses?


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer