Anagram uses conventional HTTP response codes to indicate the success or failure of an API request. In general: Codes in the 2xx range indicate success. Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted). Codes in the 5xx range indicate an error with Anagram’s servers (these are rare).

There are 2 possible error responses:

  • Validation error with Error object,
  • General error with the string field detail.

General error (string field “detail”)

The error is related to the request itself. The field detail contains a human-readable error message.

Example:

{
    "detail": "Unknown authentication token type."
}

Validation error (error object in field “errors”)

Errors related to the request body object itself are validation errors with a status code 400 BAD_REQUEST.

Validation errors return a response object with a field errors, organized in a structure matching the request object (similar to GraphQL), containing error messages related to specific fields. For errors related to specific array elements, array indices are used as object keys.

Examples:

One error in the field quantity of the first service object in the services array field:

{
    "errors": {
        "services": {
            "0": {
                "quantity": {
                    "$": ["This field cannot be null."]
                }
            }
        }
    }
}

Three errors in the field last_name of object primary_member:

{
    "errors": {
        "primary_member": {
            "last_name": {
                "$": [
                    "This field cannot be null.",
                    "Required to access with Member ID.",
                    "Required to access with SSN last four."
                ]
            }
        }
    }
}

Validation errors in multiple fields:

{
    "errors": {
        "patient": {
            "last_name": {
                "$": ["Required to access with SSN last four."]
            }
        },
        "primary_member": {
            "ssn_last_four": {"$": ["Invalid SSN format."]
        },
        "services": {
            "1": {
                "quantity": {
                    "$": ["This field cannot be null."]
                }
            }
        }
    }
}