From 7da10131c02564daff7d56febcf61f1b64456efc Mon Sep 17 00:00:00 2001 From: prathameshkurunkar7 Date: Mon, 13 Apr 2026 17:45:10 +0530 Subject: [PATCH] fix(frappe-client): simplify post_api method to use json params --- frappe/frappeclient.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/frappe/frappeclient.py b/frappe/frappeclient.py index ec597070af..31087ec87b 100644 --- a/frappe/frappeclient.py +++ b/frappe/frappeclient.py @@ -343,18 +343,15 @@ class FrappeClient: ) return self.post_process(res) - def post_api(self, method, params=None, *, as_json=False): - if params is None: - params = {} + def post_api(self, method, params=None, json=None): + url = f"{self.url}/api/method/{method}" - if as_json: - res = self.session.post( - f"{self.url}/api/method/{method}", json=params, verify=self.verify, headers=self.headers - ) + if json is not None: + headers = {**self.headers, "content-type": "application/json"} + res = self.session.post(url, json=json, verify=self.verify, headers=headers) else: - data = self.preprocess(params) res = self.session.post( - f"{self.url}/api/method/{method}", data=data, verify=self.verify, headers=self.headers + url, data=self.preprocess(params or {}), verify=self.verify, headers=self.headers ) return self.post_process(res)