CORS errors: why it works in Postman but not the browser
Short answer: A CORS error means the browser blocked your page's JavaScript from reading a response from another domain, because that domain's server didn't say your site was allowed. It works in Postman, curl or a server-side script because CORS is enforced by browsers, not by servers or API tools. The fix is almost always on the server you're calling (or a small server of your own in between), never by trying to switch CORS off in the browser.
Small teams wiring a website to an API (a booking system, a CRM, a pricing service, an AI endpoint) hit this constantly. The request looks fine, the API key is right, Postman returns data, yet the browser console fills with red. Here's how to read the symptom, find the cause and apply the right fix.
What's going on
MDN's guide to Cross-Origin Resource Sharing explains that for security reasons, browsers restrict cross-origin HTTP requests initiated from scripts: fetch() and XMLHttpRequest follow the same-origin policy, so a web application can only request resources from the origin it was loaded from, unless the response from the other origin includes the right CORS headers.
An "origin" is the combination of scheme, domain and port. https://www.example.com and https://api.example.com are different origins; so are http:// and https:// versions of the same domain.
MDN also notes that CORS failures produce errors, but for security reasons the specifics aren't available to JavaScript, which is why your code often sees only a vague network failure while the console shows more detail.
Symptom → cause → fix
"No 'Access-Control-Allow-Origin' header is present"
Cause: The API server didn't include the header that permits your site's origin to read the response.
Fix: Configure the API server to send Access-Control-Allow-Origin with your site's origin (for example https://www.example.com). If it's a third-party API, check its documentation: some support browser calls and let you register allowed origins in a dashboard; many don't support browser calls at all and expect requests from your server instead.
Works in Postman, fails in the browser
Cause: Postman and curl aren't browsers and don't apply the same-origin policy. The API happily answers them.
Fix: None needed in Postman; the browser behaviour is expected. Choose between allowing your origin on the API, or calling the API from your own server.
A request with a custom header fails before it's even sent
Cause: A preflight. MDN explains that for requests other than "simple" ones (for example, methods other than GET, HEAD or POST, POST with certain content types, or custom headers such as an API key header), browsers first send an HTTP OPTIONS request asking the server which methods and headers it allows, and only send the real request if the server approves.
Fix: The server must respond to OPTIONS requests with the appropriate Access-Control-Allow-Methods and Access-Control-Allow-Headers (plus Access-Control-Allow-Origin). If the server returns an error or a redirect for OPTIONS, the real request never happens.
Error mentions credentials and the wildcard
Cause: Your request sends cookies or authentication (credentials), but the server responds with Access-Control-Allow-Origin: *. MDN states that when responding to a credentialed request, the server must specify an origin rather than the * wildcard.
Fix: Return the specific origin, and include Access-Control-Allow-Credentials: true where credentials are intended.
It worked on staging but not on the live domain
Cause: The API allows the staging origin but not production, or allows example.com but your live site runs on www.example.com.
Fix: Add every origin that legitimately calls the API, exactly as the browser reports it.
It works for GET but not for POST
Cause: The POST includes a JSON content type or custom headers, triggering a preflight the server doesn't handle.
Fix: Handle OPTIONS on the server, as above.
The fixes that don't work (or shouldn't)
- Browser extensions that disable CORS. They "fix" it on your machine only. Customers won't have them.
mode: 'no-cors'in fetch. This sends the request but gives your script an opaque response it can't read. It rarely does what people expect.Access-Control-Allow-Origin: *everywhere. Fine for genuinely public, read-only data. Risky for anything involving user data or credentials, and not allowed with credentials anyway.
When a small server in between is the right answer
Many APIs, especially ones needing a secret key, aren't meant to be called directly from browsers. If your page calls them, your key is visible to anyone who opens developer tools. The cleaner pattern:
- Your page calls an endpoint on your own domain (a serverless function, a small backend route or your CMS's server).
- That endpoint adds the secret key and calls the third-party API from the server, where CORS doesn't apply.
- It returns only the data your page needs.
This removes the CORS problem and keeps keys off the front end.
Quick diagnostic routine
- Open the browser console and Network tab; reproduce the error.
- Find the failed request. Is there an
OPTIONSrequest before it? What status did it return? - Check the response headers for
Access-Control-Allow-Origin. Does it match your page's origin exactly? - Is the request sending cookies or an
Authorizationheader? - Check the API's documentation: does it support browser calls?
FAQ
Can I fix a CORS error from my website's code alone?
Usually not. The server you're calling decides whether to allow your origin. Your options are changing that server's configuration or routing calls through a server you control.
Is CORS a security feature or a bug?
A security feature of browsers. It stops other sites' scripts from reading responses that were only meant for your site, such as data returned with a logged-in user's cookies.
Why does my form submission work but fetch doesn't?
Ordinary HTML form submissions navigate the page and aren't read by scripts, so CORS doesn't block them the same way. fetch() reads the response, which is what CORS controls.
Does CORS affect mobile apps?
Native mobile apps aren't browsers, so CORS doesn't apply to their HTTP requests. It does apply to web views and progressive web apps running in a browser engine.
Stuck connecting your site to an API that refuses browser requests? Tell us which service you're calling and we'll suggest the cleanest route.