Curl Success But Wrong Response: Validate API Responses
Your curl command returns HTTP 200, but the response body contains an error message. Learn how to detect and handle this.
The Problem: HTTP 200 with Error Content
Many APIs return HTTP 200 even when there's an error, putting the error message in the response body. This breaks simple exit code checks:
- API returns 200 OK with JSON error: {"error": "Invalid token"}
- REST API returns 200 with HTML error page
- GraphQL returns 200 with errors array in response
- Webhook endpoints return 200 but log failures internally
- Health check endpoints return 200 even when service is degraded
Checking only HTTP status code isn't enough. You need to validate the response body content.
Solution: Validate Response Body
Always check response content, not just HTTP status. Parse JSON responses and look for error fields, or search for error keywords in text responses.
Bash Example: Check JSON Response
#!/bin/bashRESPONSE=$(curl -s -w "\n%{http_code}" "https://api.example.com/data")HTTP_CODE=$(echo "$RESPONSE" | tail -n1)BODY=$(echo "$RESPONSE" | sed '$d')# Extract response validation dataHAS_ERROR=0if echo "$BODY" | grep -q '"error"'; then HAS_ERROR=1fi# Single ping with response data in payload# In DeadManPing panel: set validation rules:# - "status_code" == 200# - "has_error" == 0# Panel will automatically detect violations and alertcurl -X POST "https://deadmanping.com/api/ping/api-check?status_code=$HTTP_CODE&has_error=$HAS_ERROR"Python Example: Validate JSON Response
import requestsimport jsonresponse = requests.get("https://api.example.com/data")# Extract response data for payloadhas_error = Falsetry: data = response.json() has_error = "error" in dataexcept json.JSONDecodeError: has_error = True # Invalid JSON# Single ping with response data in payload# In DeadManPing panel: set validation rules:# - "status_code" == 200# - "has_error" == False# Panel will automatically detect violations and alertrequests.post(f"https://deadmanping.com/api/ping/api-check?status_code={response.status_code}&has_error={has_error}")Node.js Example: Check Response Content
const https = require('https');https.get('https://api.example.com/data', (res) => { let data = ''; res.on('data', (chunk) => data += chunk); res.on('end', () => { // Extract response data for payload let hasError = false; try { const json = JSON.parse(data); hasError = !!json.error; } catch (e) { // Invalid JSON } // Single ping with response data in payload // In DeadManPing panel: set validation rules: // - "status_code" == 200 // - "has_error" == false // Panel will automatically detect violations and alert https.request(`https://deadmanping.com/api/ping/api-check?status_code=${res.statusCode}&has_error=${hasError}`, { method: 'POST' }).end(); });});GraphQL Example: Check Errors Array
#!/bin/bashRESPONSE=$(curl -s -X POST "https://api.example.com/graphql" \ -H "Content-Type: application/json" \ -d '{"query": "{ query { data } }"}')# Extract GraphQL response dataHAS_ERRORS=0if echo "$RESPONSE" | grep -q '"errors"'; then HAS_ERRORS=1fi# Single ping with GraphQL response data in payload# In DeadManPing panel: set validation rule "has_errors" == 0# Panel will automatically detect if GraphQL response has errorscurl -X POST "https://deadmanping.com/api/ping/graphql-check?has_errors=$HAS_ERRORS"Monitoring Response Validation
After adding response validation to your scripts, use a dead man switch to monitor whether validation completed successfully. If your script detects an error in the response body and exits with error code, the ping never arrives, and you get an alert.
Include error messages in your ping payload so you can track what types of errors occur and identify patterns.
Working Examples
See complete, working code examples in our GitHub repository:
View Examples on GitHub →Start Monitoring API Responses
DeadManPing monitors whether your response validation completes. Set up monitoring in 2 minutes, get alerts when APIs return wrong responses.
Start Monitoring FreeRelated Articles
Learn more about cron job monitoring and troubleshooting:
Curl Returns 200 But Wrong Data
How to detect when curl returns HTTP 200 but contains wrong data.
Verify Cron Output
How to verify cron job script output contains expected content.
Verify Script Output Content
How to verify script output contains expected content.
Cron Job Returns Success But Fails
How to detect when cron jobs return success exit code but actually fail.