---
title: "Error Codes"
description: "The error response structure and the error codes the Leyr API can return."
canonical_url: "https://docs.leyr.io/api/error-handling/error_codes"
---
# Error Codes

> The error response structure and the error codes the Leyr API can return.

## Overview

When an error occurs, the API returns a JSON response containing error details. The response includes a general error code and an array of detailed errors. Each detailed error provides specific information about what went wrong.

### Error Response Structure

```json
{
    "code": "BAD_REQUEST",
    "detail": "Bad request. Check documentation if you send all the fields in a proper format.",
    "errors": [
        {
            "details": "The timeslot for the given parameters was not found",
            "emr_error": null,
            "error_code": "NO_TIMESLOTS_AVAILABLE",
            "path": null
        }
    ],
    "instance": "d3e84cc1-148a-4edf-9579-5dcef1d6dbfa",
    "status": 400,
    "title": "Request validation failed",
    "type": "https://docs.leyr.io/api/error-handling/bad_request"
}
```

Note: Multiple detailed errors may be returned in the `errors` array. For example, if a request contains an invalid parameter and no available timeslot, both errors will be included in the response.

## 400 Bad Request

<table>
<thead>
  <tr>
    <th>
      Error Code
    </th>
    
    <th>
      Default Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      INVALID_PATIENT_ID
    </td>
    
    <td>
      Provided patient_id is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_CARE_UNIT_ID
    </td>
    
    <td>
      Provided care_unit_id is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_HEALTHCARE_SERVICE_ID
    </td>
    
    <td>
      Provided healthcare_service_id is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_RESOURCE_ID
    </td>
    
    <td>
      Provided resource_id is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_APPOINTMENT_ID
    </td>
    
    <td>
      Provided appointment_id is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      NO_TIMESLOTS_AVAILABLE
    </td>
    
    <td>
      No timeslots available for the given parameters
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_COMMENT_LENGTH
    </td>
    
    <td>
      Provided comment is too long
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_CREATED_BY_ID
    </td>
    
    <td>
      Provided created_by_id is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_NOTE_CONTENT
    </td>
    
    <td>
      Provided content for medical note is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      MISSING_REQUIRED_FIELD
    </td>
    
    <td>
      Missing required field in the request
    </td>
  </tr>
  
  <tr>
    <td>
      MAX_ITEMS_EXCEEDED
    </td>
    
    <td>
      Max items exceeded
    </td>
  </tr>
  
  <tr>
    <td>
      BAD_INPUT
    </td>
    
    <td>
      Invalid input, EHR rejected your request
    </td>
  </tr>
  
  <tr>
    <td>
      PATIENT_ID_LOOKUP_TYPE_NOT_SUPPORTED
    </td>
    
    <td>
      EHR does not support patient lookup by the given lookup type
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_PATIENT_ID_TYPE
    </td>
    
    <td>
      Provided patient id type is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      AMBIGUOUS_TIMESLOTS
    </td>
    
    <td>
      More than one timeslot found for the given parameters
    </td>
  </tr>
  
  <tr>
    <td>
      NOT_SUPPORTED
    </td>
    
    <td>
      Not supported
    </td>
  </tr>
  
  <tr>
    <td>
      BAD_TIME_RANGE
    </td>
    
    <td>
      Bad time range. End time must be greater than start time
    </td>
  </tr>
  
  <tr>
    <td>
      MEDICAL_NOTE_MAPPING_BAD_MAPPING
    </td>
    
    <td>
      Medical note mapping is not configured correctly for provided template id
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_PARAMETER
    </td>
    
    <td>
      One or more provided parameters are invalid
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_CONFIRMATION_CODE
    </td>
    
    <td>
      Invalid confirmation code for the appointment
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_POSTAL_CODE
    </td>
    
    <td>
      Provided postal code is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_COUNTRY
    </td>
    
    <td>
      Provided country is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_PAGINATION_TOKEN
    </td>
    
    <td>
      Provided pagination token is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_TEMPLATE_ID
    </td>
    
    <td>
      Provided template_id is not valid
    </td>
  </tr>
  
  <tr>
    <td>
      AMBIGUOUS_PATCH_PARAMS
    </td>
    
    <td>
      Cannot both reschedule/change and confirm/cancel an appointment in the same request
    </td>
  </tr>
  
  <tr>
    <td>
      INVALID_PATCH_PARAMS
    </td>
    
    <td>
      Patch params must include either reschedule/change or confirm/cancel set of parameters
    </td>
  </tr>
  
  <tr>
    <td>
      RESCHEDULE_NOT_POSSIBLE
    </td>
    
    <td>
      Rescheduling is not possible for the given appointment
    </td>
  </tr>
  
  <tr>
    <td>
      CANCEL_NOT_POSSIBLE
    </td>
    
    <td>
      Cancelling is not possible for the given appointment
    </td>
  </tr>
  
  <tr>
    <td>
      CHANGE_NOT_POSSIBLE
    </td>
    
    <td>
      Changing is not possible for the given appointment
    </td>
  </tr>
  
  <tr>
    <td>
      CONFIRMATION_NOT_REQUIRED
    </td>
    
    <td>
      The given EHR does not require confirmation for scheduling or canceling the appointment
    </td>
  </tr>
  
  <tr>
    <td>
      AMBIGUOUS_HEALTHCARE_SERVICES
    </td>
    
    <td>
      More than one healthcare service found for the given parameters
    </td>
  </tr>
  
  <tr>
    <td>
      AMBIGUOUS_PATIENTS
    </td>
    
    <td>
      More than one patient found for the given parameters
    </td>
  </tr>
  
  <tr>
    <td>
      AMBIGUOUS_RESOURCES
    </td>
    
    <td>
      More than one resource found for the given parameters
    </td>
  </tr>
