> ## Documentation Index
> Fetch the complete documentation index at: https://api-docs.getmeadow.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> How to handle errors returned from Meadow endpoints

Meadow uses  HTTP response codes to indicate the success or failure of an API request. 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, a order could not be created, etc.). Codes in the `5xx` range indicate an error with Meadow's servers (which should happen very infrequently).

# Error Response

When an error is returned, it will be in the following format

<ResponseField name="message" type="string">
  A human readable string to describe the error to a developer
</ResponseField>

<ResponseField name="code" type="string">
  A code pertaining to a specific Meadow error (Example: `INVALID_API_CREDENTIALS`)
</ResponseField>

<ResponseField name="meta" type="object">
  Some errors will contain additional information in this object to help debug the issue
</ResponseField>

### Example

```json theme={"system"}
{
  "error": {
    "message": "Your API credentials are invalid.",
    "code": "INVALID_API_CREDENTIALS"
  }
}
```

# Error Codes

Below is a list of error codes that Meadow may return on various requests. This list does not contain every single error that is possible, so we encourage you to handle unknown codes that you have not seen before.

### `INSUFFICIENT_PERMISSIONS`

The `X-Client-Key` is valid but does not have the proper permissions for that endpoint

```json theme={"system"}
{
  "error": {
    "message": "This API client key does not have permissions to perform this request.",
    "code": "INSUFFICIENT_PERMISSIONS"
  }
}
```

### `INVALID_API_CREDENTIALS`

Thrown when either the `X-Consumer-Key` or `X-Client-Key` provided is invalid

```json theme={"system"}
{
  "error": {
    "message": "Your API credentials are invalid.",
    "code": "INVALID_API_CREDENTIALS"
  }
}
```

### `INVALID_CHILD_RESOURCE`

Thrown when data submitted is not owned by the parent resource specified (Example: Submitting options that belong to another product)

```json theme={"system"}
{
  "error": {
    "message": "That child resource does not belong to the specified parent.",
    "code": "INVALID_CHILD_RESOURCE"
  }
}
```

### `INVALID_IDEMPOTENCY_KEY`

The`idempotencyKey` submitted is not a valid uuid v4. We recommend using the `idempotencyKey` returned from pricing so you do not run into this error.

```json theme={"system"}
{
  "error": {
    "message": "idempotencyKey must be a uuid v4",
    "code": "INVALID_IDEMPOTENCY_KEY"
  }
}
```

### `INVALID_INVENTORY_TYPE`

A product option ID was or was not passed when it was supposed to. Check the `inventoryType` of the product. If it is `option` then `productOptionId` should be passed, otherwise do not include this ID in the purchase order line item.

```json theme={"system"}
{
  "error": {
    "message": "Incorrect inventory type submitted.",
    "code": "INVALID_INVENTORY_TYPE"
  }
}
```

### `INVALID_PARAMS`

One or more of the properties in the request body is invalid.

```json theme={"system"}
{
  "error": {
    "message": "type must be one of: delivery, pickup, in-store.",
    "code": "INVALID_PARAMS"
  }
}
```

### `INVALID_ORDER`

An order was unable to be created for an unknown reason

```json theme={"system"}
{
  "error": {
    "message": "The order you submitted was malformed.",
    "code": "INVALID_ORDER"
  }
}
```

### `INVALID_ORDER_QUANTITY`

Thrown when a line item has an invalid quantity

```json theme={"system"}
{
  "error": {
    "message": "Orders cannot contain negative quantities.",
    "code": "INVALID_ORDER_QUANTITY"
  }
}
```

### `INVALID_ORDER_TYPE`

Throw when an order type (example: `pickup`) is submitted but the organization does not allow that type of order

```json theme={"system"}
{
  "error": {
    "message": "The organization does not support that order type.",
    "code": "INVALID_ORDER_TYPE"
  }
}
```

### `MISSING_PARAMS`

The request body is missing a required parameter

```json theme={"system"}
{
  "error": {
    "message": "Please enter your address.",
    "code": "MISSING_PARAMS",
    "meta": {
      "missing": [
        "address"
      ]
    }
  }
}
```

