REST API & WP-CLI
The plugin exposes a full REST API (24 endpoints) and WP-CLI command set (7 commands) so you can automate sync, testing, and monitoring from CI/CD pipelines, external services, or the server command line.
REST API
Authentication
All endpoints require:
- A logged-in WordPress user with the correct capability.
- A valid WordPress REST nonce:
X-WP-Nonce: <nonce> - OR an Application Password (WP 5.6+) via HTTP Basic Auth.
Base URL:
https://your-domain.com/wp-json/wkpbic/v1
Endpoint Summary
| Resource | Method | Endpoint | Purpose |
|---|---|---|---|
| Entities | GET | /entities | List all registered entities |
| GET | /entities/{slug}/schema | Column definitions for an entity | |
| GET | /entities/{slug}/preview | Preview rows (default 25) | |
| GET | /entities/{slug}/count | Total row count | |
| Sync | POST | /sync/manual | Trigger manual sync (requires entity and dataset_id) |
| GET | /sync/status | Current sync status and last sync results | |
| GET | /sync/logs | Recent sync logs (supports page, per_page, entity_type, status params) | |
| POST | /sync/schedule | Create or update sync schedule (enabled, frequency, time) | |
| GET/POST | /sync/profiles | List or create sync profiles | |
| Workspaces | GET | /workspaces | List Power BI workspaces |
| POST | /workspaces | Create a new workspace | |
| POST | /workspaces/activate | Set the active workspace (requires workspace_id) | |
| Datasets | GET | /datasets | List datasets in active workspace |
| POST | /datasets | Create a dataset (requires name, optional entity_types) | |
| POST | /datasets/{id}/publish | Publish dataset to Power BI | |
| DELETE | /datasets/{id} | Delete a dataset | |
| Tables | GET | /tables/{dataset_id} | List tables in a dataset |
| POST | /tables | Create a table (requires dataset_id, table_name, entity_type) | |
| DELETE | /tables/{dataset_id}/{table_name}/rows | Clear all rows from a table | |
| Reports | GET | /reports | List imported reports |
| GET | /reports/{id}/embed-token | Get embed token for a report | |
| Dashboards | GET | /dashboards | List imported dashboards |
| GET | /dashboards/{id}/embed-token | Get embed token for a dashboard | |
| Alerts | GET | /alerts | List all alerts |
| POST | /alerts | Create alert (requires name, metric, notify_email) | |
| PUT | /alerts/{id} | Update an alert | |
| DELETE | /alerts/{id} | Delete an alert | |
| POST | /alerts/{id}/test | Test fire an alert |
Example — Trigger sync
Triggers a manual sync for the orders entity to a specific dataset.
curl -X POST "https://your-domain.com/wp-json/wkpbic/v1/sync/manual" \
-H "X-WP-Nonce: <nonce>" \
-H "Content-Type: application/json" \
-b cookies.txt \
-d '{"entity":"orders","dataset_id":"07a30802-ade3-4349-..."}'
Example — Check sync status
Returns current sync state and the most recent sync results per entity.
curl "https://your-domain.com/wp-json/wkpbic/v1/sync/status" \
-H "X-WP-Nonce: <nonce>" \
-b cookies.txt
Response:
{
"is_syncing": false,
"last_syncs": [
{
"id": "264",
"entity_type": "orders",
"status": "completed",
"rows_pushed": "342",
"duration_seconds": "5",
"completed_at": "2026-04-10 13:00:00"
}
]
}
Example — List entities
Returns all registered data types with slug, label, and description.
curl "https://your-domain.com/wp-json/wkpbic/v1/entities" \
-H "X-WP-Nonce: <nonce>" \
-b cookies.txt
Response:
[
{
"slug": "orders",
"label": "Orders",
"description": "WooCommerce orders with all order data.",
"icon": "dashicons-cart"
},
{
"slug": "customers",
"label": "Customers",
"description": "Customer profiles and user data.",
"icon": "dashicons-groups"
}
]
WP-CLI Commands
All commands live under the wp wkpbic namespace.
wp wkpbic status
Shows connection status, token expiry, active workspace, last sync timestamp, and counts per entity.
wp wkpbic status
Expected output:
Connection: Connected
Token expiry: 2026-04-10 14:32 UTC (52 min remaining)
Workspace: WooCommerce Store (a1b2c3d4-...)
Last sync: 2026-04-10 13:00 UTC — orders — 342 rows — 4.8s
Entities: orders (12,450) | products (890) | customers (3,210)
wp wkpbic test-connection
Runs a 3-step validation: (1) decrypt credentials, (2) request an OAuth token, (3) call the Power BI API. Output is a clear pass/fail per step with remediation hints.
wp wkpbic test-connection
Expected output:
Step 1 — Decrypt credentials ............ PASS
Step 2 — Request OAuth token ............ PASS
Step 3 — Call Power BI API .............. PASS
All checks passed.
wp wkpbic sync
Trigger a sync from the command line.
# Sync one entity (incremental)
wp wkpbic sync --entity=orders
# Sync everything
wp wkpbic sync --full
# Run a saved profile
wp wkpbic sync --profile="Daily Orders"
# Specify batch size
wp wkpbic sync --entity=products --batch=1000
wp wkpbic list-entities
Lists every registered entity with status and row count.
wp wkpbic list-entities
wp wkpbic list-entities --format=json
wp wkpbic list-datasets
Lists datasets in the active workspace.
wp wkpbic list-datasets
wp wkpbic logs
View recent logs with filters.
wp wkpbic logs --limit=20
wp wkpbic logs --entity=orders --status=failed
wp wkpbic logs --since="2026-04-01"
wp wkpbic flush-cache
Clear all plugin caches and transients.
wp wkpbic flush-cache
Automating Common Tasks
Nightly sync via system cron
Run a full sync at 2 AM every night and log the output. Use system cron (not WP-Cron) for reliability.
0 2 * * * cd /var/www/html && wp wkpbic sync --profile="Nightly Full" >> /var/log/wkpbic.log 2>&1
CI/CD health check
Add this to your deployment pipeline to verify Power BI connectivity after each deploy. Exits with code 1 if any check fails.
#!/bin/bash
set -e
wp wkpbic test-connection || exit 1
wp wkpbic status
Slack notification on failure
Run an hourly sync and post to Slack if it fails. Set $SLACK_WEBHOOK in your environment variables.
wp wkpbic sync --profile="Hourly" || \
curl -X POST -H 'Content-type: application/json' \
--data '{"text":"WC Power BI sync failed on prod!"}' \
"$SLACK_WEBHOOK"
Response Format
All REST endpoints return JSON with a consistent envelope:
{
"success": true,
"data": { ... },
"meta": {
"request_id": "abc123",
"timestamp": "2026-04-09T09:15:00Z"
}
}
Errors use standard WordPress REST error shapes:
{
"code": "wkpbic_auth_failed",
"message": "Azure AD token refresh failed",
"data": { "status": 401 }
}
