Step 1:
Create a Custom doctype in your Custom app
assume Whatsapp
your custom app and Status is your custom doctype
Step 2: Task
Create a 2 API
create_satatus
anddelete_status
Step 3: Create API in Status
Doctype
status.py
import json
import frappe
from frappe.model.document import Document
from werkzeug.wrappers import Response
from frappe.utils import response as r
class ShoppingCart(Document):
pass
@frappe.whitelist(method='POST')
def create_status():
# Your Code here
data = json.loads(frappe.request.data)
doc = frappe.new_doc('Status')
doc.title = 'New Task 1'
doc.ordered_by = frappe.session.user
doc.text_status = data.get('text_status')
doc.insert()
return {'status_code':200, 'message': 'Status Uploaded succesfully'}
@frappe.whitelist(method='DELETE')
def delete_status():
# Your Code here
data = json.loads(frappe.request.data)
frappe.db.delete("Route History", {
"name": data.get("name")
})
Step 4: After creating the API hit API from the postman
add Header
in both API CLICK
Get API Key and Secret Key
Go to
User
doctype and scroll down you find a API Access generate there
POST method
http://mysite.localhost:8000/api/method/whatsapp.whatsapp.doctype.status.status.create_status
JSON BODY
{
"text_status": "Hi I'm in Traveling"
}
DELETE method
http://mysite.localhost:8000/api/method/whatsapp.whatsapp.doctype.status.status.delete_status
JSON BODY
{
"name": "status-0001"
}