CORS Error (Request header field 0x-version)

CORS policy: Request header field 0x-version is not allowed by Access-Control-Allow-Headers in preflight response.

const headers = { “0x-api-key”: “0x-api-key”,
“0x-version”: “v2”, };

can not fetch…
const response = await fetch(
https://api.0x.org/swap/permit2/price?${qs.stringify(params)}, { headers }
);

Hi @godaemad,

Welcome to the Auth0 Community!

The CORS error related to the request header field 0x-version occurs when a request is made to the server, but the server’s CORS policy does not allow this specific header.

To resolve this issue, ensure the server’s Access-Control-Allow-Headers response header includes 0x-version. If it does not, you must update the server configuration to allow this header in CORS requests.

If you use a service that adds unwanted custom headers, consider updating the configuration to exclude this header from requests to the affected endpoint.

If you have any other questions, feel free to reach out.

Have a good one,
Vlad

I did these to fix the problem

  1. updated the .htaccess file by adding
    Header set Access-Control-Allow-Origin “*” Header set Access-Control-Allow-Headers “0x-version, Content-Type, Authorization, Accept, Origin, X-Requested-With”

  2. Added this snippet at the beginning of my API script:
    header(“Access-Control-Allow-Origin: *”); header(“Access-Control-Allow-Headers: 0x-version, Content-Type, Authorization, Accept, Origin, X-Requested-With”); header(“Access-Control-Allow-Methods: GET, POST, OPTIONS”);

but still have the same issue!