</tbody>
</table>

## 401 Unauthorized

<table>
<thead>
  <tr>
    <th>
      Error Code
    </th>
    
    <th>
      Default Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      BAD_CREDENTIALS
    </td>
    
    <td>
      Bad EHR credentials provided for the request
    </td>
  </tr>
  
  <tr>
    <td>
      FAILED_EMR_AUTH
    </td>
    
    <td>
      Failed to authenticate with the EHR
    </td>
  </tr>
</tbody>
</table>

## 403 Forbidden

<table>
<thead>
  <tr>
    <th>
      Error Code
    </th>
    
    <th>
      Default Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      NO_DATA_ACCESS
    </td>
    
    <td>
      EHR responded with data access error
    </td>
  </tr>
  
  <tr>
    <td>
      CORRUPTED_OR_INVALID_TOKEN
    </td>
    
    <td>
      Auth token you provided is corrupted or invalid
    </td>
  </tr>
</tbody>
</table>

## 404 Not Found

<table>
<thead>
  <tr>
    <th>
      Error Code
    </th>
    
    <th>
      Default Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      APPOINTMENT_NOT_FOUND
    </td>
    
    <td>
      Given appointment couldn't be found in the EHR
    </td>
  </tr>
  
  <tr>
    <td>
      PATIENT_NOT_FOUND
    </td>
    
    <td>
      Given patient couldn't be found in the EHR
    </td>
  </tr>
  
  <tr>
    <td>
      CARE_UNIT_NOT_FOUND
    </td>
    
    <td>
      Given care unit couldn't be found in the EHR
    </td>
  </tr>
  
  <tr>
    <td>
      RESOURCE_NOT_FOUND
    </td>
    
    <td>
      Given resource couldn't be found in the EHR
    </td>
  </tr>
  
  <tr>
    <td>
      INSTANCE_CONFIG_NOT_FOUND
    </td>
    
    <td>
      Instance config not found
    </td>
  </tr>
  
  <tr>
    <td>
      HEALTHCARE_SERVICE_NOT_FOUND
    </td>
    
    <td>
      Given healthcare service couldn't be found in the EHR
    </td>
  </tr>
  
  <tr>
    <td>
      MEDICAL_NOTE_MAPPING_NOT_FOUND
    </td>
    
    <td>
      Medical note mapping not found for provided template id
    </td>
  </tr>
</tbody>
</table>

## 409 Conflict

<table>
<thead>
  <tr>
    <th>
      Error Code
    </th>
    
    <th>
      Default Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      PATIENT_ALREADY_EXISTS
    </td>
    
    <td>
      The EHR reported that the given patient already exists in their records
    </td>
  </tr>
</tbody>
</table>

## 429 Too Many Requests

<table>
<thead>
  <tr>
    <th>
      Error Code
    </th>
    
    <th>
      Default Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      RATE_LIMIT_EXCEEDED
    </td>
    
    <td>
      Rate limit exceeded, please try again later.
    </td>
  </tr>
</tbody>
</table>

## 500 Internal Server Error

<table>
<thead>
  <tr>
    <th>
      Error Code
    </th>
    
    <th>
      Default Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      UNEXPECTED_EMR_CHANGE
    </td>
    
    <td>
      There seem to be an unexpected change in the EHR
    </td>
  </tr>
</tbody>
</table>

## 501 Not Implemented

<table>
<thead>
  <tr>
    <th>
      Error Code
    </th>
    
    <th>
      Default Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      MEDICAL_NOTE_TEMPLATE_NOT_IMPLEMENTED
    </td>
    
    <td>
      This medical note template is not implemented for the given EHR
    </td>
  </tr>
</tbody>
</table>

## 503 Service Unavailable

<table>
<thead>
  <tr>
    <th>
      Error Code
    </th>
    
    <th>
      Default Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      EHR_CONNECTION_ERROR
    </td>
    
    <td>
      Failed to connect to the EHR system. Please check the EHR URL and network connectivity.
    </td>
  </tr>
</tbody>
</table>


## Sitemap

See the full [sitemap](https://docs.leyr.io/sitemap.md) for all pages.
