docker-erpnext/test_api.sh
Brian Tan Seng afe596e5ef 📚 Complete API Documentation Created
Files Generated:

  1. API_ENDPOINTS.md (1,171 lines)
    - Complete documentation of all 771 DocTypes in ERPNext
    - Organized by 37 modules
    - Sample record names for each DocType
    - Full REST endpoint patterns
    - Examples and usage instructions
  2. generate_api_docs.py
    - Python script to auto-discover and document all API endpoints
    - Fetches live data from your ERPNext instance
    - Can be re-run anytime to update documentation
  3. discover_api_endpoints.sh
    - Bash alternative for API discovery
    - Lightweight script for quick checks
  4. test_api.sh
    - Ready-to-use API testing script
    - Demonstrates authentication and common API calls

  Key Features of the Documentation:

  Complete Coverage:

  -  All 771 DocTypes documented
  -  37 modules categorized
  -  Sample data for each DocType
  -  Single vs Standard vs Submittable types identified
  -  Child tables marked

  API Endpoint Patterns for Each DocType:

  # Standard DocTypes (e.g., Item, Customer)
  GET    /api/resource/{DocType}          # List all
  GET    /api/resource/{DocType}/{name}   # Get single
  POST   /api/resource/{DocType}          # Create new
  PUT    /api/resource/{DocType}/{name}   # Update
  DELETE /api/resource/{DocType}/{name}   # Delete

  # Single DocTypes (e.g., System Settings)
  GET    /api/resource/{DocType}/{DocType}  # Get singleton

  Sample DocTypes by Category:

  Standard DocTypes (most common):
  - Customer, Item, Sales Order, Purchase Order, etc.

  Single DocTypes (singletons):
  - System Settings, Accounts Settings, Stock Settings, etc.

  Submittable DocTypes (workflow):
  - Sales Invoice, Purchase Invoice, Journal Entry, etc.

  Child Tables (part of parent):
  - Sales Order Item, Purchase Order Item, etc.
2025-08-22 17:23:16 +08:00

44 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# ERPNext API Test Script
# This script demonstrates how to access ERPNext APIs
API_URL="http://localhost:8080"
USERNAME="Administrator"
PASSWORD="LocalDev123!"
echo "======================================"
echo "ERPNext API Test Script"
echo "======================================"
echo ""
# 1. Login and save cookies
echo "1. Logging in..."
curl -s -c cookies.txt -X POST \
-H "Content-Type: application/json" \
-d "{\"usr\":\"$USERNAME\",\"pwd\":\"$PASSWORD\"}" \
$API_URL/api/method/login | jq '.'
echo ""
echo "2. Getting list of DocTypes (first 5)..."
curl -s -b cookies.txt "$API_URL/api/resource/DocType?limit_page_length=5" | jq '.data[].name'
echo ""
echo "3. Getting list of Users..."
curl -s -b cookies.txt "$API_URL/api/resource/User?fields=\[\"name\",\"full_name\",\"enabled\"\]&limit_page_length=3" | jq '.'
echo ""
echo "4. Getting system settings..."
curl -s -b cookies.txt "$API_URL/api/resource/System%20Settings/System%20Settings" | jq '{country: .data.country, timezone: .data.time_zone}'
echo ""
echo "5. Getting Company list..."
curl -s -b cookies.txt "$API_URL/api/resource/Company" | jq '.'
echo ""
echo "======================================"
echo "API test complete!"
echo "======================================"
# Clean up
rm -f cookies.txt