Open utkarsh3020 opened 4 months ago
@sawilde Hi, can u please help me regarding this issue
Hi @utkarsh3020
I haven't worked on this project in 8 years, ever since I moved on from MYOB.
However, if you are accessing any API from backend code then you shouldn't be troubled by CORS as that is purely a browser thing.
Hi @utkarsh3020
I haven't worked on this project in 8 years, ever since I moved on from MYOB.
However, if you are accessing any API from backend code then you shouldn't be troubled by CORS as that is purely a browser thing.
I am accessing the API from the frontend which calls my backend, and then it calls the MYOB accounting server
Then is the CORS error due to your backend not supporting CORS with your frontend? What backend server are you using and have you enabled CORS on it?
When I hit the API from my frontend react app then I get a CORS error
Frontend Code -
const fetchContacts = async () => { const oauthKeyService = keystore; fetch("https://localhost:44326/OAuth/GetContacts", { method: "GET", headers: { 'Content-Type': 'application/json', 'OAuth-Key-Service': JSON.stringify(oauthKeyService) }, }) .then((response) => response.json()) .then((data) => { console.log("Contacts received:", data); setContacts(data); }) .catch((error) => { console.error("Error fetching contacts:", error); }); };
Backend Code - ` public ActionResult CreateContact(Customer customer) { try { var oauthKeyServiceJson = HttpContext.Request.Headers["OAuth-Key-Service"]; var keystore = JsonConvert.DeserializeObject(oauthKeyServiceJson);
// Ensure keystore is initialized
if (keystore == null)
{
return new HttpStatusCodeResult(500, "OAuth KeyStore is not initialized.");
}
`
The CORS Error I am getting for both creating contact and fetching contact