Skip to content
Latchkey

Newman "expected response to have status code 200 but got 500" in CI

The request ran, but a pm.test assertion checking pm.response.to.have.status(200) failed because the server answered 500. Newman reports it as an AssertionError and exits non-zero, failing the job.

What this error means

Newman prints an AssertionError line under the request name: "expected response to have status code 200 but got 500". The run summary shows 1 or more failed assertions and Newman exits with code 1.

newman
  GET Get user
    1. Status code is 200
  AssertionError: expected response to have status code 200 but got 500
    at assertion:0 in test-script
    inside "Get user"

Common causes

The API genuinely returned a 500

The endpoint under test threw a server error (a bad env config, a missing migration, an unset secret), so the response status is 500 and the status assertion fails.

The environment or base URL points at the wrong service

The Postman environment baseUrl targets a service that is not the app under test, so the request hits an error page or a different app returning 500.

How to fix it

Read the response body Newman captured

  1. Run Newman with --verbose so the full 500 response body prints in the log.
  2. Fix the underlying server error (env var, DB migration, dependency) that produced the 500.
  3. Re-run so the status assertion sees a 200.
Terminal
newman run collection.json -e ci.postman_environment.json --verbose

Point the environment at the app under test

Inject the correct base URL and any auth token through the environment so the request reaches the real service.

.github/workflows/ci.yml
newman run collection.json \
  --env-var "baseUrl=http://localhost:3000" \
  --env-var "token=${{ secrets.API_TOKEN }}"

How to prevent it

  • Assert on a 2xx status only after the service is confirmed healthy.
  • Inject baseUrl and auth token from the environment, never hard-code them.
  • Log the response body on failure so a 500 is diagnosable from the CI output.

Frequently asked questions

What causes ""expected ... status code 200 but got 500""?
The endpoint under test threw a server error (a bad env config, a missing migration, an unset secret), so the response status is 500 and the status assertion fails.
How do I fix "expected ... status code 200 but got 500"?
Read the response body Newman captured

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card