### Collection Agent API - REST Client File ### @baseUrl = http://localhost:3001 @authToken = your_auth_token_here @adminAuthToken = your_admin_auth_token_here ### @mobile_no = 9876543210 @otp = 123456 @device_id = test-device-123 @loan_id = TEST-LOAN-001 @company_id = 1 ### # AUTHENTICATION ENDPOINTS # Note: Query parameters must be included in the URL ### POST http://localhost:3001/?generate_otp=true Content-Type: application/json { "mobile_no": "8825948300" } HTTP/1.1 200 - OK x-powered-by: Express access-control-allow-origin: * access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, Authorization content-type: application/json; charset=utf-8 content-length: 111 etag: W/"6f-odeXOZUAQFAMz5QeZliRHcElBbg" date: Thu, 04 Dec 2025 10:26:19 GMT connection: close ### POST {{baseUrl}}/?verify_otp=true Content-Type: application/json { "mobile_no": "{{mobile_no}}", "otp": "865049", "device_id": "{{device_id}}", "device_type": "android", "device_token": "test-device-token-123" } HTTP/1.1 400 - Bad Request x-powered-by: Express access-control-allow-origin: * access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, Authorization content-type: application/json; charset=utf-8 content-length: 42 etag: W/"2a-Wy0lqJjIW2EgXciTLQpCMxzpvLk" date: Thu, 04 Dec 2025 10:26:21 GMT connection: close ### GET {{baseUrl}}/check_auth Authorization: Bearer {{authToken}} ### POST {{baseUrl}}/logout Authorization: Bearer {{authToken}} ### # COLLECTION AGENT ENDPOINTS ### GET {{baseUrl}}/collection_agent Authorization: Bearer {{authToken}} ### GET {{baseUrl}}/fetch_agent_data Authorization: Bearer {{authToken}} HTTP/1.1 401 - Unauthorized x-powered-by: Express access-control-allow-origin: * access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, Authorization content-type: application/json; charset=utf-8 content-length: 55 etag: W/"37-mjz5+OMyYuAXsPp/BcnVlshvRS4" date: Thu, 04 Dec 2025 08:27:22 GMT connection: close ### GET {{baseUrl}}/get_agents_format Authorization: Bearer {{authToken}} ### GET {{baseUrl}}/get_agents_by_time?start_time=2025-12-04T09:00:00&end_time=2025-12-04T17:00:00 Authorization: Bearer {{authToken}} ### GET {{baseUrl}}/get_areas_by_line?line=Line-1 Authorization: Bearer {{authToken}} ### # COLLECTION DETAILS ENDPOINTS ### GET {{baseUrl}}/collection_details Authorization: Bearer {{authToken}} ### GET {{baseUrl}}/collection_details?area=Area-A Authorization: Bearer {{authToken}} ### GET {{baseUrl}}/loan_details?loan_id={{loan_id}} Authorization: Bearer {{authToken}} ### # RECEIPT ENDPOINTS ### POST {{baseUrl}}/insert_receipt Authorization: Bearer {{authToken}} Content-Type: application/json { "loan_id": "{{loan_id}}", "rec_no": "REC20251204001", "cust_name": "Test Customer", "num_dues": 1, "principal_amount": 333.33, "interest_amount": 8.33, "receipt_date": "2025-12-04", "remark": "Payment received", "next_due_date": "2025-12-11" } ### GET {{baseUrl}}/today_collection_history Authorization: Bearer {{authToken}} ### # EXPENSE ENDPOINTS ### POST {{baseUrl}}/insert_expense Authorization: Bearer {{authToken}} Content-Type: application/json { "expense_date": "2025-12-04", "amount": 50.00, "reason": "Transportation cost for collection" } ### GET {{baseUrl}}/today_expense_list Authorization: Bearer {{authToken}} ### # STATISTICS ENDPOINTS ### GET {{baseUrl}}/collection_statistics Authorization: Bearer {{authToken}} ### # ADMIN ENDPOINTS (Optional) ### POST {{baseUrl}}/admin/login Content-Type: application/json { "username": "admin", "password": "password123", "company_id": {{company_id}} } ### GET {{baseUrl}}/admin/check_auth Authorization: Bearer {{authToken}} ### POST {{baseUrl}}/logout?admin=true Authorization: Bearer {{authToken}} ### # SETTINGS ENDPOINTS ### GET {{baseUrl}}/settings/multiple-devices ### POST {{baseUrl}}/settings/multiple-devices Content-Type: application/json { "allow_multiple_devices": true } ### PUT {{baseUrl}}/settings/multiple-devices Content-Type: application/json { "allow_multiple_devices": false } ### # EXAMPLE REQUESTS WITH FULL DATA ### # Step 1: Generate OTP POST {{baseUrl}}/?generate_otp=true Content-Type: application/json { "mobile_no": "8825948300" } HTTP/1.1 200 - OK x-powered-by: Express access-control-allow-origin: * access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, Authorization content-type: application/json; charset=utf-8 content-length: 111 etag: W/"6f-7kNSLaLe1RHp/TI0C/PeMYTKSaQ" date: Thu, 04 Dec 2025 10:56:06 GMT connection: close ### # Step 2: Verify OTP (use OTP from Step 1 response) POST {{baseUrl}}/?verify_otp=true Content-Type: application/json { "mobile_no": "8825948300", "otp": "{{otp}}", "device_id": "device-123", "device_type": "android", "device_token": "token-123" } HTTP/1.1 400 - Bad Request x-powered-by: Express access-control-allow-origin: * access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, Authorization content-type: application/json; charset=utf-8 content-length: 42 etag: W/"2a-Wy0lqJjIW2EgXciTLQpCMxzpvLk" date: Thu, 04 Dec 2025 10:56:13 GMT connection: close ### # Step 3: Get Collection Details GET {{baseUrl}}/collection_details Authorization: Bearer 6f794896537dcc0f6201b03d5f696a7b52cabb838ef19ac8848653e35856107f HTTP/1.1 200 - OK x-powered-by: Express access-control-allow-origin: * access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, Authorization content-type: application/json; charset=utf-8 content-length: 490 etag: W/"1ea-ASc7vqb3Yex4qZLvsxqfzrHsWCc" date: Thu, 04 Dec 2025 11:29:48 GMT connection: close ### # Step 4: Get Loan Details GET {{baseUrl}}/loan_details?loan_id=TEST-LOAN-001 Authorization: Bearer your_token_from_step_2 HTTP/1.1 401 - Unauthorized x-powered-by: Express access-control-allow-origin: * access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, Authorization content-type: application/json; charset=utf-8 content-length: 55 etag: W/"37-mjz5+OMyYuAXsPp/BcnVlshvRS4" date: Thu, 04 Dec 2025 10:27:27 GMT connection: close ### # Step 5: Insert Receipt POST {{baseUrl}}/insert_receipt Authorization: Bearer your_token_from_step_2 Content-Type: application/json { "loan_id": "TEST-LOAN-001", "rec_no": "REC20251204001", "cust_name": "Test Customer", "num_dues": 1, "principal_amount": 333.33, "interest_amount": 8.33, "receipt_date": "2025-12-04", "remark": "Payment received in cash", "next_due_date": "2025-12-11" } ### # Step 6: Insert Expense POST {{baseUrl}}/insert_expense Authorization: Bearer your_token_from_step_2 Content-Type: application/json { "expense_date": "2025-12-04", "amount": 50.00, "reason": "Transportation cost for collection" } ### # Step 7: Get Today's Collection History GET {{baseUrl}}/today_collection_history Authorization: Bearer your_token_from_step_2 ### # Step 8: Get Today's Expense List GET {{baseUrl}}/today_expense_list Authorization: Bearer your_token_from_step_2 ### # Step 9: Get Collection Statistics GET {{baseUrl}}/collection_statistics Authorization: Bearer your_token_from_step_2 ### # ERROR HANDLING EXAMPLES ### GET {{baseUrl}}/loan_details?loan_id=INVALID_LOAN_ID_99999 Authorization: Bearer {{authToken}} ### POST {{baseUrl}}/insert_receipt Authorization: Bearer {{authToken}} Content-Type: application/json { "loan_id": "TEST123" } ### GET {{baseUrl}}/collection_details ### # ADMIN DIRECT RECEIPT INSERTION ENDPOINTS ### # Direct receipt insertion - accepts all fields including company_id (using Sequelize model) POST {{baseUrl}}/admin/insert_receipt_direct Authorization: Bearer {{authToken}} Content-Type: application/json { "loan_id": "DL2025001", "com_id": 8, "rec_no": "001", "rec_date": "2025-12-04", "cust_id": 534687676476, "cust_name": "Pavithra", "cust_mobile": "5346876764", "num_dues": 60, "due_amnt": 92.00, "paid_amnt": 2208.00, "paid_dues": 24, "balance_dues": 60, "pending_dues": 24, "next_date": "2025-12-05", "remark": "hvhjfgh", "agent": "Raja" } ### # Direct receipt insertion using raw SQL POST {{baseUrl}}/admin/insert_receipt_sql Authorization: Bearer {{authToken}} Content-Type: application/json { "loan_id": "DL2025001", "com_id": 8, "rec_no": "001", "rec_date": "2025-12-04", "cust_id": 534687676476, "cust_name": "Pavithra", "cust_mobile": "5346876764", "num_dues": 60, "due_amnt": 92.00, "paid_amnt": 2208.00, "paid_dues": 24, "balance_dues": 60, "pending_dues": 24, "next_date": "2025-12-05", "remark": "hvhjfgh", "agent": "Raja" } ### # Get all companies for authenticated admin (multi-company support) GET {{baseUrl}}/admin/companies?username=super_admin Content-Type: application/json ### # Get registrations under companies for admin (all companies) GET {{baseUrl}}/admin/registrations?username=super_admin Content-Type: application/json ### # Get registrations for a specific company GET {{baseUrl}}/admin/registrations?username=super_admin&company_id=17 Content-Type: application/json ### # NOTES ### # 1. Replace {{authToken}} with actual token from verify_otp response # 2. Replace {{mobile_no}} with actual collection agent mobile number # 3. Replace {{loan_id}} with actual loan ID from your database # 4. All authenticated endpoints require: Authorization: Bearer # 5. Token can also be passed as query parameter: ?auth_token= # 6. Date format: YYYY-MM-DD (e.g., 2025-12-04) # 7. Amounts should be numbers (not strings) # 8. OTP expires in 5 minutes # 9. Server timezone: Asia/Kolkata (+05:30) # 10. Admin endpoints require admin authentication token # 11. Direct receipt insertion endpoints allow specifying company_id directly