I am getting CORS Exception while accessing Trading APIs

I am using react to access the DHAN API,

useEffect(() => {
    const fetchData = async () => {
      setLoading(true);
      try {
        const headers = {
          'Authorization': `Bearer ${accessToken}`,
          'Content-Type': 'application/json',
        };

        const response = await fetch('https://api.dhan.co/v2/fundlimit', { headers });

        // Check if the response is not ok (status code is not 2xx)
        if (!response.ok) {
          throw new Error(`API Error: ${response.status} - ${response.statusText}`);
        } else {
          console.log(response.status);
          
        }

Getting below error,

Access to fetch at ‘https://api.dhan.co/v2/fundlimit’ from origin ‘http://localhost:3000’ 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.

I really appreciate if anyone could support on this ?

Hello @Pushparaj_Gopalsamy

Welcome to MadeForTrade community!

If you are making browser requests to APIs, then the same will be restricted due to the CORS policy. It needs to be server polling only.