Building a Mobile App on Top of ERPNext APIs: Auth, Sync, and Poor Connections

How to build a mobile app on ERPNext's APIs: choose the right authentication, design custom endpoints, sync data safely, and handle weak or missing connections.

Share Article:
Building a Mobile App on Top of ERPNext APIs: Auth, Sync, and Poor Connections
Dhruv Patel
Post By
Dhruv Patel

Why Build a Mobile App on ERPNext?

ERPNext is great at running the back office. But your sales team is in the field, your warehouse staff are walking around with a phone, and your delivery drivers are rarely at a desk. A mobile app gives them just the part of the ERP they need, in a form that works on a small screen.

The good news is that Frappe and ERPNext already expose APIs, so you don't have to build a backend from scratch. The harder parts are the ones around it: authentication, deciding what data to send to the phone, keeping it in sync, and handling poor connections.

In this post, we'll walk through each of those, with practical advice from building mobile apps on top of Frappe. If you're still deciding whether you need a native app at all, start with our guide to choosing between a mobile app, a web app, and a PWA.

What Frappe Gives You Out of the Box

Frappe exposes two main kinds of API:

  • Resource API - Standard create, read, update, and delete access to any DocType, under /api/resource/
  • Method API - Calls to server functions that you mark as whitelisted, under /api/method/

Both respect the logged-in user's roles and permissions, so a user only sees and changes what they are allowed to in ERPNext itself.

The resource API is a good start, and it's fine for simple lists and forms. But for a real mobile app, you will usually add your own endpoints.

Step 1: Choose the Right Authentication

Authentication is the first decision, and the easiest to get wrong.

Option A: API key and secret. Each user can have an API key and secret, and requests send them in the Authorization header. It's simple, and it's good for server-to-server integrations.

Option B: Login-based sessions or tokens. The user signs in with their own credentials, and the app stores a session or token for that user. This suits mobile apps better, because every person has their own identity.

Option C: OAuth. Frappe also supports OAuth 2, which is a good fit if you need a more formal flow or third-party sign-in.

A few rules we follow:

  • Never put a shared API secret inside the app. Anything inside a mobile app can be extracted by someone determined enough
  • Use per-user credentials, so permissions and audit trails match real people
  • Store tokens in secure storage on the device, not in plain app storage
  • Plan for expiry and logout - Handle expired sessions gracefully, and clear everything on sign-out
  • Think about revoking access - When someone leaves the company, their access should end immediately

Step 2: Don't Send the Whole DocType to the Phone

A Sales Order in ERPNext can have dozens of fields and child tables. A phone screen needs a handful.

With the resource API, ask only for what you need:

TS
const params = new URLSearchParams({
  fields: JSON.stringify(["name", "customer", "grand_total", "status", "modified"]),
  filters: JSON.stringify([["status", "=", "To Deliver and Bill"]]),
  limit_page_length: "20",
  limit_start: "0",
  order_by: "modified desc",
});

const res = await fetch(`${BASE_URL}/api/resource/Sales Order?${params}`, {
  headers: { Authorization: `Bearer ${token}` },
});
const { data } = await res.json();

Smaller responses mean faster screens, less data use, and less to go wrong on a weak connection. Always paginate lists instead of loading everything at once.

Step 3: Write Your Own Endpoints for Real Screens

Once a screen needs more than one request, or some logic, create a whitelisted method in a custom app:

PYTHON
import frappe

@frappe.whitelist()
def get_my_orders(start=0, limit=20):
    return frappe.get_list(
        "Sales Order",
        fields=["name", "customer", "grand_total", "status", "modified"],
        filters={"owner": frappe.session.user},
        order_by="modified desc",
        limit_start=int(start),
        limit_page_length=int(limit),
    )

This gives you:

  • One request per screen instead of five
  • Logic on the server, where it's easier to change without releasing a new app version
  • A stable contract between your app and your backend

Put these endpoints in a proper custom app, not in scattered scripts. We explain why in Frappe custom app vs server scripts. A mobile API is exactly the kind of long-lived, testable code that belongs in version control.

