OneHash generates REST API for all of your DocTypes out of the box and can be used to seemless integration with other systems.


There are two ways to authenticate through REST API. Token based authentication and password based authentication.

1. Token Based Authentication

A token is a pair of API Key and API Secret. First, you must create an API User and then generate the keys in the API Access section in the User form.
The token is generated by concatenating api_key and api_secret with a colon :. Pass the string token api_key:api_secret to the Authorization header in the request.

2. Password Based Authentication

Password based authentication relies on cookies and session data to maintain authentication in subsequent requests. In most cases, the library you are using to issue REST calls will handle session data, but if it doesn't you should use Token based authentication.

Listing Documents

To get a list of records of a DocType, send a GET request at /api/resource/:doctype. By
default, it will return 20 records and will only fetch the name of the records.
GET /api/resource/:doctype


You can specify which fields to fetch in the fields param. It should be a JSON array.

GET /api/resource/:doctype?fields=["field1", "field2"]

You can filter the records by passing filters param. Filters should be an array, where each
filter is of the format: [field, operator, value]

GET /api/resource/:doctype?filters=[["field1", "=", "value1"], ["field2",">", "value2"]]

You can also provide the sort field and order. It should be of the format fieldname asc or
fieldname desc. The space should be URL encoded.

GET /api/resource/:doctype?order_by=title%20desc

You can also page the results by providing the limit_start and limit_page_length params.

GET /api/resource/:doctype?limit_start=10&limit_page_length=20

CRUD Operations

OneHash generates REST endpoints for CRUD operations for all DocTypes automatically. Make
sure you set the following headers in your requests so that you get proper JSON responses.


Create a new document by sending a POST request to /api/resource/:doctype. Send the
document as JSON in the Request Body.



Get a document by sending a GET request to /api/resource/:doctype/:name.

GET /api/resource/:doctype/:name



Update a document by sending a PUT request to /api/resource/:doctype/:name. You don't need to send the whole document, instead you can just send the fields that you want to update.



Delete a document by sending a DELETE request to /api/resource/:doctype/:name.

DELETE /api/resource/:doctype/:name


{"message": "ok"}

File Uploads

There is a dedicated method /api/method/upload_file that accepts binary file data and uploads it into the system.
Here is the curl command for it:

If you are using client side Javascript to upload files, you can append the uploaded files as FormData and send an XHR request.

Was this article helpful?
Thank you!