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 ?