Profit Analytics
Get comprehensive profit data including revenue, costs, margins, and trends for your e-commerce business.
GET /v1/profit/dashboard
Get main profit dashboard data with summary metrics.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
period | string | No | Preset period: today, yesterday, 7d, 30d, 90d, custom (default: 30d) |
start_date | string | No | Custom start date (YYYY-MM-DD format) |
end_date | string | No | Custom end date (YYYY-MM-DD format) |
Note: Use period for preset ranges, OR use start_date/end_date with period=custom for custom ranges.
Example Request
bash
curl -H "Authorization: Bearer looha_your_api_key" \
"https://api.looha.app/v1/profit/dashboard?period=30d"Response
json
{
"success": true,
"data": {
"summary": {
"revenue": 125000,
"productCosts": 62500,
"adSpend": 15000,
"platformFees": 3125,
"paymentFees": 3750,
"netProfit": 40625,
"profitMargin": 32.5,
"roas": 8.33,
"orderCount": 450,
"avgOrderValue": 277.78
},
"ads": {
"spend": 15000,
"impressions": 450000,
"clicks": 15000,
"conversions": 250,
"cpc": 1.0,
"cpa": 60.0
},
"comparison": {
"revenueChange": 13.64,
"periodDays": 30
},
"confidence": {
"level": "high",
"missingData": []
},
"period": {
"start": "2024-01-01",
"end": "2024-01-31"
}
}
}Response Fields
| Field | Type | Description |
|---|---|---|
summary.revenue | number | Total revenue in SAR |
summary.productCosts | number | Total product costs |
summary.adSpend | number | Total advertising spend |
summary.platformFees | number | Platform fees (Salla/Zid) |
summary.paymentFees | number | Payment processing fees |
summary.netProfit | number | Net profit (revenue - all costs) |
summary.profitMargin | number | Profit margin percentage |
summary.roas | number | Return on ad spend |
summary.orderCount | number | Number of orders |
summary.avgOrderValue | number | Average order value |
confidence.level | string | Data confidence: high, medium, low |
confidence.missingData | array | List of missing data points |
GET /v1/profit/products
Get profit breakdown by product.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
period | string | No | today, yesterday, 7d, 30d, 90d, custom (default: 30d) |
start_date | string | No | Custom start date (YYYY-MM-DD) |
end_date | string | No | Custom end date (YYYY-MM-DD) |
limit | number | No | Number of products (1-100, default: 20) |
sort | string | No | Sort by: profit, revenue, units, margin (default: profit) |
Example Request
bash
curl -H "Authorization: Bearer looha_your_api_key" \
"https://api.looha.app/v1/profit/products?period=30d&sort=profit&limit=10"Response
json
{
"success": true,
"data": {
"products": [
{
"id": "prod_123",
"name": "Premium Laptop Bag",
"sku": "LB-001",
"image_url": "https://cdn.looha.app/products/lb-001.jpg",
"price": 300,
"units_sold": 50,
"revenue": 15000,
"unit_cost": 180,
"total_cost": 9000,
"net_profit": 6000,
"profit_margin": 40.0,
"has_cost": 1
}
]
}
}GET /v1/profit/products/:id
Get detailed profit for a specific product.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
period | string | No | today, yesterday, 7d, 30d, 90d, custom (default: 30d) |
start_date | string | No | Custom start date (YYYY-MM-DD) |
end_date | string | No | Custom end date (YYYY-MM-DD) |
Example Request
bash
curl -H "Authorization: Bearer looha_your_api_key" \
"https://api.looha.app/v1/profit/products/prod_123?period=30d"Response
json
{
"success": true,
"data": {
"product": {
"id": "prod_123",
"name": "Premium Laptop Bag",
"sku": "LB-001",
"price": 300,
"cost": 180,
"shippingCost": 15,
"packagingCost": 5,
"otherCosts": 0
},
"summary": {
"totalUnits": 50,
"totalRevenue": 15000,
"totalCost": 9000,
"netProfit": 6000,
"profitMargin": 40.0,
"avgDailyUnits": 1.67
},
"dailyData": [
{
"date": "2024-01-25",
"units": 2,
"revenue": 600,
"profit": 240
}
],
"confidence": {
"level": "high",
"missingData": []
}
}
}GET /v1/profit/ads
Get profit breakdown by ad campaign.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
period | string | No | today, yesterday, 7d, 30d, 90d, custom (default: 30d) |
start_date | string | No | Custom start date (YYYY-MM-DD) |
end_date | string | No | Custom end date (YYYY-MM-DD) |
platform | string | No | Filter: all, meta, google, tiktok, snapchat (default: all) |
Example Request
bash
curl -H "Authorization: Bearer looha_your_api_key" \
"https://api.looha.app/v1/profit/ads?period=30d&platform=meta"Response
json
{
"success": true,
"data": {
"campaigns": [
{
"id": "camp_123",
"external_id": "23851234567890",
"name": "Winter Sale 2024",
"platform": "meta",
"status": "active",
"objective": "CONVERSIONS",
"daily_budget": 500,
"start_date": "2024-01-01",
"end_date": null,
"synced_at": "2024-01-25T10:30:00Z",
"total_spend": 8000,
"impressions": 250000,
"clicks": 8500,
"conversions": 150,
"revenue": 50000,
"roas": 6.25,
"cpc": 0.94,
"cpa": 53.33,
"ad_sets_count": 3,
"ads_count": 8
}
],
"totals": {
"spend": 15000,
"revenue": 125000,
"impressions": 450000,
"clicks": 15000,
"conversions": 450,
"roas": 8.33,
"cpc": 1.0,
"cpa": 33.33
}
},
"generatedAt": "2024-01-25T12:00:00Z"
}Note: This endpoint is cached for 10 minutes.
GET /v1/profit/ads/:id
Get detailed campaign data with ad sets and ads.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
period | string | No | today, yesterday, 7d, 30d, 90d, custom (default: 30d) |
start_date | string | No | Custom start date (YYYY-MM-DD) |
end_date | string | No | Custom end date (YYYY-MM-DD) |
Example Request
bash
curl -H "Authorization: Bearer looha_your_api_key" \
"https://api.looha.app/v1/profit/ads/camp_123?period=30d"Response
json
{
"success": true,
"data": {
"campaign": {
"id": "camp_123",
"external_id": "23851234567890",
"name": "Winter Sale 2024",
"platform": "meta",
"status": "active",
"objective": "CONVERSIONS",
"daily_budget": 500,
"lifetime_budget": null,
"start_date": "2024-01-01",
"end_date": null,
"synced_at": "2024-01-25T10:30:00Z",
"created_at": "2024-01-01T08:00:00Z",
"total_spend": 8000,
"impressions": 250000,
"clicks": 8500,
"conversions": 150,
"revenue": 50000,
"roas": 6.25,
"cpc": 0.94,
"cpa": 53.33,
"ctr": 3.4
},
"adSets": [],
"ads": [],
"dailyMetrics": [
{
"date": "2024-01-25",
"spend": 500,
"impressions": 15000,
"clicks": 500,
"conversions": 8,
"revenue": 3000
}
]
}
}GET /v1/profit/timeline
Get profit over time for charts.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
period | string | No | today, yesterday, 7d, 30d, 90d, custom (default: 30d) |
start_date | string | No | Custom start date (YYYY-MM-DD) |
end_date | string | No | Custom end date (YYYY-MM-DD) |
granularity | string | No | hour, day, week, month (default: day) |
Example Request
bash
curl -H "Authorization: Bearer looha_your_api_key" \
"https://api.looha.app/v1/profit/timeline?period=7d&granularity=day"Response
json
{
"success": true,
"data": {
"timeline": [
{
"period": "2024-01-25",
"revenue": 4200,
"orders": 15,
"adSpend": 500,
"profit": 3700
},
{
"period": "2024-01-24",
"revenue": 3800,
"orders": 13,
"adSpend": 450,
"profit": 3350
}
],
"granularity": "day"
}
}POST /v1/profit/calculate
Force recalculation of profit metrics (queued job).
Example Request
bash
curl -X POST \
-H "Authorization: Bearer looha_your_api_key" \
"https://api.looha.app/v1/profit/calculate"Response
json
{
"success": true,
"data": {
"message": "تم بدء إعادة حساب الأرباح"
}
}Note: This endpoint queues a background job. Recalculation may take a few minutes.
Alias: POST /v1/profit/recalculate works the same way.
Error Responses
400 Bad Request
json
{
"success": false,
"error": "تاريخ البداية يجب أن يكون بتنسيق YYYY-MM-DD"
}401 Unauthorized
json
{
"success": false,
"error": "Unauthorized"
}404 Not Found
json
{
"success": false,
"error": "Product not found"
}Use Cases
Daily Profit Tracking in Google Sheets
javascript
function fetchDailyProfit() {
const API_KEY = PropertiesService.getScriptProperties().getProperty('LOOHA_API_KEY')
const response = UrlFetchApp.fetch('https://api.looha.app/v1/profit/dashboard?period=today', {
headers: { Authorization: `Bearer ${API_KEY}` },
})
const data = JSON.parse(response.getContentText())
const sheet = SpreadsheetApp.getActiveSheet()
sheet.appendRow([
new Date(),
data.data.summary.revenue,
data.data.summary.netProfit,
data.data.summary.profitMargin,
])
}Track Top Profitable Products
python
import requests
API_KEY = 'looha_your_api_key'
response = requests.get(
'https://api.looha.app/v1/profit/products',
params={'period': '30d', 'sort': 'profit', 'limit': 5},
headers={'Authorization': f'Bearer {API_KEY}'}
)
products = response.json()['data']['products']
for product in products:
print(f"{product['name']}: {product['net_profit']} SAR profit")Monitor Campaign Performance
javascript
const API_KEY = 'looha_your_api_key'
const response = await fetch('https://api.looha.app/v1/profit/ads?period=7d&platform=meta', {
headers: { Authorization: `Bearer ${API_KEY}` },
})
const data = await response.json()
const campaigns = data.data.campaigns
// Find campaigns with ROAS < 3
const underperforming = campaigns.filter(c => c.roas < 3)
console.log(`${underperforming.length} campaigns need attention`)Next: Analytics API →