Skip to content

REST API v1 Overview

Base URL: /wp-json/middag-account/v1/

The middag-account REST API exposes 79 endpoints across 18 groups. All endpoints use the WordPress REST API infrastructure with permission_callback on every route.

Authentication Methods

The API supports triple authentication depending on context:

MethodHeader / MechanismUsed By
JWT RS256Authorization: Bearer {token}Portal, mobile, third-party
WordPress NonceX-WP-Nonce cookie-basedwp-admin (Inertia UI)
WC API KeysConsumer key + secret (WooCommerce native)WooCommerce integrations

JWT Details

  • Algorithm: RS256 (RSA + SHA-256). Never HS256.
  • Access token TTL: 24 hours
  • Refresh token TTL: 7 days (mandatory rotation)
  • Private key stored outside the webroot
  • Payload fields at top level: sub, org, roles, scopes, company
json
{
    "sub": 42,
    "org": 15,
    "roles": [
        "admin"
    ],
    "scopes": [
        "organization",
        "finances",
        "orders"
    ],
    "company": "middag_br",
    "iat": 1714200000,
    "exp": 1714286400
}

Required Headers

HeaderDirectionRequiredValue
AuthorizationRequestYes *Bearer {jwt_token}
X-Middag-OrganizationRequestYes **Organization ID (int)
X-Middag-CompanyRequestNomiddag_br or middag_global
Content-TypeRequestYes (POST/PUT)application/json

* Except /auth/login, /auth/register, and other public endpoints. ** Except endpoints that do not operate on organization-scoped data.

Response Envelope

Every endpoint returns a consistent JSON envelope:

json
{
    "success": true,
    "data": {},
    "meta": {
        "page": 1,
        "per_page": 20,
        "total": 100,
        "pages": 5
    },
    "message": null,
    "errors": null
}
FieldTypeAlways PresentDescription
successbooleanYestrue for 2xx, false for errors
data`objectarray`Yes
meta`objectnull`Yes
message`stringnull`Yes
errors`objectnull`Yes

Pagination

List endpoints accept these query parameters:

ParameterTypeDefaultDescription
pageint1Current page
per_pageint20Items per page (max: 100)
orderstringdescSort direction: asc or desc
orderbystringcreated_atSort field
searchstring--Text search (when supported)

Error Codes

CodeHTTPWhen
VALIDATION_ERROR422Invalid input fields
AUTHENTICATION_ERROR401Missing, expired, or invalid token
AUTHORIZATION_ERROR403Insufficient permissions
NOT_FOUND404Resource does not exist
CONFLICT409Conflicting state
RATE_LIMIT429Rate limit exceeded
INTERNAL_ERROR500Unexpected server error

Error Response Example

json
{
    "success": false,
    "data": null,
    "meta": null,
    "message": "Validation failed",
    "errors": {
        "code": "VALIDATION_ERROR",
        "fields": {
            "email": [
                "Email is required"
            ],
            "name": [
                "Name must be at least 2 characters"
            ]
        }
    }
}

Rate Limiting

EndpointLimitWindowPer
/auth/login51 minuteIP
/auth/register31 minuteIP
/auth/forgot-password35 minutesIP
/auth/resend-verification35 minutesEmail
/auth/refresh101 minuteUser ID
Other authenticated endpoints601 minuteUser ID

Exceeded requests receive HTTP 429 with a Retry-After header.

Middleware Pipeline

Every authenticated request passes through this middleware chain in order:

  1. AuthMiddleware -- Extract and validate JWT, set WP_User in request context
  2. PermissionsMiddleware -- Validate role and scopes against route requirements
  3. OrganizationMiddleware -- Validate X-Middag-Organization header and membership
  4. CompanyMiddleware -- Validate X-Middag-Company header (if route is company-scoped)

Stability Contract

REST API v1 guarantees no breaking changes within v1. New endpoints are additive. Existing fields are never removed. Deprecation comes with 6 months advance notice.

Endpoint Groups

GroupEndpointsReference
Auth12/auth/*
Organizations7organizations.md
Collaborators8collaborators.md
Entitlements6entitlements.md
Orders4orders.md
Invoices4invoices.md
Tax Invoices4invoices.md
Quotes5quotes.md
Licenses4licenses.md
Contracts3contracts.md
Environments4environments.md
Services3services.md
Service Requests4services.md
Documents3--
Downloads2--
Affiliates2--
Admin2--
Webhooks2--