2

I'm trying to make API call to some open APIs and getting the same error every time: "TypeError: Failed to fetch". The site is added to CSP trusted sites and CORS allowed origin list. The code is working properly in LWC Playground and I can make this call from Postman. Below is my code:

let endpoint = 'https://sv443.net/jokeapi/v2/joke/Any';

        let requestParams = {
            method: 'GET',
            headers: {
                'Content-Type' : 'application/json'//,
                //'Access-Control-Allow-Origin' : '*'
            }
        };

        fetch(endpoint, requestParams)
            .then(response => {
                console.log('in response');
            })
            .catch(error => {
                console.log('error3: ' + error);
            });
2

The right answer is that I left checked one default CSP Directive only (it was "Allow site for img-src") for the site. When I checked all the others directives in 10 min I got a response (CSP takes time to start work) enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.