React Native fetch fails with Postman mock server: CORS, headers, and schema mismatches

Archived topic — some details may be out of date.
Mock servers built from saved collection examples are still supported. Postman now also has code-based mocks: JavaScript request handlers plus a config.yaml, stored as files in your Git repository, which you can run locally or deploy. Create one in the app, or use the Postman CLI to generate one from an OpenAPI spec, collection or dataset (postman mock generate) and run it (postman mock run). See About mocks and Create a mock.
Working with an AI coding agent? The Postman plugin can build and run mocks for you.
For current help, see the Postman docs, try the free Postman tools (no account needed), or join us on Discord.

I’m using the latest Postman mock server with API versioning to develop against my evolving backend schema, but I keep hitting a wall. My fetch requests, which work fine against production, often fail with the mock server due to missing or inconsistent CORS and custom auth headers, and sometimes the mock returns JSON that doesn’t match my OpenAPI schema—fields are missing or the types are off, even when the schema is up to date. Switching API versions in Postman sometimes leaves stale responses or mismatches, and dynamic path parameters like /user/:id/items intermittently 404 or return partial data. Here’s a typical fetch that works in production but fails with the mock server:

fetch('https://mock-server-url/user/123/items', {
  method: 'GET',
  headers: {
    'Accept': 'application/json',
    'X-Auth-Token': 'mytoken'
  }
})
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error('API error:', err));

With the mock server, I get either Network request failed or Unexpected token < in JSON at position 0 . Is there a way to guarantee the Postman mock server always returns the correct schema (with all fields and types), includes all CORS and custom headers so fetch requests don’t fail, keeps mock responses in sync across API versions, and reliably handles dynamic path params?

Hi @yonandualem. Mock servers in Postman are tied to saved request examples and not your OpenAPI Schema. Could you share a bit more about what you mean by “Mock server with API versioning”?

Never mind I have solved this issue. Thank you for your help!