# ERPNext REST API BOM and Stock Query Generator

> Source: https://netray.co/tools/erpnext-rest-api-bom-and-stock-query-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Build ERPNext REST requests with correct filters and fields for BOMs, stock bins and work orders, ready to paste into curl or Postman.

## Category

developer

## Erp

ERPNext

## Industry

Discrete Manufacturing

## Audience

- ERP developer
- ERP consultant
- Integration engineer

## Tool

**Kind:** template

**Output:** code

**Language:** http

**Fields:**

#### Site URL

**Key:** site

**Type:** text

**Default:** https://erp.example.com

#### Item code

**Key:** item

**Type:** text

**Default:** FG-1001

#### Warehouse

**Key:** warehouse

**Type:** text

**Default:** Stores - AC

#### Work order status

**Key:** wo_status

**Type:** select

**Options:**

- Not Started
- In Process
- Completed

**Default:** In Process

#### Page size

**Key:** limit

**Type:** number

**Default:** 100

**Blocks:**

#### Active BOMs for an item

**Body:** curl -G "{{site}}/api/resource/BOM" \
  -H "Authorization: token API_KEY:API_SECRET" \
  --data-urlencode 'filters=[["item","=","{{item}}"],["is_active","=",1],["docstatus","=",1]]' \
  --data-urlencode 'fields=["name","item","quantity","is_default","total_cost"]' \
  --data-urlencode 'limit_page_length={{limit}}'

#### One BOM with its component rows

**Body:** GET {{site}}/api/resource/BOM/BOM-{{item}}-001
Authorization: token API_KEY:API_SECRET

# The response contains an items child table (BOM Item rows)
# with item_code, qty, uom and rate for each component.

#### Stock in a warehouse (Bin)

**Body:** curl -G "{{site}}/api/resource/Bin" \
  -H "Authorization: token API_KEY:API_SECRET" \
  --data-urlencode 'filters=[["item_code","=","{{item}}"],["warehouse","=","{{warehouse}}"]]' \
  --data-urlencode 'fields=["item_code","warehouse","actual_qty","reserved_qty","projected_qty"]'

#### Work orders by status

**Body:** curl -G "{{site}}/api/resource/Work Order" \
  -H "Authorization: token API_KEY:API_SECRET" \
  --data-urlencode 'filters=[["status","=","{{wo_status}}"]]' \
  --data-urlencode 'fields=["name","production_item","qty","produced_qty","planned_start_date"]' \
  --data-urlencode 'order_by=planned_start_date asc' \
  --data-urlencode 'limit_page_length={{limit}}'

**Notes:** Create an API key and secret on the User document (API Access section) and use a dedicated integration user with read permissions only. Field names such as is_default and projected_qty are standard in current versions; confirm in your DocType if a call returns a field error.

## Content

**Intro:** ERPNext exposes every DocType through a REST API under /api/resource, with filters passed as JSON in the query string. This generator writes the requests for the most common manufacturing reads so you do not have to hand-escape the JSON.

**Sections:**

#### How to use the requests

**Body:** Enter your site URL, an item code, a warehouse and a work order status. Copy a block into a terminal or into Postman. The Authorization header uses the token scheme with an API key and secret from the user's API Access section. Responses are JSON wrapped in a data key. Always use urlencode so the brackets and quotes in the filters survive.

**Bullets:**

- Use filters for a list of triplets: field, operator, value
- Use fields to return only the columns you need
- Set limit_page_length and limit_start to page results
- Fetch a single document by name to receive its child tables

#### Filters, fields and paging

**Body:** A filter is an array of field, operator and value, with operators such as =, !=, like, in, between and >. List calls return only fields from the parent DocType, so child rows come from fetching the document itself. The default page size is 20, so a missing limit_page_length is the most common reason an integration appears to lose rows. For counts, call frappe.client.get_count under /api/method.

#### Reading stock correctly

**Body:** Bin returns actual_qty, reserved_qty and projected_qty per item and warehouse. Projected quantity includes planned receipts and requirements, so a planner and a storekeeper will read different numbers on purpose. For history and valuation, query Stock Ledger Entry instead. Whichever you use, read it with a role that cannot write, and cache results rather than polling every second.

#### Common mistakes

**Body:** Not URL-encoding the filter JSON, which produces a parse error. Using the login password in the token header instead of the API key and secret. Expecting draft BOMs in results when you filtered on docstatus 1. Sending a request to a DocType name with a space without encoding it. And putting API secrets in client-side code, where anyone can read them.

**Cta:** If you would rather ask your ERP questions in plain English than maintain API queries, Netray sets up read-only, grounded answers on your own infrastructure.

**Faq:**

#### How do I authenticate to the ERPNext API?

**Answer:** Generate an API key and secret on the User record, then send the header Authorization: token key:secret with each request. Session cookies from the login endpoint also work for browser tools. Use a dedicated integration user with only the roles it needs.

#### Why do I only get 20 records back?

**Answer:** List calls default to 20 results. Set limit_page_length to a larger value, or 0 for no limit on small sets, and use limit_start to page through large ones. Pass a stable order_by so pages do not overlap or skip rows between requests.

#### Can I create documents with the same API?

**Answer:** Yes. POST a JSON body to /api/resource/DocType to insert a document, and PUT to update it. Submitting is a separate step that sets docstatus to 1. Writes run validations and hooks, so test in a staging site before pointing automation at production.

#### How do I get child table rows like BOM items?

**Answer:** Fetch the parent document by name with GET /api/resource/BOM/name. The response includes child tables such as items and operations as arrays. List endpoints do not return child rows, so for bulk component data fetch documents in a loop or use a custom report endpoint.

## Search terms

erpnext rest api example, erpnext api resource filters, erpnext get bom api, erpnext bin api stock, frappe api token authentication, erpnext work order api, erpnext curl api, frappe api filters json

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