### `NON_ZERO_INVENTORY`

This product has non zero inventory and the product (or option) cannot be deleted.  Ask the client organization to zero out the inventory.

```json theme={"system"}
{
"error": {
  "message": "This operation may not be performed while a product has inventory.",
  "code": "NON_ZERO_INVENTORY"
}
```

### `ORDER_MINIMUM_NOT_MET`

Organizations may set minimums for orders. This is thrown if the final total is under the minimum.

```json theme={"system"}
{
  "error": {
    "message": "The amount you submitted is under the order minimum for this organization.",
    "code": "ORDER_MINIMUM_NOT_MET",
    "meta": {
      "minimum": "$75"
    }
  }
}
```

### `OUT_OF_STOCK`

Thrown when there is not enough inventory of a product or product option to create an order

```json theme={"system"}
{
  "error": {
    "message": "An order line exceeds current inventory.",
    "code": "OUT_OF_STOCK",
    "meta": {
      "lineItem": {
        "productOptionId": 2307,
        "quantity": 1,
        "specifiedPackageId": null
      },
      "product": {
        "name": "Blue Dream"
      }
    }
  }
}
```

### `PRODUCT_CATEGORY_NOT_FOUND`

We could not find the category. Please use the product categories API to get a list of valid category names.

```json theme={"system"}
{
  "error": {
    "message": "A primary category with that name was not found.",
    "code": "PRODUCT_CATEGORY_NOT_FOUND"
  }
}
```

### `PRODUCT_IS_INACTIVE`

Thrown when an organization has removed a product from their menu, but an order was submitted with it.

```json theme={"system"}
{
  "error": {
    "message": "One of the products you submitted is currently inactive.",
    "code": "PRODUCT_IS_INACTIVE",
    "meta": {
      "productId": 994
    }
  }
}
```

### `PURCHASE_LIMIT_EXCEEDED`

Each state has its own set of purchase limits. When an order would put a customer over the limit, this error is thrown

```json theme={"system"}
{
  "error": {
    "message": "This order is over the daily purchase limit by 3.36g of non-concentrated cannabis (flowers).",
    "code": "PURCHASE_LIMIT_EXCEEDED",
    "meta": {
      "overages": [
        {
          "cannabisType": "non-concentrated",
          "limit": "28.5",
          "total": "31.86",
          "overage": "3.36"
        }
      ]
    }
  }
}
```

### `PURCHASE_ORDER_CLOSED`

The purchase order status is closed and no more updates can be made. You can ask the organization to reopen from Meadow.

```json theme={"system"}
{
  "error": {
    "message": "This purchase order is already closed. You may only set paymentStatus to paid.",
    "code": "PURCHASE_ORDER_CLOSED"
  }
}
```

### `PURCHASE_ORDER_LINE_ITEM_RECEIVED`

This line item has been received and cannot be edited or deleted.

```json theme={"system"}
{
  "error": {
    "message": "Purchase Order Line Items that already have receptions may not be edited.",
    "code": "PURCHASE_ORDER_LINE_ITEM_RECEIVED"
  }
}
```

### `PURCHASE_ORDER_MISSING_CUSTOM_DATE`

For customer payment terms, `paymentTermsDueDate` must be submitted.

```json theme={"system"}
{
  "error": {
    "message": "Purchase Orders with paymentTerms: Custom must have a paymentTermsDueDate",
    "code": "PURCHASE_ORDER_MISSING_CUSTOM_DATE"
  }
}
```

### `TRANSACTION_RETRY_EXCEEDED`

This error should be very rare, but if it is thrown, show a generic error to the customer with a button to submit the order again.

```json theme={"system"}
{
  "error": {
    "message": "Retry limit exceeded for concurrent transactions. Retry the request.",
    "code": "TRANSACTION_RETRY_EXCEEDED"
  }
}
```

### `USER_NOT_FOUND`

Thrown when a customer cannot be found for the information submitted.

```json theme={"system"}
{
  "error": {
    "message": "A user was not found for that information.",
    "code": "USER_NOT_FOUND"
  }
}
```
