Making API Calls from Components
By default, you can’t make calls to third-party APIs from client-side code. Add a remote
site as a Trusted URL with Content Security Policy (CSP) directives to allow client-side component
code to load assets from and make API requests to that site’s domain.
The Lightning Component framework uses Content Security Policy (CSP) to impose restrictions on content. The main objective is to help prevent cross-site scripting (XSS) and other code injection attacks. Lightning apps are served from a different domain than Salesforce APIs, and the default CSP policy doesn’t allow API calls from JavaScript code. You change the policy, and the content of the CSP header, by adding Trusted URLs.
Sometimes, you have to make API calls from server-side controllers rather than client-side code. In particular, you can’t make calls to Salesforce APIs from client-side Aura component code. For information about making API calls from server-side controllers, see Making API Calls from Apex.