Dedicated API endpoint for GET request

Hello,

being beginner in IT and ERPNext, just wanted to know after creating GET request (eg : > @frappe.whitelist(allow_guest=True)

def get_item(item=None):
if item:
# Item = frappe.db.get_value(‘Item’, item, [‘name’, ‘owner’])
Item = frappe.db.get_value(‘Item’, item, ‘name’)
else:
Item = frappe.db.get_all(‘Item’, fields=[‘*’])

return Item

i’m getting the data but using the same endpoint for POST request, still getting the data… so my query here : IS THERE ANY METHOD/PERMISSION mechanism WHERE I CAN RESTRICT and not getting data while using POST API endpoint in postman

Hi, @Rajesh_Sukheja
Yes you can restrict the access for only GET method.

@frappe.whitelist(allow_guest=True, request_method="GET")
def get_item(item=None):
    if item:
        Item = frappe.db.get_value('Item', item, 'name')
    else:
        Item = frappe.db.get_all('Item', fields=['*'])

    return Item

Hope this will help you out.

Thank you.

Great… :+1:
yes it works
Thanks @VINOTH , thanks a lot

@VINOTH , one more thing Vinoth, can you send documentation where this thing mentioned, wanted to read more about this because i didn’t get anything in this : Introduction

Once again thanks

Sure, This Rest API link might help you out, and you can refer this link also.

Hope this will give you some clarity in this concepts.
Thank you.

@VINOTH Thanks for links :+1:

Hi @VINOTH , i checked again and there is an error in POSTMAN while using suggested above code :

earlier when i was using my code and got the data while using POST request and quickly committed mine and tried urs and didn’t get data in response which i got in my code (but yes got this error at that time also) and thought not getting the data in response so felt it works but i would appreciate if you can help me out with this error

Hi, @Rajesh_Sukheja

The requested argument is not valid, So the below code might give you a solution.

@frappe.whitelist(allow_guest=True)
def get_item(item=None, request_method="GET"):
    if item:
        Item = frappe.db.get_value('Item', item, 'name')
    else:
        Item = frappe.db.get_all('Item', fields=['*'])

    return Item

Hope this will help you out.

Thank you