ERPNext exposes a powerful REST API that lets you integrate with external apps, automate tasks, and build custom frontends. This guide covers authentication, creating documents, reading data, and common API patterns.

Authentication

ERPNext supports two authentication methods — API keys and token-based auth.

Method 1: API Key + Secret

# Generate API keys from:
# User Settings > API Access > Generate Keys

curl -X GET https://yoursite.com/api/resource/Customer 
  -H "Authorization: token api_key:api_secret"

Method 2: Username + Password

curl -X POST https://yoursite.com/api/method/login 
  -H "Content-Type: application/json" 
  -d '{"usr":"admin@example.com","pwd":"your_password"}'

Create a Document

curl -X POST https://yoursite.com/api/resource/Customer 
  -H "Authorization: token api_key:api_secret" 
  -H "Content-Type: application/json" 
  -d '{
    "customer_name": "Acme Corp",
    "customer_type": "Company",
    "customer_group": "Commercial",
    "territory": "All Territories"
  }'

Read a Document

# Get a specific document
curl -X GET https://yoursite.com/api/resource/Customer/Acme%20Corp 
  -H "Authorization: token api_key:api_secret"

# List documents with filters
curl -X GET "https://yoursite.com/api/resource/Customer?filters=[["customer_type","=","Company"]]&fields=["name","customer_name"]&limit_page_length=20" 
  -H "Authorization: token api_key:api_secret"

Update a Document

curl -X PUT https://yoursite.com/api/resource/Customer/Acme%20Corp 
  -H "Authorization: token api_key:api_secret" 
  -H "Content-Type: application/json" 
  -d '{"customer_name": "Acme Corporation"}'

Delete a Document

curl -X DELETE https://yoursite.com/api/resource/Customer/Acme%20Corp 
  -H "Authorization: token api_key:api_secret"

Python Example

import requests

url = "https://yoursite.com"
headers = {"Authorization": "token api_key:api_secret"}

# Create
resp = requests.post(f"{url}/api/resource/Customer", headers=headers, json={
    "customer_name": "Test Corp",
    "customer_type": "Company"
})
print(resp.json())

# Read
resp = requests.get(f"{url}/api/resource/Customer/Test Corp", headers=headers)
print(resp.json())

# List with filters
resp = requests.get(f"{url}/api/resource/Customer", headers=headers, params={
    "fields": '["name","customer_name"]',
    "limit_page_length": 10
})
print(resp.json())

The ERPNext API follows REST conventions and returns JSON responses. Every Doctype automatically gets full CRUD API endpoints without any extra configuration.

Share this article

Comments

Join the discussion. Got a question, found an issue, or want to share your experience?

Leave a Comment

Your email stays private. We just use it for replies.

Nothing to preview yet.

Use **bold**, *italic*, `code`, ```code blocks```, [link](url), > quote, - list