Skip to content

Quick Start

1️⃣ Check Requirements

Before starting, make sure:

  • You're subscribed to Pro plan (API is Pro-only)
  • You have an active account on the dashboard

If you're on the free plan, upgrade to Pro first.


2️⃣ Get Your API Key

Follow these steps:

  1. Go to Settings → API
  2. Click "Create New Key"
  3. Enter a descriptive name (e.g., "Excel Integration" or "Mobile App")
  4. Choose expiration date (optional)
    • No date = permanent validity
    • With date = limited validity (better for security)
  5. Click "Create Key"
  6. Copy the key immediately - you won't see it again!

⚠️ Security Warning

Store the key in a safe place (like a password manager). If you lose it, delete it and create a new one.


3️⃣ First API Request

Try getting profit overview:

cURL:

bash
curl -H "Authorization: Bearer looha_your_api_key" \
  "https://api.looha.app/v1/profit/dashboard?period=30d"

JavaScript / Node.js:

javascript
const API_KEY = 'looha_your_api_key'
const response = await fetch('https://api.looha.app/v1/profit/dashboard?period=30d', {
  headers: { Authorization: `Bearer ${API_KEY}` },
})
const data = await response.json()
console.log('Profit:', data.data.summary.netProfit)

Python:

python
import requests

API_KEY = 'looha_your_api_key'
response = requests.get(
    'https://api.looha.app/v1/profit/dashboard',
    params={'period': '30d'},
    headers={'Authorization': f'Bearer {API_KEY}'}
)
data = response.json()
print('Profit:', data['data']['totalProfit'])

Expected Response:

json
{
  "success": true,
  "data": {
    "totalRevenue": 50000,
    "totalCost": 35000,
    "totalProfit": 15000,
    "profitMargin": 30,
    "adSpend": 8000,
    "roas": 6.25,
    "period": {
      "start": "2024-01-01",
      "end": "2024-01-31"
    }
  }
}

4️⃣ Practical Use Cases

Auto-update Google Sheets

javascript
function updateLoohaData() {
  const API_KEY = PropertiesService.getUserProperties().getProperty('LOOHA_API_KEY')
  const sheet = SpreadsheetApp.getActiveSheet()

  // Fetch last 30 days profit
  const response = UrlFetchApp.fetch('https://api.looha.app/v1/profit/dashboard?period=30d', {
    headers: { Authorization: `Bearer ${API_KEY}` },
  })

  const data = JSON.parse(response.getContentText())
  const now = new Date()

  // Fill the spreadsheet
  sheet.appendRow([
    now,
    data.data.totalRevenue,
    data.data.totalCost,
    data.data.summary.netProfit,
    data.data.profitMargin + '%',
    data.data.roas,
  ])
}

// Schedule (auto-run every morning at 8am)
function createDailyTrigger() {
  ScriptApp.newTrigger('updateLoohaData').timeBased().everyDays(1).atHour(8).create()
}

Send Slack Alert When Profit Drops

javascript
const API_KEY = process.env.LOOHA_API_KEY
const SLACK_WEBHOOK = process.env.SLACK_WEBHOOK_URL

async function checkProfitAndAlert() {
  const response = await fetch('https://api.looha.app/v1/profit/dashboard?period=today', {
    headers: { Authorization: `Bearer ${API_KEY}` },
  })

  const data = await response.json()
  const profit = data.data.summary.netProfit

  // If profit is less than 1000 SAR
  if (profit < 1000) {
    await fetch(SLACK_WEBHOOK, {
      method: 'POST',
      body: JSON.stringify({
        text: `⚠️ Alert: Today's profit is only ${profit} SAR!`,
        color: 'danger',
      }),
    })
  }
}

checkProfitAndAlert()

Read Data in React App

javascript
import { useEffect, useState } from 'react'

function ProfitOverview() {
  const [profit, setProfit] = useState(null)
  const [loading, setLoading] = useState(true)

  useEffect(() => {
    const API_KEY = localStorage.getItem('looha_api_key')

    fetch('https://api.looha.app/v1/profit/dashboard?period=30d', {
      headers: { Authorization: `Bearer ${API_KEY}` },
    })
      .then(r => r.json())
      .then(data => {
        setProfit(data.data)
        setLoading(false)
      })
  }, [])

  if (loading) return <div>Loading...</div>

  return (
    <div>
      <h2>Net Profit: {profit.totalProfit} SAR</h2>
      <p>Profit Margin: {profit.profitMargin}%</p>
      <p>ROAS: {profit.roas}x</p>
    </div>
  )
}

export default ProfitOverview

5️⃣ Error Handling

Common Errors and Solutions

401 Unauthorized

Invalid or expired API key

Solution:

  • Make sure you copied the key correctly
  • Check the key expiration date from /settings/api
  • Create a new key if needed

429 Rate Limit Exceeded

You exceeded the request limit (1,000 requests/hour for Pro)

Solution:

  • Wait before trying again
  • Reduce number of requests or use caching

400 Validation Error

Invalid data sent

Solution:


6️⃣ Best Practices

✅ DO:

  • Store keys in environment variables (.env)
  • Use a separate key for each app
  • Set expiration dates for temporary keys
  • Delete old keys from Settings
  • Use caching to reduce number of requests

❌ DON'T:

  • Put keys in source code (Git)
  • Share keys via email or Slack
  • Use the same key for all applications
  • Send keys in URL (accidentally)

7️⃣ Next Steps

Choose what interests you:

💰 Profit Analytics

Learn how to extract detailed profit data and trends

Learn more →

📊 Ad Performance

Get real ROAS and campaign performance analysis

Learn more →

🤖 AI Recommendations

Get AI recommendations to improve your profits

Learn more →

🔔 Alerts

Manage custom alerts and rules

Learn more →


Common Issues?

If you encounter a problem:

  1. Read the full documentation for the specific endpoint
  2. Check the error (error message explains the reason)
  3. Contact support: support@looha.app

➡️ Next: Profit Analytics

Profit analytics platform for Saudi e-commerce merchants