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!

::alert{type="danger"} ⚠️ 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:

::code-group

bash
curl -H "Authorization: Bearer looha_your_api_key" \
  "https://api.looha.app/v1/profit/overview?period=30d"
javascript
const API_KEY = 'looha_your_api_key'
const response = await fetch(
  'https://api.looha.app/v1/profit/overview?period=30d',
  {
    headers: { 'Authorization': `Bearer ${API_KEY}` }
  }
)
const data = await response.json()
console.log('Profit:', data.data.totalProfit)
python
import requests

API_KEY = 'looha_your_api_key'
response = requests.get(
    'https://api.looha.app/v1/profit/overview',
    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

::code-group

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/overview?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.totalProfit,
    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

::code-group

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/overview?period=today', {
    headers: { 'Authorization': `Bearer ${API_KEY}` }
  })

  const data = await response.json()
  const profit = data.data.totalProfit

  // 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

::code-group

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/overview?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

::alert{type="danger"} 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 ::

::alert{type="danger"} 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 ::

::alert{type="danger"} 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:

::card-group ::card{icon="i-heroicons-currency-dollar" title="Profit Analytics" to="/profit"} Learn how to extract detailed profit data and trends ::

::card{icon="i-heroicons-chart-bar" title="Ad Performance" to="/analytics"} Get real ROAS and campaign performance analysis ::

::card{icon="i-heroicons-light-bulb" title="Recommendations" to="/recommendations"} Get AI recommendations to improve your profits ::

::card{icon="i-heroicons-bell" title="Alerts" to="/alerts"} Manage custom alerts and rules :: ::


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

::button{to="/profit" icon="i-heroicons-arrow-right" size="lg"} Next: Profit Analytics ::

Profit analytics platform for Saudi e-commerce merchants