Also remember that old app versions stay in users' pockets for a long time. Don't break existing endpoints, and add new ones instead of changing old ones. The same compatibility thinking applies to the rollout itself, which we cover in shipping a React Native rewrite while production stays live.

Step 4: Handle Poor Connections

Field staff work in basements, warehouses, rural roads, and lifts. Assume the connection will drop.

Make reads resilient:

  • Cache the data users need most - Customer lists, item lists, and recent documents
  • Show cached data first, then refresh in the background
  • Show clear status - Let users know when they're offline and when data was last updated

Make writes safe:

  • Queue changes locally when offline, and send them when the connection returns
  • Give each queued action a unique ID, so a retry never creates a duplicate order or payment
  • Retry with a delay, and stop after a sensible number of attempts
  • Show the user what's pending, so nothing silently disappears

The duplicate problem is the one that causes real damage. If a request times out after the server already saved it, a naive retry creates a second record. Unique request IDs, checked on the server, solve this.

Step 5: Keep Data in Sync

Syncing doesn't mean downloading everything every time.

  • Use the modified timestamp - Ask only for records changed since the last successful sync
  • Sync in small batches so a dropped connection doesn't lose everything
  • Handle deletions - Decide how the app learns that something was removed or cancelled
  • Decide who wins in a conflict - If a document changed on the server while the user edited it offline, show the user what changed, rather than silently overwriting it
  • Respect submitted documents - Many ERPNext documents can't be edited after submission, so the app must handle those rules

Keep the first version simple. Often, a few key lists synced regularly plus a safe write queue is enough.

Step 6: Handle Files, Photos, and Notifications

  • File uploads - Photos of delivery proofs, receipts, and signatures can go through Frappe's upload endpoint. Compress images on the device first, since phone photos can be very large
  • Push notifications - Use a push service such as Firebase Cloud Messaging, with a server-side hook in your custom app that sends a notification when something relevant happens, like a new assignment or an approval request
  • Printable documents - If your app needs invoices or reports as PDFs, our React Native PDF library can generate multi-page documents with headers, footers, and page numbers directly on the device

Step 7: Plan for Multiple Sites

If you run a multi-tenant product, each customer is a separate site with its own address, which means your app needs to know which site to talk to. Common approaches are asking for a company code at login, or using a per-customer app configuration. The backend side of this is covered in multi-tenant SaaS on Frappe.

Security Checklist for the App

  • Per-user authentication, with no shared secrets in the app
  • Tokens in secure device storage
  • HTTPS everywhere
  • Permissions enforced on the server, never only in the app
  • Input validated on the server
  • Rate limits and monitoring on custom endpoints
  • Dependencies reviewed, since a mobile app pulls in many packages. Our npm supply-chain security guide covers practical habits for this

Common Mistakes

  • Embedding an API secret in the app
  • Using the resource API for everything, then fighting slow, chatty screens
  • No offline plan, so the app is useless on a weak connection
  • Retries that create duplicates
  • Breaking old endpoints while old app versions are still in use
  • Putting business rules only in the app, where they can be bypassed
  • Syncing too much data and draining battery and data plans

A Starter Architecture

For a first version, a simple setup works well:

  • Mobile app in React Native, with secure storage and a small local cache
  • Custom Frappe app with whitelisted endpoints for each main screen
  • Per-user authentication with permissions enforced by Frappe
  • Write queue with unique request IDs
  • Incremental sync using modified timestamps
  • Push notifications through a push service
  • Monitoring for errors and slow endpoints

Add complexity only when real users need it.

Who Should Use This Guide?

  • Teams adding a mobile app to an existing ERPNext setup
  • Developers building field-service, delivery, or sales apps on Frappe
  • Founders building a mobile product on a Frappe backend
  • Agencies delivering mobile apps for ERPNext clients

Conclusion

Frappe gives you a solid API foundation, but a good mobile app is built in the details: per-user authentication, small purpose-built endpoints, safe offline writes, and careful syncing. Get those right, and your team gets the right slice of the ERP in their pocket, even on a weak connection.

At Flitz Interactive, we build React Native apps on top of Frappe and ERPNext, from API design to app store release. If you're planning one, we'd be happy to talk it through.

Links