erpnext-api-patterns
Complete guide for ERPNext/Frappe API integrations (v14/v15/v16) including REST API, RPC API, authentication, webhooks, and rate limiting. Use when code is needed for external API calls to ERPNext, designing API endpoints, configuring webhooks, implementing authentication (token/OAuth2/session). Triggers: API integration, REST endpoint, webhook, token authentication, OAuth, frappe.call, external connection, API response, rate limiting.
Works with
---
name: erpnext-api-patterns
description: Complete guide for ERPNext/Frappe API integrations (v14/v15/v16) including REST API, RPC API, authentication, webhooks, and rate limiting. Use when code is needed for external API calls to ERPNext, designing API endpoints, configuring webhooks, implementing authentication (token/OAuth2/session). Triggers: API integration, REST endpoint, webhook, token authentication, OAuth, frappe.call, external connection, API response, rate limiting.
license: MIT
---
# ERPNext API Patterns
## API Type Decision Tree
```
What do you want to achieve?
│
├─► CRUD operations on documents
│ └─► REST API: /api/resource/{doctype}
│
├─► Call custom business logic
│ └─► RPC API: /api/method/{path}
│
├─► Notify external systems on events
│ └─► Configure Webhooks
│
└─► Client-side server calls (JavaScript)
└─► frappe.call() or frappe.xcall()
```
## Quick Reference
### Authentication Headers
```python
# Token Auth (RECOMMENDED for integrations)
headers = {
'Authorization': 'token api_key:api_secret',
'Accept': 'application/json',
'Content-Type': 'application/json'
}
# Bearer Token (OAuth2)
headers = {'Authorization': 'Bearer {access_token}'}
```
### REST API CRUD
| Operation | Method | Endpoint |
|-----------|--------|----------|
| List | `GET` | `/api/resource/{doctype}` |
| Create | `POST` | `/api/resource/{doctype}` |
| Read | `GET` | `/api/resource/{doctype}/{name}` |
| Update | `PUT` | `/api/resource/{doctype}/{name}` |
| Delete | `DELETE` | `/api/resource/{doctype}/{name}` |
### Filter Operators
```python
# Basic filters
filters = [["status", "=", "Open"]]
filters = [["amount", ">", 1000]]
filters = [["status", "in", ["Open", "Pending"]]]
filters = [["date", "between", ["2024-01-01", "2024-12-31"]]]
filters = [["reference", "is", "set"]] # NOT NULL
```
### RPC Method Call
```python
# Server-side: mark with decorator
@frappe.whitelist()
def my_function(param1, param2):
return {"result": "value"}
# API call
POST /api/method/my_app.api.my_function
{"param1": "value1", "param2": "value2"}
```
### Client-Side Calls (JavaScript)
```javascript
// Async/await pattern (RECOMMENDED)
const result = await frappe.xcall('my_app.api.my_function', {
param1: 'value'
});
// Promise pattern
frappe.call({
method: 'my_app.api.my_function',
args: {param1: 'value'},
freeze: true,
freeze_message: __('Processing...')
}).then(r => console.log(r.message));
```
## Response Structure
**REST API Success:**
```json
{"data": {...}}
```
**RPC API Success:**
```json
{"message": "return_value"}
```
**Error Response:**
```json
{
"exc_type": "ValidationError",
"_server_messages": "[{\"message\": \"Error details\"}]"
}
```
## HTTP Status Codes
| Code | Meaning |
|------|---------|
| `200` | Success |
| `400` | Validation error |
| `401` | No authentication |
| `403` | No permissions |
| `404` | Document not found |
| `417` | Server exception |
| `429` | Rate limit exceeded |
## Critical Rules
1. **ALWAYS** include `Accept: application/json` header
2. **ALWAYS** add permission checks in whitelisted methods
3. **NEVER** hardcode credentials - use `frappe.conf`
4. **NEVER** write SQL injection vulnerable queries
5. **GET** for read-only, **POST** for state-changing operations
## Reference Files
| File | Contents |
|------|----------|
| [authentication-methods.md](references/authentication-methods.md) | Token, Session, OAuth2 implementation |
| [rest-api-reference.md](references/rest-api-reference.md) | Complete REST API with filters and pagination |
| [rpc-api-reference.md](references/rpc-api-reference.md) | Whitelisted methods and frappe.call patterns |
| [webhooks-reference.md](references/webhooks-reference.md) | Webhook configuration and security |
| [anti-patterns.md](references/anti-patterns.md) | Common mistakes and fixes |
## Version Notes (v14 vs v15)
| Feature | v14 | v15 |
|---------|-----|-----|
| `expand_links` parameter | ❌ | ✅ |
| Server Script rate limiting | ❌ | ✅ |
| PKCE for OAuth2 | Limited | ✅ |More API Design skills
lark-event
larksuite/cli
Lark/Feishu real-time event listening / subscribing / consuming: stream events as NDJSON via `lark-cli event consume <EventKey>` (covers IM messages/reactions/chat changes, Approval status changes, Task updates, VC meeting started/joined/ended, Minutes generated, Whiteboard updated, etc.). Use for Lark bots, real-time message processing, long-running subscribers, streaming webhook/push handlers. Supports `--max-events` / `--timeout` bounded runs and a stderr ready-marker contract — designed for AI agents running as subprocesses.
lark-contact
larksuite/cli
飞书 / Lark 通讯录:按姓名 / 邮箱解析成 open_id,或按 open_id 反查姓名 / 部门 / 邮箱 / 联系方式 / 个人状态 / 签名,以及按关键词搜索当前用户可见的机器人 / 智能体(agent)。当用户提到一个名字要下一步发消息 / 排日程,或拿到 open_id 想查具体信息时使用。不负责部门树遍历、按部门列员工、组织架构图,这类需求走原生 OpenAPI。
lark-openapi-explorer
larksuite/cli
飞书/Lark 原生 OpenAPI 探索:从官方文档库中挖掘未经 CLI 封装的原生 OpenAPI 接口。当用户的需求无法被现有 lark-* skill 或 lark-cli 已注册命令满足,需要查找并调用原生飞书 OpenAPI 时使用。

