Collection Agent API Test

1. Standalone API Endpoint (collection_agent_fetch.php)

URL: collection_agent_fetch.php?line=main line

Method: GET

Headers: Authorization: Bearer [JWT_TOKEN]

Description: Fetches collection agents, line entries, and loan entries for a specific line with today's due date.

2. Integrated Routes API (collection_agent_auth.php)

URL: collection_agent_auth.php?fetch_agent_data=1&line=main line

Method: GET

Headers: Authorization: Bearer [JWT_TOKEN]

Description: Same functionality but integrated into the existing routes system.

3. Example Response Structure

{
    "status": "success",
    "data": {
        "agents": [
            {
                "id": "1",
                "name": "baby",
                "mobile_no": "7675675652",
                "address": "komarapalayam",
                "aadhar_no": "4850394580594",
                "report_in": "2025-09-25 15:15:55",
                "reporting_time": "2025-09-25 15:15:55",
                "status": "active",
                "line": "main area"
            }
        ],
        "line_entries": [
            {
                "id": "1",
                "com_id": "9",
                "area": "erode",
                "line": "main line",
                "created_on": "0000-00-00 00:00:00"
            },
            {
                "id": "2",
                "com_id": "9",
                "area": "salem",
                "line": "main line",
                "created_on": "0000-00-00 00:00:00"
            }
        ],
        "loan_entries": [
            {
                "id": "5",
                "loan_id": "DL2025002",
                "com_id": "9",
                "cus_name": "Raja",
                "cust_mobile": "1234567890",
                "area": "salem",
                "loan_type": "Daily",
                "loan_amt": "10000",
                "next_due_date": "2025-09-23",
                "per_due_amt": "167"
            }
        ],
        "query_info": {
            "company_id": "9",
            "line": "main line",
            "today": "2025-09-23",
            "areas_found": [
                "erode",
                "salem"
            ],
            "total_agents": 1,
            "total_line_entries": 2,
            "total_loan_entries": 1
        }
    }
}

4. How to Use

  1. Get a valid JWT token by logging in through the authentication system
  2. Make a GET request to either endpoint with the 'line' parameter
  3. The API will return:

5. Example cURL Commands

Standalone API:

curl -X GET 'http://your-domain.com/collection_agent_fetch.php?line=main%20line' \
  -H 'Authorization: Bearer YOUR_JWT_TOKEN' \
  -H 'Content-Type: application/json'

Integrated Routes API:

curl -X GET 'http://your-domain.com/collection_agent_auth.php?fetch_agent_data=1&line=main%20line' \
  -H 'Authorization: Bearer YOUR_JWT_TOKEN' \
  -H 'Content-Type: application/json'

6. Database Query Logic

The API performs the following queries:

  1. Collection Agents: SELECT * FROM collection_agent WHERE com_id = ? AND line = ?
  2. Line Entries: SELECT * FROM line_entry WHERE com_id = ? AND line = ?
  3. Loan Entries: SELECT * FROM loan_entry WHERE com_id = ? AND area IN (areas) AND next_due_date = today

7. Error Handling