filters – No ‘Access-Control-Allow-Origin’ header is present

I keep getting this error message when I am sending a fetch request from the admin side. I want to connect to that API and get some response.

Access to fetch at
‘’ from origin ‘’ has been blocked by CORS
policy: Response to preflight request doesn’t pass access control
check: No ‘Access-Control-Allow-Origin’ header is present on the
requested resource. If an opaque response serves your needs, set the
request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

Is there a WordPress way to get it fixed?

Please help thanks

Tried these :

add_filter( 'allowed_http_origin', '__return_true' );
function add_cors_http_header(){
    header("Access-Control-Allow-Origin: *");

add_filter('allowed_http_origins', 'add_allowed_origins');

function add_allowed_origins($origins) {
    $origins() = '';
    $origins() = '';
    return $origins;

this is the fetch request

 fetch('', {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
          'Access-Control-Allow-Origin': '*',
      }).then(response => {
        return response.json()
      .then(data => console.log(data))
      .catch(error => console.log(error));