Skip to content

Commit b92ce61

Browse files
Merge pull request The-Commit-Company#2094 from The-Commit-Company/develop
fix(notification): replace post_api with requests for large payload requests (The-Commit-Company#2093)
2 parents b87e410 + 0a4bce1 commit b92ce61

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

raven/notification.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,27 @@ def make_post_call_for_notification(messages, raven_settings):
199199
"""
200200
Make a post call to the push notification server to send the notification
201201
"""
202+
from base64 import b64encode
202203

203-
client = FrappeClient(
204-
url=raven_settings.push_notification_server_url,
205-
api_key=raven_settings.push_notification_api_key,
206-
api_secret=raven_settings.get_password("push_notification_api_secret"),
207-
)
204+
import requests
205+
206+
# instead of using the frappe client, we will use the requests library to make the post call
207+
# reason: FrappeClient's post_api method sends data in params which is not ideal for large payloads(Proxy returns JSON Decode errors as the URL is too long)
208+
# and post_request method uses "cmd" based key in it's payload which is weird semantically
209+
210+
api_key = raven_settings.push_notification_api_key
211+
api_secret = raven_settings.get_password("push_notification_api_secret")
212+
213+
token = b64encode(f"{api_key}:{api_secret}".encode()).decode()
214+
auth_header = {"Authorization": f"Basic {token}"}
208215

209-
client.post_api(
210-
"raven_cloud.api.notification.send_to_users",
211-
params={
216+
requests.post(
217+
f"{raven_settings.push_notification_server_url}/api/method/raven_cloud.api.notification.send_to_users",
218+
json={
212219
"messages": json.dumps(messages),
213220
"site_name": urlparse(frappe.utils.get_url()).hostname,
214221
},
222+
headers=auth_header,
215223
)
216224

217225

0 commit comments

Comments
 (0)