| 1 |
# REST API Reference |
| 2 |
|
| 3 |
CartFlows exposes a REST API under the `cartflows/v1` namespace. All endpoints are admin-only — they require authentication and the appropriate CartFlows capability. |
| 4 |
|
| 5 |
## Base URL |
| 6 |
|
| 7 |
``` |
| 8 |
/wp-json/cartflows/v1/ |
| 9 |
``` |
| 10 |
|
| 11 |
## Authentication |
| 12 |
|
| 13 |
All endpoints require: |
| 14 |
1. A valid WordPress nonce sent as the `X-WP-Nonce` header |
| 15 |
2. The appropriate CartFlows capability (see each endpoint) |
| 16 |
|
| 17 |
In the React apps, `@wordpress/api-fetch` handles authentication automatically: |
| 18 |
|
| 19 |
```js |
| 20 |
import apiFetch from '@wordpress/api-fetch'; |
| 21 |
|
| 22 |
apiFetch.use( apiFetch.createNonceMiddleware( wcfEditorAppData.nonce ) ); |
| 23 |
``` |
| 24 |
|
| 25 |
## Custom Capabilities |
| 26 |
|
| 27 |
CartFlows registers two custom WordPress capabilities: |
| 28 |
|
| 29 |
| Capability | Purpose | |
| 30 |
|-----------|---------| |
| 31 |
| `cartflows_manage_flows_steps` | Create, edit, and delete flows and steps | |
| 32 |
| `cartflows_manage_settings` | Edit global plugin settings | |
| 33 |
|
| 34 |
These are assigned to WordPress roles via the **User Role Manager** in global settings. |
| 35 |
|
| 36 |
--- |
| 37 |
|
| 38 |
## Endpoints |
| 39 |
|
| 40 |
### 1. List Flows |
| 41 |
|
| 42 |
Retrieve a paginated list of all flows/funnels. |
| 43 |
|
| 44 |
``` |
| 45 |
POST /wp-json/cartflows/v1/admin/flows/ |
| 46 |
``` |
| 47 |
|
| 48 |
**Permission:** `cartflows_manage_flows_steps` |
| 49 |
|
| 50 |
**Request body (JSON):** |
| 51 |
|
| 52 |
| Parameter | Type | Default | Description | |
| 53 |
|-----------|------|---------|-------------| |
| 54 |
| `status` | string | `publish` | Filter by post status (`publish`, `draft`, `trash`, `any`) | |
| 55 |
| `page` | int | `1` | Page number | |
| 56 |
| `per_page` | int | `10` | Items per page | |
| 57 |
| `search` | string | `""` | Search term for flow title | |
| 58 |
| `start_date` | string | — | Start date for date range filter | |
| 59 |
| `end_date` | string | — | End date for date range filter | |
| 60 |
| `test_mode` | bool | `false` | Include test mode flows | |
| 61 |
|
| 62 |
**Response:** |
| 63 |
|
| 64 |
```json |
| 65 |
{ |
| 66 |
"success": true, |
| 67 |
"data": { |
| 68 |
"flows": [ /* Array of flow objects */ ], |
| 69 |
"total": 42, |
| 70 |
"flow_counts": { |
| 71 |
"active": 10, |
| 72 |
"draft": 5, |
| 73 |
"trash": 2 |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
``` |
| 78 |
|
| 79 |
**Flow object fields:** |
| 80 |
|
| 81 |
| Field | Type | Description | |
| 82 |
|-------|------|-------------| |
| 83 |
| `id` | int | Flow post ID | |
| 84 |
| `title` | string | Flow title | |
| 85 |
| `slug` | string | Flow URL slug | |
| 86 |
| `status` | string | Post status (publish/draft/trash) | |
| 87 |
| `steps` | array | Array of step summaries | |
| 88 |
| `revenue` | string | Revenue data (filtered via `cartflows_flow_revenue`) | |
| 89 |
|
| 90 |
--- |
| 91 |
|
| 92 |
### 2. Get Flow Data |
| 93 |
|
| 94 |
Retrieve complete data for a single flow including all steps and settings. |
| 95 |
|
| 96 |
``` |
| 97 |
GET /wp-json/cartflows/v1/admin/flow-data/{id} |
| 98 |
``` |
| 99 |
|
| 100 |
**Permission:** `cartflows_manage_flows_steps` |
| 101 |
|
| 102 |
**URL parameters:** |
| 103 |
|
| 104 |
| Parameter | Description | |
| 105 |
|-----------|-------------| |
| 106 |
| `id` | Flow post ID | |
| 107 |
|
| 108 |
**Response:** |
| 109 |
|
| 110 |
```json |
| 111 |
{ |
| 112 |
"success": true, |
| 113 |
"data": { |
| 114 |
"id": 123, |
| 115 |
"title": "My Sales Funnel", |
| 116 |
"slug": "my-sales-funnel", |
| 117 |
"link": "https://example.com/flows/my-sales-funnel", |
| 118 |
"status": "publish", |
| 119 |
"steps": [ /* Array of step objects */ ], |
| 120 |
"meta": { /* Flow meta options */ }, |
| 121 |
"settings": { /* Flow settings */ } |
| 122 |
} |
| 123 |
} |
| 124 |
``` |
| 125 |
|
| 126 |
--- |
| 127 |
|
| 128 |
### 3. Get Step Data |
| 129 |
|
| 130 |
Retrieve complete data for a single step including all settings, tabs, and configuration. |
| 131 |
|
| 132 |
``` |
| 133 |
GET /wp-json/cartflows/v1/admin/step-data/{id} |
| 134 |
``` |
| 135 |
|
| 136 |
**Permission:** `cartflows_manage_flows_steps` |
| 137 |
|
| 138 |
**URL parameters:** |
| 139 |
|
| 140 |
| Parameter | Description | |
| 141 |
|-----------|-------------| |
| 142 |
| `id` | Step post ID | |
| 143 |
|
| 144 |
**Response:** |
| 145 |
|
| 146 |
```json |
| 147 |
{ |
| 148 |
"success": true, |
| 149 |
"data": { |
| 150 |
"id": 456, |
| 151 |
"title": "Checkout Step", |
| 152 |
"type": "checkout", |
| 153 |
"flow_id": 123, |
| 154 |
"flow_title": "My Sales Funnel", |
| 155 |
"tabs": { /* Tab configuration */ }, |
| 156 |
"settings": { /* Step settings */ }, |
| 157 |
"page_settings": { /* Page settings */ }, |
| 158 |
"design_settings": { /* Design settings */ }, |
| 159 |
"meta": { /* Step post meta */ }, |
| 160 |
"links": { |
| 161 |
"view": "https://example.com/flows/my-sales-funnel/checkout-step", |
| 162 |
"edit": "https://example.com/wp-admin/...", |
| 163 |
"page_builder_edit": "https://example.com/wp-admin/..." |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
``` |
| 168 |
|
| 169 |
--- |
| 170 |
|
| 171 |
### 4. Get Common Settings |
| 172 |
|
| 173 |
Retrieve global CartFlows settings and their field definitions. |
| 174 |
|
| 175 |
``` |
| 176 |
GET /wp-json/cartflows/v1/admin/commonsettings/ |
| 177 |
``` |
| 178 |
|
| 179 |
**Permission:** `cartflows_manage_flows_steps` |
| 180 |
|
| 181 |
**Response:** |
| 182 |
|
| 183 |
```json |
| 184 |
{ |
| 185 |
"success": true, |
| 186 |
"data": { |
| 187 |
"settings": { |
| 188 |
"_cartflows_common": { /* General settings */ }, |
| 189 |
"_cartflows_permalink": { /* Permalink settings */ }, |
| 190 |
"_cartflows_facebook": { /* Facebook integration */ }, |
| 191 |
"_cartflows_google_analytics": { /* GA settings */ }, |
| 192 |
"_cartflows_roles": { /* User role settings */ } |
| 193 |
}, |
| 194 |
"fields": { /* Field definitions for settings form */ } |
| 195 |
} |
| 196 |
} |
| 197 |
``` |
| 198 |
|
| 199 |
--- |
| 200 |
|
| 201 |
### 5. Get Home Page Settings |
| 202 |
|
| 203 |
Retrieve dashboard configuration and visibility settings. |
| 204 |
|
| 205 |
``` |
| 206 |
GET /wp-json/cartflows/v1/admin/homepage/ |
| 207 |
``` |
| 208 |
|
| 209 |
**Permission:** `cartflows_manage_flows_steps` |
| 210 |
|
| 211 |
**Response:** |
| 212 |
|
| 213 |
```json |
| 214 |
{ |
| 215 |
"success": true, |
| 216 |
"data": { |
| 217 |
"show_analytics": true, |
| 218 |
"show_quick_actions": true |
| 219 |
} |
| 220 |
} |
| 221 |
``` |
| 222 |
|
| 223 |
--- |
| 224 |
|
| 225 |
### 6. Get Setup Checklist |
| 226 |
|
| 227 |
Retrieve setup checklist data for the onboarding flow. |
| 228 |
|
| 229 |
``` |
| 230 |
POST /wp-json/cartflows/v1/admin/setup-checklist/ |
| 231 |
``` |
| 232 |
|
| 233 |
**Permission:** `cartflows_manage_flows_steps` |
| 234 |
|
| 235 |
**Response:** |
| 236 |
|
| 237 |
```json |
| 238 |
{ |
| 239 |
"success": true, |
| 240 |
"data": { |
| 241 |
"published_flows_count": 0, |
| 242 |
"first_checkout_step_id": null, |
| 243 |
"first_checkout_step_flow_id": null |
| 244 |
} |
| 245 |
} |
| 246 |
``` |
| 247 |
|
| 248 |
--- |
| 249 |
|
| 250 |
## Error Responses |
| 251 |
|
| 252 |
All endpoints return errors in this format: |
| 253 |
|
| 254 |
```json |
| 255 |
{ |
| 256 |
"code": "rest_forbidden", |
| 257 |
"message": "Sorry, you are not allowed to do that.", |
| 258 |
"data": { "status": 403 } |
| 259 |
} |
| 260 |
``` |
| 261 |
|
| 262 |
| HTTP Status | Meaning | |
| 263 |
|-------------|---------| |
| 264 |
| `200` | Success | |
| 265 |
| `400` | Bad request (invalid parameters) | |
| 266 |
| `401` | Unauthenticated (missing/invalid nonce) | |
| 267 |
| `403` | Forbidden (insufficient capability) | |
| 268 |
| `404` | Not found | |
| 269 |
| `500` | Server error | |
| 270 |
|
| 271 |
--- |
| 272 |
|
| 273 |
## Extending the API |
| 274 |
|
| 275 |
CartFlows provides filters to extend API responses: |
| 276 |
|
| 277 |
```php |
| 278 |
// Add data to the flows list response |
| 279 |
add_filter( 'cartflows_admin_flows_step_data', function( $steps ) { |
| 280 |
// Modify step data here |
| 281 |
return $steps; |
| 282 |
} ); |
| 283 |
|
| 284 |
// Add fields to global settings |
| 285 |
add_filter( 'cartflows_admin_global_data_options', function( $options ) { |
| 286 |
$options['my_custom_setting'] = get_option( 'my_plugin_setting' ); |
| 287 |
return $options; |
| 288 |
} ); |
| 289 |
``` |
| 290 |
|
| 291 |
--- |
| 292 |
|
| 293 |
## Related Pages |
| 294 |
|
| 295 |
- [](AJAX-API-ReferenceAJAX-API-Reference](AJAX-API-Reference](AJAX-API-Reference) |
| 296 |
- [](WordPress-Hooks-ReferenceWordPress-Hooks-Reference](WordPress-Hooks-Reference](WordPress-Hooks-Reference) |
| 297 |
- [](Architecture-OverviewArchitecture-Overview](Architecture-Overview](Architecture-Overview) |
| 298 |
- [](WordPress-Plugin-StructureWordPress-Plugin-Structure](WordPress-Plugin-Structure](WordPress-Plugin-Structure) |
| 299 |
|