{
 "openapi": "3.1.0",
 "info": {
  "title": "MapX Pet member alert subscriptions",
  "version": "1.0.0",
  "description": "Reuse your EXISTING mxk_ member account key, never an mxe_ events writer key. No new key or per-channel grants. Existing scopes: member:read to read subscription, notify:manage to register/update, notifications:read to poll/ack. Existing account owner key-management grants missing scopes. Select a granted account with X-MapXPet-Account if key has multiple accounts. All private routes require verified email and current membership (existing active/trialing/past_due grace policy, not elapsed current_period_end).\nPOST {} registers once; repeated POST never resets toggles. PUT supplies all three booleans, any combination, including all false. New registrations default all three channels false; event alerts also require explicit stored consent. Existing email/agent/digest preferences remain untouched. A true toggle does not override topic=off or email-only/agent-only routing. Coupon notices require explicit registration. Each channel enabled_at skips earlier source posts on re-enable. Opt-out prevents future canonical notices and queued webhook delivery; history stays readable while membership remains eligible.\nBot delivery is POLLING, not required webhooks. since is exclusive cursor; omitted since uses per-key/account ack. Scan pages with has_more=true even when notifications=[]; next_cursor advances past rows not routed to agent. Persist notification id dedupe, durably process, then POST ack {cursor:next_cursor}. Ack is monotonic, account/key isolated, rejects future cursor; never deletes history. Explicit since=0 replays history. At-least-once until ack, client dedupes. Poll at >=300 seconds; drain has_more pages. Poll causes no outbound delivery.\nEvents: new public events API posts, existing city+province/date/events/free_services preferences and nearby ranking, only paid verified members, account/event dedupe. Nonmembers get no alerts, not later alerts. Coupons: active unexpired partner_coupons linked to active paid business profile with current business subscription/grace, valid local city or national coupon, member preferences; first cron run baselines old coupons, future eligible coupon notices deduped per account/coupon. Real owner profiles and reciprocal explicit-criteria matching; see /api/v1/member/alert-onboarding/schema. Runtime producer status is exposed in subscription response.\nHumans receive email from the same canonical notice, respecting existing routing. Instant email supported; daily/weekly remains queued with no digest sender implemented. Transport failure audited, no automatic email retry after notice row exists. Scheduler readiness and inbox delivery must be verified separately; this contract does not assert mail transport is enabled. Alert delivery is OFF; registration stores preferences only. Free-item watches: /api/v1/member/free-item-watch/schema. Docs: https://mapxpet.ca/docs/member-alerts/. Delivery (t839): every alert is one notification with a stable id (payload.id) delivered by email, pull (GET /api/v1/member/notifications) and optional signed push (PUT /api/v1/agents/me/webhook). A 2xx push is not returned again by the same key's default poll (?include_pushed=1 to include); POST /api/v1/member/notifications/ack {\"ids\":[...]} is idempotent and cancels a pending push. Failed pushes stay in the pull queue; retries max 5 attempts; auto-disable after 8 consecutive failures. See https://mapxpet.ca/docs/member-alerts/. Opt-in only (CASL): nothing is on by default; a member gets an alert type (event_alerts, partner_coupons, breeding_matches, free_items) only after explicitly setting that channel true (a free-item watch counts for free_items only). No email, push or pull entry otherwise; notification preferences are routing, not consent."
 },
 "servers": [
  {
   "url": "https://mapxpet.ca"
  }
 ],
 "security": [
  {
   "memberKey": []
  }
 ],
 "components": {
  "securitySchemes": {
   "memberKey": {
    "type": "http",
    "scheme": "bearer",
    "description": "Existing mxk_ member API key"
   }
  },
  "schemas": {
   "AlertSubscription": {
    "type": "object",
    "required": [
     "api_version",
     "account_id",
     "registered",
     "channels",
     "producers",
     "poll",
     "ack",
     "schema"
    ],
    "properties": {
     "api_version": {
      "const": "v1"
     },
     "account_id": {
      "type": "string"
     },
     "registered": {
      "type": "boolean"
     },
     "channels": {
      "type": "object",
      "additionalProperties": false,
      "required": [
       "partner_coupons",
       "event_alerts",
       "breeding_matches"
      ],
      "properties": {
       "partner_coupons": {
        "type": "boolean"
       },
       "event_alerts": {
        "type": "boolean"
       },
       "breeding_matches": {
        "type": "boolean"
       },
       "free_items": {
        "type": "boolean"
       }
      }
     },
     "enabled_at": {
      "type": "object",
      "additionalProperties": {
       "type": "integer"
      }
     },
     "producers": {
      "type": "object",
      "properties": {
       "event_alerts": {
        "const": "scheduled"
       },
       "partner_coupons": {
        "const": "scheduled_promoted_paid_partner_coupons"
       },
       "breeding_matches": {
        "const": "reciprocal_explicit_owner_criteria"
       },
       "free_items": {
        "const": "scheduled_events_api_category_free-item"
       }
      }
     },
     "poll": {
      "type": "string"
     },
     "ack": {
      "type": "string"
     },
     "schema": {
      "type": "string",
      "format": "uri"
     },
     "delivery_enabled": {
      "type": "boolean",
      "description": "True only while the alert scheduler reports delivery on (latest run <= 45 min old)."
     },
     "delivery": {
      "type": "object",
      "description": "scheduler heartbeat, transports {pull, push status for this key}, dedupe rule"
     }
    }
   },
   "AlertNotice": {
    "type": "object",
    "required": [
     "schema",
     "id",
     "topic",
     "type",
     "created_at",
     "account_id",
     "cursor"
    ],
    "properties": {
     "schema": {
      "const": "mapxpet.notification/1"
     },
     "id": {
      "type": "string"
     },
     "topic": {
      "type": "string"
     },
     "type": {
      "type": "string"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "account_id": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "body": {
      "type": "string"
     },
     "url": {
      "type": [
       "string",
       "null"
      ]
     },
     "data": {
      "type": "object"
     },
     "cursor": {
      "type": "integer",
      "minimum": 0
     }
    }
   },
   "AlertPoll": {
    "type": "object",
    "required": [
     "api_version",
     "notifications",
     "next_cursor",
     "has_more",
     "poll_after_seconds"
    ],
    "properties": {
     "api_version": {
      "const": "v1"
     },
     "notifications": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/AlertNotice"
      }
     },
     "next_cursor": {
      "type": "string",
      "pattern": "^[0-9]+$"
     },
     "has_more": {
      "type": "boolean"
     },
     "poll_after_seconds": {
      "const": 300
     }
    }
   },
   "AlertAck": {
    "type": "object",
    "required": [
     "acked_through"
    ],
    "properties": {
     "acked_through": {
      "type": "integer",
      "minimum": 0
     }
    }
   },
   "AlertError": {
    "type": "object",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "object",
      "required": [
       "code",
       "message",
       "status",
       "docs"
      ],
      "properties": {
       "code": {
        "type": "string"
       },
       "message": {
        "type": "string"
       },
       "status": {
        "type": "integer"
       },
       "docs": {
        "type": "string",
        "format": "uri"
       }
      }
     }
    }
   }
  }
 },
 "paths": {
  "/api/v1/member/alert-subscriptions": {
   "get": {
    "description": "Requires member:read",
    "parameters": [
     {
      "in": "header",
      "name": "X-MapXPet-Account",
      "schema": {
       "type": "string"
      },
      "description": "Only your granted member account."
     }
    ],
    "responses": {
     "200": {
      "description": "Success JSON object",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertSubscription"
        }
       }
      }
     },
     "400": {
      "description": "bad_request; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "401": {
      "description": "unauthenticated / invalid_key / key_revoked; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "403": {
      "description": "insufficient_scope / verification_required / membership_required / no_account; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "404": {
      "description": "not_found (including ungranted account); {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "409": {
      "description": "account_selection_required; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited; Retry-After; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "500": {
      "description": "internal; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     }
    }
   },
   "post": {
    "description": "Requires notify:manage",
    "parameters": [
     {
      "in": "header",
      "name": "X-MapXPet-Account",
      "schema": {
       "type": "string"
      },
      "description": "Only your granted member account."
     }
    ],
    "responses": {
     "200": {
      "description": "Success JSON object",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertSubscription"
        }
       }
      }
     },
     "400": {
      "description": "bad_request; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "401": {
      "description": "unauthenticated / invalid_key / key_revoked; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "403": {
      "description": "insufficient_scope / verification_required / membership_required / no_account; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "404": {
      "description": "not_found (including ungranted account); {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "409": {
      "description": "account_selection_required; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited; Retry-After; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "500": {
      "description": "internal; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "additionalProperties": false
       }
      }
     }
    }
   },
   "put": {
    "description": "Requires notify:manage",
    "parameters": [
     {
      "in": "header",
      "name": "X-MapXPet-Account",
      "schema": {
       "type": "string"
      },
      "description": "Only your granted member account."
     }
    ],
    "responses": {
     "200": {
      "description": "Success JSON object",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertSubscription"
        }
       }
      }
     },
     "400": {
      "description": "bad_request; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "401": {
      "description": "unauthenticated / invalid_key / key_revoked; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "403": {
      "description": "insufficient_scope / verification_required / membership_required / no_account; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "404": {
      "description": "not_found (including ungranted account); {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "409": {
      "description": "account_selection_required; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited; Retry-After; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "500": {
      "description": "internal; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "channels"
        ],
        "additionalProperties": false,
        "properties": {
         "channels": {
          "type": "object",
          "additionalProperties": false,
          "required": [
           "partner_coupons",
           "event_alerts",
           "breeding_matches"
          ],
          "properties": {
           "partner_coupons": {
            "type": "boolean"
           },
           "event_alerts": {
            "type": "boolean"
           },
           "breeding_matches": {
            "type": "boolean"
           },
           "free_items": {
            "type": "boolean",
            "description": "Optional (default false). Events posted with category free-item in your saved city -> topic free_items."
           }
          }
         },
         "webhook_url": {
          "type": "string",
          "maxLength": 500,
          "pattern": "^https://",
          "description": "Optional (mxk_ agent keys): registers/updates this key's push webhook, same rules as PUT /api/v1/agents/me/webhook."
         }
        }
       }
      }
     }
    }
   },
   "delete": {
    "summary": "Disable all three saved alert channels; also cancel pending onboarding intent",
    "security": [
     {
      "agentKey": []
     }
    ],
    "responses": {
     "200": {
      "description": "Cancelled; delivery_enabled:false; history preserved"
     }
    }
   }
  },
  "/api/v1/member/notifications": {
   "get": {
    "description": "Requires notifications:read",
    "parameters": [
     {
      "in": "header",
      "name": "X-MapXPet-Account",
      "schema": {
       "type": "string"
      },
      "description": "Only your granted member account."
     },
     {
      "in": "query",
      "name": "since",
      "schema": {
       "type": "string",
       "pattern": "^[0-9]+$"
      }
     },
     {
      "in": "query",
      "name": "limit",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 50
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Success JSON object",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertPoll"
        }
       }
      }
     },
     "400": {
      "description": "bad_request; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "401": {
      "description": "unauthenticated / invalid_key / key_revoked; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "403": {
      "description": "insufficient_scope / verification_required / membership_required / no_account; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "404": {
      "description": "not_found (including ungranted account); {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "409": {
      "description": "account_selection_required; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited; Retry-After; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "500": {
      "description": "internal; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     }
    }
   }
  },
  "/api/v1/member/notifications/ack": {
   "post": {
    "description": "Requires notifications:read",
    "parameters": [
     {
      "in": "header",
      "name": "X-MapXPet-Account",
      "schema": {
       "type": "string"
      },
      "description": "Only your granted member account."
     }
    ],
    "responses": {
     "200": {
      "description": "Success JSON object",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertAck"
        }
       }
      }
     },
     "400": {
      "description": "bad_request; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "401": {
      "description": "unauthenticated / invalid_key / key_revoked; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "403": {
      "description": "insufficient_scope / verification_required / membership_required / no_account; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "404": {
      "description": "not_found (including ungranted account); {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "409": {
      "description": "account_selection_required; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited; Retry-After; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     },
     "500": {
      "description": "internal; {error:{code,message,status,docs,...}}",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AlertError"
        }
       }
      }
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "cursor"
        ],
        "properties": {
         "cursor": {
          "oneOf": [
           {
            "type": "integer",
            "minimum": 0
           },
           {
            "type": "string",
            "pattern": "^[0-9]+$"
           }
          ]
         }
        }
       }
      }
     }
    }
   }
  },
  "/api/v1/member/alert-subscriptions/schema": {
   "get": {
    "security": [],
    "responses": {
     "200": {
      "description": "Public OpenAPI contract"
     }
    }
   }
  }
 },
 "x-examples": {
  "toggles": {
   "channels": {
    "partner_coupons": true,
    "event_alerts": true,
    "breeding_matches": false,
    "free_items": false
   }
  },
  "poll": {
   "api_version": "v1",
   "notifications": [
    {
     "schema": "mapxpet.notification/1",
     "id": "nt_example",
     "topic": "local_events",
     "type": "event.new",
     "account_id": "ma_example",
     "title": "Example event",
     "data": {
      "event_id": "ev_example",
      "free": true
     },
     "cursor": 42
    }
   ],
   "next_cursor": "42",
   "has_more": false,
   "poll_after_seconds": 300
  },
  "push_headers": {
   "X-MapXPet-Notification-Id": "nt_example",
   "X-MapXPet-Delivery-Id": "wd_example",
   "X-MapXPet-Attempt": "1",
   "X-MapXPet-Timestamp": "1794340000",
   "X-MapXPet-Signature": "v1=<hex HMAC-SHA256(secret, timestamp + \".\" + raw_body)>"
  }
 }
}