I’m facing the issue Access to fetch at ‘https://XXXXXXXX.xxx.com:9443/api/user_tokens/search’ from origin ‘https://salesforce.lightning.force.com’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.
this is the request i’m sending
import { LightningElement } from 'lwc';
export default class ProjectAnalysis extends LightningElement {
connectedCallback() {
this.getProjectAnalysisData();
}
getProjectAnalysisData() {
const token = "XXXXXXXXXXXXXXXXXX";
const authHeader = "Basic " + btoa(token + ":");
fetch('https://XXXXXXXX.xxx.com:9443/api/user_tokens/search', {
method: "GET",
headers: {
"Content-Type": "application/json",
"Authorization": authHeader // Add the Authorization header with the token
},
})
.then((response) => {
if (!response.ok) {
throw new Error("HTTP error " + response.status);
}
return response.json();
})
.then((data) => {
console.log(data);
})
.catch((error) => {
console.log('Error: ', error);
});
}
}