Namespace
Všechny endpointy mají namespace affinite-affiliate/v1. Base URL: {site_url}/wp-json/affinite-affiliate/v1/
Permission callbacks
- admin_permissions_check — vyžaduje
manage_optionscapability. - affiliate_permissions_check — admin nebo přihlášený affiliate (active status).
- track_conversion_permissions_check — vyžaduje
X-Affinite-API-Keyheader.
Affiliates endpoints
- GET /affiliates — seznam affiliate (admin). Args: page, per_page, search, status, orderby, order.
- GET /affiliates/{id} — detail (admin nebo vlastník).
- PUT /affiliates/{id} — update (admin pro všechna pole, vlastník pro profilová pole).
Commissions endpoints
- GET /commissions — seznam komisí. Args: page, per_page, status (enum: pending/approved/paid/rejected/refunded), type (enum: sale/subpartner/custom_form/refund).
- POST /commissions/{id}/approve — schválí provizi (admin).
Statistics endpoints
- GET /stats/overview — overview pro admin dashboard (cached 5 min).
- GET /stats/affiliate/{id} — stats pro affiliate (basic + monthly + recent_clicks + recent_conversions).
Tracking endpoint
- POST /track/conversion — pro custom form integrace. Vyžaduje
X-Affinite-API-Keyheader. Per-IP rate limit 10/min. Args: affiliate_code (required), amount (required, 0-1000000), form_id (optional), customer_email (optional, email format).
Links endpoint
- POST /links/generate — vygeneruje affiliate link pro přihlášeného affiliate. Args: url (optional, default home_url), campaign (optional).
Clicks analytics
- GET /clicks/monthly — měsíční data pro chart v dashboardu. Args: month (1-12), year (2020+).
- Response: clicks_data per day, total_clicks, conversions, conversion_rate, top_sources, device_breakdown, navigation flags (has_prev/next_data).
Příklad volání s WP REST client
// Server-side PHP
$response = wp_remote_get(
rest_url('affinite-affiliate/v1/stats/overview'),
[
'headers' => [
'X-WP-Nonce' => wp_create_nonce('wp_rest'),
],
]
);
$data = json_decode(wp_remote_retrieve_body($response), true);
