HelloJohn / docs
API Reference

Error Codes

Complete reference of all HelloJohn API error codes, their meanings, and how to resolve them.

Error Codes

All API errors return a JSON body with a structured error object:

{
  "error": {
    "code": "invalid_credentials",
    "message": "The email or password is incorrect.",
    "status": 401,
    "request_id": "req_01HABCDEF999888"
  }
}

Use code (not status or message) for programmatic error handling — messages may change between versions.

HTTP Status Summary

StatusMeaning
200Success
201Created
204Success, no content
400Bad request — invalid input
401Unauthenticated — missing or invalid token
403Forbidden — valid token, insufficient permissions
404Resource not found
409Conflict — resource already exists
422Unprocessable entity — validation failed
429Too many requests — rate limit exceeded
500Internal server error
503Service unavailable

Authentication Errors (401)

CodeStatusDescriptionResolution
missing_token401No Authorization header presentInclude Authorization: Bearer <token>
invalid_token401Token is malformed or has invalid signatureRe-authenticate to get a fresh token
token_expired401Access token has expiredUse refresh token to get a new access token
refresh_token_expired401Refresh token has expired (session ended)User must sign in again
refresh_token_invalid401Refresh token does not match sessionRe-authenticate
invalid_api_key401Secret key sk_... is invalid or revokedRegenerate the key in dashboard
invalid_publishable_key401Publishable key pk_... is invalidCheck the key in dashboard settings
session_revoked401Session was explicitly revokedUser must sign in again

Authorization Errors (403)

CodeStatusDescriptionResolution
insufficient_permissions403Token is valid but lacks required role/permissionUse a token with higher permissions
tenant_mismatch403Resource belongs to a different tenantVerify X-Tenant-ID header
cp_admin_required403Endpoint requires a CP Admin tokenUse a Control Plane admin secret key
mfa_required403MFA verification required before proceedingComplete MFA challenge first
email_not_verified403User's email must be verified firstTrigger email verification flow
account_disabled403User account has been disabledContact tenant admin
account_locked403Account temporarily locked (too many failed attempts)Wait for lockout period or reset password
org_member_required403Action requires org membershipJoin the organization first
org_role_insufficient403Action requires a higher org roleRequires admin or owner role

Validation Errors (400 / 422)

CodeStatusDescriptionResolution
invalid_request400Request body is malformed JSONCheck request body format
missing_required_field422A required field is absentInclude all required fields
invalid_email422Email format is invalidProvide a valid email address
password_too_short422Password does not meet minimum lengthUse at least 8 characters
password_too_weak422Password failed strength check (zxcvbn)Use a stronger password
password_breached422Password found in breach database (HIBP)Choose a different password
invalid_phone422Phone number format is invalidUse E.164 format (e.g., +14155552671)
invalid_cursor400Pagination cursor is malformedUse the exact cursor from the previous response
invalid_date422Date field is not a valid ISO 8601 stringUse format 2024-01-15T10:30:00Z
field_too_long422A field exceeds maximum lengthCheck field length limits
unsupported_oauth_provider400OAuth provider is not configured for this tenantEnable the provider in tenant settings

Resource Errors (404 / 409)

CodeStatusDescriptionResolution
user_not_found404No user matches the given ID or emailVerify the user ID or email
session_not_found404Session does not existSession may have expired or been revoked
org_not_found404Organization not foundVerify the org ID
tenant_not_found404Tenant does not existVerify the tenant ID or slug
client_not_found404Client (app) does not existVerify the client ID
mfa_factor_not_found404MFA factor not foundUser may not have enrolled this factor
webhook_not_found404Webhook endpoint not foundVerify the webhook ID
api_key_not_found404API key not foundKey may have been revoked
invitation_not_found404Org invitation not found or expiredRe-send the invitation
email_already_exists409Email is already registeredSign in or use password reset
username_already_exists409Username is already takenChoose a different username
mfa_factor_already_enrolled409User already has this MFA factor enrolledUnenroll first to re-enroll
org_name_already_exists409Organization name is taken within tenantChoose a different org name
member_already_in_org409User is already a member of this orgNo action needed

Authentication Flow Errors

CodeStatusDescriptionResolution
invalid_credentials401Email or password is incorrectCheck credentials
invalid_magic_link401Magic link token is invalid or expiredRequest a new magic link
invalid_otp401OTP code is incorrectRe-enter the code or request a new one
otp_expired401OTP has expiredRequest a new OTP
invalid_totp401TOTP code is invalidCheck device clock sync and try again
backup_code_invalid401Backup code is invalid or already usedUse a different backup code
oauth_state_mismatch400OAuth state parameter does not matchRestart OAuth flow
oauth_denied400User denied OAuth authorizationUser cancelled — no action required
oauth_error400OAuth provider returned an errorCheck provider configuration
saml_assertion_invalid401SAML assertion failed validationCheck IdP configuration

Rate Limit Errors (429)

CodeStatusDescriptionResolution
rate_limit_exceeded429Too many requests in the time windowWait for Retry-After seconds
account_lockout429Too many failed sign-in attemptsWait for the lockout period

The Retry-After header contains the number of seconds to wait:

HTTP/1.1 429 Too Many Requests
Retry-After: 60
X-RateLimit-Reset: 1700000060

Server Errors (5xx)

CodeStatusDescriptionResolution
internal_server_error500Unexpected server errorRetry with exponential backoff; contact support if persistent
database_error500Database operation failedRetry; check database health
service_unavailable503Server is temporarily unavailableRetry after a few seconds
migration_in_progress503Server is applying schema migrationsWait 30-60 seconds and retry

Handling Errors: Examples

TypeScript / Node.js:

try {
  const user = await hellojohn.users.get(userId)
} catch (err) {
  if (err instanceof HelloJohnError) {
    switch (err.code) {
      case 'user_not_found':
        return res.status(404).json({ message: 'User does not exist' })
      case 'token_expired':
        return res.status(401).json({ message: 'Please sign in again' })
      default:
        console.error('HelloJohn error:', err.code, err.message)
        return res.status(500).json({ message: 'Internal error' })
    }
  }
}

Go:

user, err := client.Users().Get(ctx, userID)
if err != nil {
    var apiErr *hj.APIError
    if errors.As(err, &apiErr) {
        switch apiErr.Code {
        case "user_not_found":
            http.Error(w, "user not found", http.StatusNotFound)
        case "token_expired":
            http.Error(w, "session expired", http.StatusUnauthorized)
        default:
            http.Error(w, "internal error", http.StatusInternalServerError)
        }
        return
    }
}

Python:

from hellojohn.exceptions import HelloJohnError

try:
    user = await client.users.get(user_id)
except HelloJohnError as e:
    if e.code == "user_not_found":
        raise HTTPException(status_code=404, detail="User not found")
    elif e.code == "token_expired":
        raise HTTPException(status_code=401, detail="Session expired")
    raise

On this page