Aakvatech Limited - Frappe v15 REST API Naming: name vs __newname

Frappe v15 introduced REST API v2 alongside the traditional `/api/resource` API. One subtle but important difference is how callers can explicitly control a new document's `name`.

 · 9 min read

Setting Document Names Through the Frappe v15 REST API

When integrating an external application with Frappe or ERPNext, there are cases where the external system already has a meaningful identifier.

For example:

EXT-CUSTOMER-000123
ORDER-98451
DEVICE-00125

You may want that identifier to become the actual Frappe document name, rather than allowing Frappe to generate another identifier.

In Frappe Framework v15, the correct way to do this depends on which REST API endpoint you use.

This distinction is particularly important because Frappe v15 supports both:

/api/resource/<doctype>

and the newer:

/api/v2/document/<doctype>

Although both ultimately create Frappe Documents, they do not handle an incoming name identically.

The short answer

For Frappe v15:

Endpoint Explicit naming behaviour
POST /api/resource/<doctype> Use __newname when the DocType uses autoname = Prompt
POST /api/v2/document/<doctype> Send name directly
Python doc.insert(set_name="...") Use set_name

The most significant difference is that API v2 explicitly recognizes a supplied name and tells the Document naming system that the name has already been set.


Traditional REST API: /api/resource

The traditional REST API creates documents using:

POST /api/resource/<doctype>

Frappe's v15 API implementation essentially performs:

def create_doc(doctype: str):
    data = get_request_form_data()
    data.pop("doctype", None)
    return frappe.new_doc(doctype, **data).insert()

Notice that there is no special handling here for:

{
    "name": "MY-DOCUMENT-NAME"
}

The request data is passed into frappe.new_doc() and then normal document insertion and naming logic executes.

Prompt-based DocTypes

For DocTypes configured with:

autoname = Prompt

Frappe uses the internal property:

__newname

to communicate the user-selected document name.

Therefore, a traditional REST request should look like this:

POST /api/resource/My%20DocType
Content-Type: application/json
Authorization: token API_KEY:API_SECRET

Payload:

{
    "__newname": "EXT-000123",
    "description": "External document"
}

During insertion, Frappe's Document.set_new_name() contains logic equivalent to:

if self.get("__newname") and autoname.lower() == "prompt":
    self.name = validate_name(
        self.doctype,
        self.get("__newname")
    )
    self.flags.name_set = True
    return

The result is:

name = EXT-000123

Why __newname exists

__newname is not normally a database field in your DocType.

It is framework metadata used during document creation.

The Desk UI uses the same mechanism when a DocType has:

autoname = Prompt

Frappe dynamically presents a field called:

__newname

and uses its value when inserting the document.

Conceptually:

User enters:
EXT-000123

        ↓

__newname = "EXT-000123"

        ↓

Document.set_new_name()

        ↓

name = "EXT-000123"

Once the document has been created, name is the actual persistent document identifier.


__newname is not a universal force-name mechanism

This distinction is important.

Suppose a DocType uses:

autoname = naming_series:

Sending:

{
    "__newname": "MY-CUSTOM-NAME"
}

does not mean:

Ignore the configured naming rules and force this document to use MY-CUSTOM-NAME.

The relevant Document.set_new_name() branch specifically checks:

autoname.lower() == "prompt"

Therefore __newname should primarily be considered the naming input for Prompt-based DocTypes.

The same applies when the DocType uses naming strategies such as:

field:item_code

or:

