Skip to navigation

Handle API errors and rate limits

The Middesk API uses HTTP status codes to indicate whether a request succeeded. Use the status code and response body to decide whether to correct the request or retry it.

Status codes

Codes in the 2xx range indicate success. Codes in the 4xx range indicate a request or access problem. Codes in the 5xx range indicate a server error.

Status codeMeaning
200OK — The request succeeded.
201Created — The object was created.
202Accepted — The request was accepted for processing.
400Bad Request — The request was unacceptable.
401Unauthorized — Valid authentication credentials are required.
403Forbidden — The credentials do not allow the requested operation.
404Not Found — The requested resource does not exist.
422Validation — A parameter was not formatted correctly.
429Too Many Requests — The request exceeded a rate limit.
500Internal Server Error — Middesk encountered an internal server error.

Error messages

Most API errors return JSON with an errors array. Each error contains a message and can include a parameter identifying the affected field. Rate-limited requests can return plain text instead; check the 429 response formats before parsing the body as JSON.

Example validation error
{
"errors": [
{
"message": "Name is required",
"parameter": "name"
},
{
"message": "Address line1 is required",
"parameter": "address.address_line1"
}
]
}

Rate limits

Middesk tracks most limits by credential. Each API key and OAuth access token has its own limits, so your sandbox and Production keys do not share them. Requests that exceed a limit return 429 Too Many Requests.

Default limit

Requests to /v1/ endpoints share a limit of 20 requests per second for each credential, except autocomplete, which has separate limits below.

Endpoint-specific limits

EndpointLimit
PATCH /v1/businesses/{id}5 requests per 15 seconds for each credential and business, in addition to the default limit
POST /v1/identities/autocomplete20 requests per second for each credential and 20 requests per second for each IP address, instead of the default limit

Your frontend usually sends autocomplete requests with the same Publishable API key, so all end users share that key’s limit.

Sandbox business creation limit

In sandbox, each account can create up to 120 businesses per minute. These requests share the limit:

  • POST /v1/businesses
  • The createBusiness GraphQL mutation
  • POST /v1/business_batches, where each batch row counts as one business

The limit resets at the start of each minute. Contact your account manager to raise this sandbox limit.

Handling 429 responses

The response format depends on the limit exceeded:

LimitResponse bodyRetry-After header
Default and endpoint-specific limitsPlain text Retry laterNot included
Sandbox business creation limitJSON errors array with the message Rate limit exceededSeconds until the limit resets
1

Wait before retrying

If the response includes Retry-After, wait that many seconds. Otherwise, use exponential backoff: wait about one second, double the delay after each consecutive 429, and add random jitter so workers do not retry at the same moment.

2

Limit retry attempts

Stop after a fixed number of attempts and surface the error. This example returns the final response so the caller can handle it.

Retry a request after a 429 response
import random
import time
import requests
def request_with_retry(method, url, max_attempts=5, **kwargs):
if max_attempts < 1:
raise ValueError("max_attempts must be at least 1")
kwargs.setdefault("timeout", 30)
delay = 1
for attempt in range(1, max_attempts + 1):
response = requests.request(method, url, **kwargs)
if response.status_code != 429 or attempt == max_attempts:
return response
retry_after = response.headers.get("Retry-After")
time.sleep(float(retry_after) if retry_after else delay + random.uniform(0, delay))
delay *= 2

Reducing request volume

  • Use webhooks to learn when a business changes instead of polling GET /v1/businesses/{id}.
  • Use business batches to create many businesses in one request. In sandbox, each row still counts toward the business creation limit.
  • Combine changes to the same business into one PATCH request.
Get a demo
Contact your account manager or contact sales to inquire about access.