Want to create post api for a doctype which i created

I want to create the api for this form. The scenario is, i have created this doctype directly on the server so that my client can access it for testing.
Please can someone tell me the path how can i create the api for this doctype.

Hi @Aditya_vig1:

REST API is created automatically for your doctype. Look here:


You can create also custom api:

Hope this helps.

1 Like

Thanks @avc for replying.
Please have a look into this. and tell me where i am wrong

frappe.ui.form.on(‘Material Tagging’, {
// refresh: function(frm) {
fetch(‘’, {
headers: {
‘Authorization’: ‘token 925e0e81ae34590:a0aaade8e4d9ed2’
.then(r => r.json())
.then(r => {
// }

this is the js code

mport frappe

import json


def add_custom_data():


    # Get the JSON data from the request

    data = frappe.request.data


    # json_data = frappe.parse_json(data)

    json_data = frappe.parse_json(data.decode('utf-8'))

    # Check if the data is empty or if "data" key is not found

    if not json_data or "data" not in json_data:

        return {'message': 'No valid data provided in the request.'}

    # Define the DocType name

    doctype_name = 'Material Tagging'  # Replace with the actual DocType name

    # Access the "data" key to get the list of dictionaries

    data_list = json_data["data"]

    # Create and insert entries from the list of dictionaries

    for entry_data in data_list:

        # Create a new document of the custom DocType

        doc = frappe.get_doc({

            'doctype': doctype_name,

            'batch': entry_data.get('batch'),  # Use the correct field names

            'customer': entry_data.get('customer'),    # Use the correct field names

            'date': entry_data.get('date'),

            'shade': entry_data.get('shade'),

            'fabric_width': entry_data.get('fabric_width'),

            'style': entry_data.get('style'),

            'roll': entry_data.get('roll'),

            'roll_weight': entry_data.get('roll_weight'),

            'yard': entry_data.get('yard'),

            'manufacturer': entry_data.get('manufacturer'),

            'rfid_tag': entry_data.get('rfid_tag'),

            # Add other fields as needed


        # Save the document


    return {'message': f'{len(data_list)} entries added successfully'}

except Exception as e:

    frappe.log_error(frappe.get_traceback(), 'Custom Data API Error')

    return {'message': str(e)}

this is the python code.
in local i am able to hit this api with postman but when i am on server and hit this api as the url

Please tell me what i am doing wrong??

HI @Aditya_vig1:

Maybe I am not understanding your requirement … but:

Use frappe.call to get access to the resources from client side (inside frappe application). No authentication headers needed here.


To use REST API from external apps, follow the instructions mentioned above:



    "Accept": "application/json",
    "Content-Type": "application/json",


'Authorization': 'Basic api_key:api_secret'

Note that token (api_key:api_secret) should be Base64 encoded


{"batch": batch,
 "customer": customer,
 "date": date,

Hope this helps.

Hi @avc
Can i tell you my requirement agian.
I just have to give this api to my client who is not using this frappe, erpnext. They will access it on their application. I just have to give the end-point to my client. They should be able to access the fields on this doctype and enter the values and post it.

How can they access the fields which are present on this doctype?

Thanks & Regards

Hi @Aditya_vig1:



Please, read this. All operations (create, update, delete …) over all your doctype data are avaliable: