Rest API Overview
4 min read
Smart Cycle Discounts Pro provides a REST API for programmatic access to campaigns, analytics, and settings. This allows integration with external systems, mobile apps, and automation workflows. REST API access requires Smart Cycle Discounts Pro.
API Overview #
Base URL #
https://yoursite.com/wp-json/scd/v1/
Authentication #
The API uses WooCommerce REST API authentication:
- Consumer Key: Generate in WooCommerce → Settings → Advanced → REST API
- Consumer Secret: Provided when creating API keys
- Permissions: Read/Write access required
Authentication Methods #
| Method | Use Case |
|---|---|
| HTTP Basic Auth | Server-to-server requests (HTTPS required) |
| Query String | Simple integrations (less secure) |
| OAuth 1.0a | Third-party apps |
Example Authentication #
# HTTP Basic Auth curl -X GET "https://yoursite.com/wp-json/scd/v1/campaigns" \ -u "ck_your_consumer_key:cs_your_consumer_secret" # Query String Auth curl -X GET "https://yoursite.com/wp-json/scd/v1/campaigns?consumer_key=ck_xxx&consumer_secret=cs_xxx"
Endpoints #
Campaigns #
List Campaigns #
GET /wp-json/scd/v1/campaigns
Parameters:
| Parameter | Type | Description |
|---|---|---|
| status | string | Filter by status (active, scheduled, paused, expired, draft) |
| per_page | integer | Results per page (default: 10, max: 100) |
| page | integer | Page number |
| orderby | string | Order by field (id, name, created_at) |
| order | string | Sort order (asc, desc) |
Response:
{
"campaigns": [
{
"id": 123,
"name": "Summer Sale",
"status": "active",
"priority": 3,
"discount_type": "percentage",
"discount_value": 25,
"start_date": "2025-06-01T00:00:00",
"end_date": "2025-06-30T23:59:59",
"products_count": 45,
"created_at": "2025-05-15T10:30:00",
"updated_at": "2025-05-20T14:15:00"
},
...
],
"total": 15,
"total_pages": 2
}
Get Single Campaign #
GET /wp-json/scd/v1/campaigns/{id}
Response:
{
"id": 123,
"name": "Summer Sale",
"status": "active",
"priority": 3,
"discount_type": "percentage",
"discount_value": 25,
"product_selection": {
"type": "conditions",
"conditions": [
{
"field": "category",
"operator": "equals",
"value": "summer-collection"
}
]
},
"schedule": {
"start_date": "2025-06-01T00:00:00",
"end_date": "2025-06-30T23:59:59",
"recurring": false
},
"products": [1, 2, 3, 4, 5],
"analytics": {
"revenue": 12500.00,
"conversions": 230,
"discount_given": 4166.67
}
}
Create Campaign #
POST /wp-json/scd/v1/campaigns
Request Body:
{
"name": "New Campaign",
"priority": 3,
"discount_type": "percentage",
"discount_value": 20,
"product_selection": {
"type": "all",
"exclusions": {
"categories": [15, 22]
}
},
"schedule": {
"start_date": "2025-07-01T00:00:00",
"end_date": "2025-07-31T23:59:59"
},
"status": "scheduled"
}
Response:
{
"id": 124,
"name": "New Campaign",
"status": "scheduled",
...
}
Update Campaign #
PUT /wp-json/scd/v1/campaigns/{id}
Request Body: Same structure as create, with only fields to update.
Delete Campaign #
DELETE /wp-json/scd/v1/campaigns/{id}
Response:
{
"deleted": true,
"id": 123
}
Campaign Actions #
POST /wp-json/scd/v1/campaigns/{id}/activate
POST /wp-json/scd/v1/campaigns/{id}/pause
POST /wp-json/scd/v1/campaigns/{id}/resume
POST /wp-json/scd/v1/campaigns/{id}/duplicate
Analytics #
Get Analytics Summary #
GET /wp-json/scd/v1/analytics
Parameters:
| Parameter | Type | Description |
|---|---|---|
| start_date | string | Start date (YYYY-MM-DD) |
| end_date | string | End date (YYYY-MM-DD) |
| campaign_id | integer | Filter by campaign |
Response:
{
"summary": {
"total_revenue": 45000.00,
"total_conversions": 850,
"total_discount": 11250.00,
"avg_order_value": 52.94
},
"campaigns": [
{
"id": 123,
"name": "Summer Sale",
"revenue": 25000.00,
"conversions": 450
},
...
],
"daily_data": [
{
"date": "2025-06-01",
"revenue": 1500.00,
"conversions": 28
},
...
]
}
Get Campaign Analytics #
GET /wp-json/scd/v1/campaigns/{id}/analytics
Products #
Get Campaign Products #
GET /wp-json/scd/v1/campaigns/{id}/products
Response:
{
"products": [
{
"id": 45,
"name": "Blue Widget",
"sku": "BW-001",
"original_price": 50.00,
"discounted_price": 37.50,
"discount_amount": 12.50
},
...
],
"total": 45
}
Check Product Discount #
GET /wp-json/scd/v1/products/{id}/discount
Response:
{
"product_id": 45,
"has_discount": true,
"campaign_id": 123,
"campaign_name": "Summer Sale",
"original_price": 50.00,
"discounted_price": 37.50,
"discount_type": "percentage",
"discount_value": 25
}
Settings #
Get Settings #
GET /wp-json/scd/v1/settings
Update Settings #
PUT /wp-json/scd/v1/settings
Error Handling #
Error Response Format #
{
"code": "rest_invalid_param",
"message": "Invalid parameter: discount_value",
"data": {
"status": 400,
"params": {
"discount_value": "Must be between 1 and 100"
}
}
}
Common Error Codes #
| HTTP Code | Error Code | Description |
|---|---|---|
| 400 | rest_invalid_param | Invalid parameters |
| 401 | rest_forbidden | Authentication failed |
| 403 | rest_forbidden | Insufficient permissions |
| 404 | rest_not_found | Resource not found |
| 500 | rest_error | Server error |
Rate Limiting #
Limits #
| Endpoint Type | Limit |
|---|---|
| Read (GET) | 120 requests/minute |
| Write (POST/PUT/DELETE) | 60 requests/minute |
Rate Limit Headers #
X-RateLimit-Limit: 120 X-RateLimit-Remaining: 115 X-RateLimit-Reset: 1625097600
Webhooks #
Available Webhook Events #
| Event | Trigger |
|---|---|
| campaign.created | New campaign created |
| campaign.updated | Campaign modified |
| campaign.activated | Campaign becomes active |
| campaign.deactivated | Campaign paused/expired |
| campaign.deleted | Campaign deleted |
| discount.applied | Discount applied to order |
Webhook Payload #
{
"event": "campaign.activated",
"timestamp": "2025-06-01T00:00:00Z",
"data": {
"campaign_id": 123,
"campaign_name": "Summer Sale",
...
}
}
Code Examples #
PHP with WordPress HTTP API #
$response = wp_remote_get(
'https://yoursite.com/wp-json/scd/v1/campaigns',
array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( $consumer_key . ':' . $consumer_secret ),
),
)
);
$campaigns = json_decode( wp_remote_retrieve_body( $response ), true );
JavaScript (fetch) #
const response = await fetch('https://yoursite.com/wp-json/scd/v1/campaigns', {
headers: {
'Authorization': 'Basic ' + btoa(consumerKey + ':' + consumerSecret),
},
});
const data = await response.json();
Python #
import requests
from requests.auth import HTTPBasicAuth
response = requests.get(
'https://yoursite.com/wp-json/scd/v1/campaigns',
auth=HTTPBasicAuth(consumer_key, consumer_secret)
)
campaigns = response.json()
Updated on February 14, 2026