I am looking for a way to remove the Message keyword as I need to send a response in a predefined format in below code, the message keyword should not be there, and it should return in the payload directly
Disable Cache
1 request
250 B / 1.02 kB transferred
Finish: 1.82 s
1
{"data":{"whatsapp_galaxy_forward_flow_data_response":{"error_msg":null,"payload":"{\"message\":\"oueUaCDHYFStXSCrk1O53w7zn2s3VgCQHHnR2tfQicp4XaF3l5kfMOLb6bUmvkwbo2gB70t7ShhnGWm9fvLIPwS9K1Yz2g==\"}","status_code":200}},"extensions":{"is_final":true}}
avc
March 9, 2024, 12:15pm
2
Hi @CA_B.C_Chechani :
New v2 API provides response in “data” key.
frappe:develop
← ankush:api_v2
opened 12:22PM - 03 Sep 23 UTC
### Why?
- Versioning lets us improve the way APIs work while still being backw… ard compatible.
- We have known few problems with APIs for long time but they can't be easily addressed because they will likely require backward incompatible changes.
### Changes
- All API routing is now handled by Werkzeug routing.
- New alias for API versions `/api/*` == `/api/v1/`
- `/api/v2` prefix for new APIs.
- API versions will ONLY specify URL and response structure.
- REST APIs will not break between versions. RPC calls and schema are out of the scope of versioning, they CAN change between versions. Keeping them backward compatible is job of developers doing the changes.
### V2 changes and features
##### 1. Shorthand for all whitelisted functions in controller files.
```diff
- GET /api/v1/method/erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice
+ GET /api/v2/method/Sales Order/make_sales_invoice
```
##### 2. Call whitelisted functions directly on ~~resources~~ => documents.
```diff
- POST /api/v1/resource/Sales Order/SO-0001?run_method=submit
+ POST /api/v2/document/Sales Order/SO-0001/method/submit
```
closes https://github.com/frappe/frappe/issues/14869
##### 3. Response Structure change
- [x] `message` => `data` key for response data **everywhere**.
- [x] `errors` key for nested and rich error information, replacing `exc`/`exc_type` etc. closes https://github.com/frappe/frappe/issues/14905
##### 4. URL/verb differences
- PATCH == PUT for updating documents. PATCH is the correct convention for partial updates.
- APIs are now divided in 3 types:
- `document` - previously known as `resource`
- `method` - RPC calls, same as before
- `doctype` - new class of APIs that operate on doctype instead of documents. e.g. meta, count, list etc.
### TODO
- [x] This PR currently copies a lot of code to demonstrate changes. Rewrite all code that touches v2 APIs before merge.
- [x] Merge `handle.py` and `api.py`, remove `globals()` lookups in RPC handler. That's unnecessary special handling.
- [x] URL encoding of names
- [x] Finalize response structure
- [x] Impl Errors and message response structure
- [x] Tests for both versions. Aim 100% coverage for this.
- [x] Collections should have methods, e.g. `GET /api/resource/Sales Order/method/count`, meta (?)
- [x] File creation and attachment
- [ ] Update client side code, frappeclient.
- [ ] xcall now uses v2
- [x] All message handlers should work
Optional / separate PRs.
- [ ] Access to actual response object from whitelisted functions.
- [ ] frappe.response.header for sending custom headers
- [ ] get_value alternate
- [ ] Documents should have methods like add attachment, get attachment, add comment, etc
- [ ] Bulk update
- [ ] permissions ??
- [ ] bulk insert with array
- [x] delete child doc
- [ ] update js `frappe.db`
- [ ] `?expand=["link_field_name"]` to link fields to their linked documents.
- [ ] reports via rest api /api/report/name
Anyway, you can customize werkzeug response
Check this:
For custom functions/endpoints you can use werkzeug Response object
import json
from werkzeug.wrappers import Response
@frappe.whitelist()
def my_custom_endpoint():
data = {"foo": "bar"}
response = Response(json.dumps(data), content_type='application/json')
response.status_code = 200
return response
Hope this helps.
Thanks , I will follow as directed and update