All API endpoints are located under /api and share common bootstrap logic from:
api/_bootstrap.php
Common response format:
- Success:
{"success": true, "...": "..."} - Error:
{"success": false, "message": "..."}
- Loads
includes/config.phpandincludes/functions.php - Calls
ensureRewardClaimSchema()(runtime schema prep; should be migrated away) - Provides helpers:
apiJsonResponse,apiSuccessResponse,apiErrorResponseapiRequireMethodapiGetRequestedUserIdapiGetAuthenticatedUserapiResolveAuthorizedUserIdapiRequireRewardIssuer
- API calls rely on current session context (user/admin cookies).
apiGetAuthenticatedUser():- accepts admin session (
admin_id) as privileged actor - accepts logged-in user session via app auth helpers
- accepts admin session (
apiResolveAuthorizedUserId()prevents normal users from reading/updating other users' reward data.
- Query:
user_id(optional for current user) - Response: available balance + cached profile balance
- Body:
user_id,amount,source, optionalaction_type,reference_id - Access: admin/reward issuer only
- Effect: inserts
reward_ledgerentry
- Query:
user_idoptional - Returns consolidated reward dashboard payload:
- balances
- claim eligibility
- open/recent claims
- recent ledger entries
- mini task/task stats and security signals
- Query:
user_idoptional - Returns active task list for authorized user
- Body:
task_id, optionalproof, optionaluser_id - Completes task or submits for review depending on task config
- Query:
user_idoptional - Returns TaskHub mission state for authorized user
- Body:
task_key, optional payload fields (wallet_address,proof,x_handle,telegram_handle,answers_json, optionaluser_id) - Returns task result, updated state, and balance
- Body: optional
user_id - Locks available rewards and creates claim snapshot
- Query:
snapshot_id(required) - Returns snapshot details (scoped to actor unless admin)
- Most endpoint exceptions map to
422. - Special cases:
generate_claim.phpmay return409for already-prepared state.claim_status.phpmay return404when snapshot not found.- method mismatch returns
405viaapiRequireMethod.
- Uses prepared statements through shared helpers.
- Authorization checks are present for user scope and issuer scope.
- CSRF enforcement is not consistently explicit on all session-authenticated POST endpoints.