> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oneclickdz.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Health Check

> Check API service health and operator availability

## Overview

The health check endpoint allows you to verify the API service status and check the availability of each mobile operator.

## Response

<ResponseField name="success" type="boolean" required>
  Always `true` if the API is operational
</ResponseField>

<ResponseField name="data" type="object" required>
  <Expandable title="properties">
    <ResponseField name="api" type="string">
      Service status: `"ok"` or `"error"`
    </ResponseField>

    <ResponseField name="operators" type="object">
      Status of each operator

      <Expandable title="properties">
        <ResponseField name="mobilis" type="string">
          Mobilis operator status: `"up"` or `"down"`
        </ResponseField>

        <ResponseField name="ooredoo" type="string">
          Ooredoo operator status: `"up"` or `"down"`
        </ResponseField>

        <ResponseField name="djezzy" type="string">
          Djezzy operator status: `"up"` or `"down"`
        </ResponseField>

        <ResponseField name="mobilisFixedPlans" type="string">
          Mobilis Fixed Plans (Sama | Pixx) status: `"up"` or `"down"`
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="meta" type="object">
  <Expandable title="properties">
    <ResponseField name="timestamp" type="string">
      Current server timestamp (ISO 8601 format)
    </ResponseField>
  </Expandable>
</ResponseField>

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl --request GET \
    --url https://api.oneclickdz.com/v3/ping
  ```

  ```bash cURL (with authentication) theme={null}
  curl --request GET \
    --url https://api.oneclickdz.com/v3/ping \
    --header 'X-Access-Token: your_api_key_here'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch("https://api.oneclickdz.com/v3/ping");
  const data = await response.json();

  console.log("API Status:", data.data.api);
  console.log("Operators:", data.data.operators);
  ```

  ```javascript Node.js (with authentication) theme={null}
  const response = await fetch("https://api.oneclickdz.com/v3/ping", {
    headers: {
      'X-Access-Token': 'your_api_key_here'
    }
  });
  const data = await response.json();

  console.log("API Status:", data.data.api);
  console.log("Operators:", data.data.operators);
  ```

  ```python Python theme={null}
  import requests

  response = requests.get('https://api.oneclickdz.com/v3/ping')
  data = response.json()

  print
  {
    "success": true,
    "data": {
      "api": "ok",
      "operators": {
        "mobilis": "up",
        "ooredoo": "up",
        "djezzy": "up",
        "mobilisFixedPlans": "up"
      }
    },
    "meta": {
      "timestamp": "2025-10-29T00:35:58.557Z"
    }
  }
  ```
</CodeGroup>

## Use Cases

<CardGroup cols={2}>
  <Card title="Service Monitoring" icon="chart-line">
    Monitor API availability and operator status for uptime tracking
  </Card>

  <Card title="Pre-flight Checks" icon="plane-departure">
    Verify service is operational before processing transactions
  </Card>

  <Card title="Operator Filtering" icon="filter">
    Hide unavailable operators from your UI
  </Card>

  <Card title="Health Dashboard" icon="heart-pulse">
    Build a status dashboard for your operations team
  </Card>
</CardGroup>

## Integration Example

```javascript theme={null}
// Check service health before processing orders
async function canProcessOrders() {
  try {
    const response = await fetch("https://api.oneclickdz.com/v3/ping");
    const data = await response.json();

    if (data.data.api !== "ok") {
      console.error("API service is down");
      return false;
    }

    return true;
  } catch (error) {
    console.error("Health check failed:", error);
    return false;
  }
}

// Check specific operator availability
async function isOperatorAvailable(operator) {
  const response = await fetch("https://api.oneclickdz.com/v3/ping");
  const data = await response.json();

  const operatorMap = {
    Mobilis: "mobilis",
    Ooredoo: "ooredoo",
    Djezzy: "djezzy",
    Pixx: "mobilisFixedPlans",
  };

  const operatorKey = operatorMap[operator];
  return data.data.operators[operatorKey] === "up";
}
```

## Best Practices

<AccordionGroup>
  <Accordion title="Poll Periodically" icon="clock">
    Check the health endpoint every 30-60 seconds to maintain an up-to-date view of service status.

    ```javascript theme={null}
    setInterval(async () => {
      const response = await fetch('https://api.oneclickdz.com/v3/ping');
      const data = await response.json();
      updateServiceStatus(data.data);
    }, 30000); // Check every 30 seconds
    ```
  </Accordion>

  <Accordion title="Cache Status" icon="database">
    Cache the status for 30-60 seconds to avoid excessive requests

    ```javascript theme={null}
    let cachedStatus = null;
    let lastCheck = 0;

    async function getServiceStatus() {
      const now = Date.now();
      
      if (cachedStatus && (now - lastCheck) < 30000) {
        return cachedStatus;
      }
      
      const response = await fetch('https://api.oneclickdz.com/v3/ping');
      cachedStatus = await response.json();
      lastCheck = now;
      
      return cachedStatus;
    }
    ```
  </Accordion>

  <Accordion title="Handle Degraded State" icon="triangle-exclamation">
    When an operator is down, inform users and suggest alternatives

    ```javascript theme={null}
    if (data.data.operators.djezzy === 'down') {
      showNotification('Djezzy service temporarily unavailable. Try Mobilis or Ooredoo.');
    }
    ```
  </Accordion>
</AccordionGroup>