format:INV-{YYYY}-{#####}

or a controller-level autoname() implementation.

In those cases, normal Frappe naming logic applies.


Frappe v15 REST API v2

Frappe v15 introduced REST API v2.

The document creation endpoint is:

POST /api/v2/document/<doctype>

This endpoint behaves differently when name is included in the request.

The Frappe v15 implementation is effectively:

def create_doc(doctype: str):
    data = frappe.form_dict
    data.pop("doctype", None)

    doc = frappe.new_doc(doctype, **data)

    if (name := data.get("name")) and isinstance(name, str | int):
        doc.flags.name_set = True

    return doc.insert().as_dict()

The important line is:

doc.flags.name_set = True

That changes the naming behaviour significantly.


Setting name directly with API v2

Using API v2, you can send:

POST /api/v2/document/My%20DocType

with:

{
    "name": "EXT-000123",
    "description": "External document"
}

Frappe creates the in-memory document with:

name = EXT-000123

and then sets:

doc.flags.name_set = True

Before normal naming logic runs.


Why flags.name_set matters

Frappe's document naming routine begins with a check similar to:

if self.flags.name_set and not force:
    return

Therefore API v2 effectively says:

The caller has already supplied the document name. Do not generate another one.

This makes:

{
    "name": "EXT-000123"
}

fundamentally different from simply passing an ordinary field through the traditional API.

The normal autonaming process is bypassed.


Example: creating a document through API v2

Request:

POST /api/v2/document/Customer
Content-Type: application/json
Authorization: token API_KEY:API_SECRET

Payload:

{
    "name": "CUST-EXT-000123",
    "customer_name": "Example Company",
    "customer_type": "Company"
}

The resulting Frappe document can have:

name = CUST-EXT-000123

because API v2 explicitly marks the supplied name as already assigned.


The important difference

Consider a DocType configured with:

autoname = format:DOC-{#####}

Under normal naming behaviour, Frappe may generate:

DOC-00001

Traditional /api/resource

Sending:

{
    "__newname": "EXTERNAL-999"
}

does not automatically override that naming configuration because __newname is specifically handled for Prompt naming.

/api/v2/document

Sending:

{
    "name": "EXTERNAL-999"
}

causes API v2 to set:

doc.flags.name_set = True

so the ordinary naming routine does not replace the supplied name.

That makes API v2 particularly useful for integrations where the remote application's identifier must also be the Frappe document identifier.


Example comparison

Assume an external application has an order:

ERP-ORDER-78452

and you want exactly that value to become the Frappe document name.

API v1 / /api/resource

For a Prompt-named DocType:

{
    "__newname": "ERP-ORDER-78452",
    "customer": "ABC Limited"
}

Endpoint:

POST /api/resource/External Order

API v2

Payload:

{
    "name": "ERP-ORDER-78452",
    "customer": "ABC Limited"
}

Endpoint:

POST /api/v2/document/External Order

For an integration where the external ID must reliably become the Frappe document name, API v2 provides the clearer mechanism.


What about field: autonaming?

Suppose the DocType defines:

autoname = field:external_id

If you want normal Frappe naming behaviour, simply send:

{
    "external_id": "EXT-000123",
    "description": "Test"
}

Frappe will derive:

name = EXT-000123

from external_id.

There is no need to force a name in this situation.

This is usually preferable when the external identifier is genuinely part of the business data model.

For example:

external_id
device_code
employee_number
membership_number

can often be represented explicitly as DocType fields and used through field: autonaming.


What about naming series?

For a DocType using a naming series, a normal integration should generally allow Frappe to create the document name.

Example:

{
    "naming_series": "ORD-.YYYY.-",
    "customer": "ABC Limited"
}

Frappe might generate:

ORD-2026-00001

This is preferable when the Frappe-generated number represents the organization's official internal document number.

The external system identifier can instead be stored separately:

{
    "external_order_id": "SHOP-984551",
    "customer": "ABC Limited"
}

This gives you two independent identifiers:

Frappe name:
ORD-2026-00001

External reference:
SHOP-984551

That is often a better integration design than forcing the external identifier into name.


When should you explicitly control name?

Explicitly setting the Frappe document name can be useful for:

  • external master-data synchronization;
  • migration from another ERP;
  • integration records;
  • device registrations;
  • imported legacy identifiers;
  • records where another platform is the system of record;
  • idempotent API operations where the external identifier uniquely represents the object.

For example:

Shopify Order
External Payment
Bank Transaction Import
Device Registration
Legacy Customer
External Booking

may benefit from deterministic naming.


Deterministic names can help prevent duplicate integrations

Suppose an external system sends:

transaction_id = PAY-847292

If every incoming transaction is assigned a random Frappe name, retries require an additional lookup to determine whether that transaction has already been processed.

If the integration record itself uses:

PAY-847292

as its Frappe name, the integration can easily check:

Does PAY-847292 already exist?

before attempting another insert.

This can contribute to an idempotent integration design.

However, document naming alone should not be your only duplicate-prevention control. Integration-specific unique fields and appropriate server-side validation remain advisable.


Important security consideration

The ability to choose a document name does not bypass normal Frappe permissions.

A user calling:

POST /api/v2/document/<doctype>

must still have appropriate permission to create that document.

Likewise, the supplied name must still satisfy Frappe's document-name validation and database uniqueness requirements.

A supplied name therefore does not mean arbitrary database insertion.

It changes the naming decision, not the broader permission and validation model.


API v1 and API v2 side by side

Requirement /api/resource /api/v2/document
Available in Frappe v15 Yes Yes
Create document POST POST
Normal autonaming Yes Yes
Prompt naming input __newname __newname can still participate in Document naming
Explicit incoming name handling No special API handling Yes
Sets flags.name_set from incoming name No Yes
Suitable for deterministic external naming Limited by naming configuration Yes

Recommended integration approach

For Frappe v15 integrations, choose the naming strategy intentionally.

Let Frappe generate the name

Use normal DocType naming when Frappe owns the business identifier.

For example:

Sales Invoice
Purchase Invoice
Payment Entry
Sales Order

These documents commonly have organization-controlled numbering and should normally use standard naming configuration.

Use a business field for the name

Use:

autoname = field:external_id

when the external identifier is part of the actual domain model.

For example:

Device
Membership
External Account
Legacy Asset

Use API v2 name

Use:

{
    "name": "EXTERNAL-ID"
}

when the integration explicitly needs to supply the Frappe document's primary identifier independently of the configured naming mechanism.


Practical recommendation for Frappe v15

If you are writing a new integration against Frappe v15 and need explicit control over document names, prefer:

POST /api/v2/document/<doctype>

with:

{
    "name": "YOUR-EXTERNAL-ID"
}

The reason is visible directly in the API v2 implementation:

if (name := data.get("name")) and isinstance(name, str | int):
    doc.flags.name_set = True

That makes the API contract much clearer for deterministic naming.

For the traditional:

POST /api/resource/<doctype>

use:

{
    "__newname": "YOUR-NAME"
}

when working with a DocType configured for:

autoname = Prompt

Do not treat __newname as a universal replacement for Frappe's naming system.


Final takeaway

The difference can be summarized in two lines:

/api/resource + Prompt naming
        → __newname

versus:

/api/v2/document
        → name

The second mechanism is not merely accidental behaviour. Frappe v15's API v2 creation endpoint explicitly detects the supplied name and sets doc.flags.name_set.

Understanding this small implementation detail can prevent confusing integration failures, unexpected naming-series values, and unnecessary custom API endpoints.

Before designing an integration around externally supplied names, check the target DocType's autoname configuration and decide whether the external identifier should be:

  1. the Frappe document name;
  2. a dedicated business field; or
  3. merely an external reference while Frappe maintains its own numbering.

That design choice is more important than the API syntax itself.

Reference articles and discussions

  • Frappe Framework REST API documentation, covering /api/resource and the Frappe v15 API v2 /api/v2/document endpoints. Frappe Framework REST API documentation
  • Frappe Framework REST API CRUD documentation for /api/resource. Frappe REST API reference
  • Frappe Framework Document API documentation describing frappe.get_doc() and document creation. Frappe Document API
  • Frappe Framework source code, version-15, frappe/api/v1.py, reviewed for the traditional REST document creation path.
  • Frappe Framework source code, version-15, frappe/api/v2.py, reviewed for API v2 document creation and explicit name handling.
  • Frappe Framework source code, version-15, frappe/model/document.py, reviewed for Document.set_new_name(), __newname, and flags.name_set.
  • Frappe Framework project, maintained by Frappe Technologies and community contributors.
  • Technical discussion and validation performed against the Frappe version-15 source branch during preparation of this article.

Aakvatech Limited is a Frappe Gold Partner and ERPNext implementation company headquartered in Dar es Salaam, Tanzania, operating across East Africa and the UAE.

This article was co-created using AI to accelerate drafting, with final insights curated and validated by the author. Any customer, personal, or sensitive data referenced during drafting has been anonymized or masked where applicable. All contributors, reference URLs, tools, and materials used to assist this content curation are credited in the Reference section.


No comments yet.

Add a comment
Ctrl+Enter to add comment