Thank you for your response, @Jaycee_Lewis
I won’t be able to provide the original code until next Tuesday, but I remember the general structure of the code. However, I don’t think the issue I’m facing requires such detailed code. The project uses AWS Lambda and is monitored and debugged using AWS CloudWatch. I’m using Python with the Flask framework. The “account component,” “toggle status,” and “update toggle” endpoints all use the POST method, and these URLs do not include any GET queries.
Here is the approximate code for the account component.
@app.route("/hubspot/settings/account", methods=["POST"])
def hubspot_settings_account():
# * Verify the signature from HubSpot (v2)
if not signature_verify_manager.verify_request_from_app_setting_page(request):
return abort(400, "Invalid signature")
# * Get the account information from our database
# * skip this part
response = {
"response": {
"accounts": [
{"accountId": "test1", "accountName": "test1"},
{"accountId": "test2", "accountName": "test2"},
]
}
}
return jsonify(response)
Here is the approximate code for the toggle status.
@app.route("/hubspot/settings/toggle-status", methods=["POST"])
def hubspot_settings_toggle_status():
# * Verify the signature from HubSpot (v2)
if not signature_verify_manager.verify_request_from_app_setting_page(request):
return abort(400, "Invalid signature")
data_toggle_status = request.json
print(data_toggle_status)
# ! I print the data to see what is in it
# ! And the data's accountId is showing wrong accountId as I mentioned in the question
# * Get the toggle status from the database
# * skip this part
return
Here is the approximate code for the update toggle.
@app.route("/hubspot/settings/update-toggle", methods=["POST"])
def hubspot_settings_update_toggle():
# * Verify the signature from HubSpot (v2)
if not signature_verify_manager.verify_request_from_app_setting_page(request):
return abort(400, "Invalid signature")
data_update_toggle = request.json
print(data_update_toggle)
# ! I print the data to see what is in it
# ! And this data's accountId is showing the right one
# * Change the toggle status in the database
# * skip this part
return
The problem and situation I encountered are as follows:
1. When I enter the settings for this app, the settings page for the account of test1 is displayed first. At this time, HubSpot sends me a toggle_fetch request. The log shows the following content, and the accountId is correct at this time.
{'actionType': 'TOGGLE_FETCH', ..., 'accountId': 'test1'}
2. At this point, I click to switch accounts and select the account for test2. I then observe the log again. Due to the change of account, HubSpot sends me another toggle_fetch request to confirm the toggle status of this account. The content at this time is as follows, and the accountId is incorrect.
{'actionType': 'TOGGLE_FETCH', ..., 'accountId': 'test1'}
3. However, if I refresh the webpage at this point, that is, directly refresh the webpage while the test2 account is selected, HubSpot sends me another toggle_fetch request. The toggle_fetch content at this time becomes correct.
{'actionType': 'TOGGLE_FETCH', ..., 'accountId': 'test2'}
4. If I do not refresh the webpage (or skip 3.) but instead keep the state of 2. and directly change the toggle status (i.e., turn on or off the toggle option), HubSpot sends me an update toggle request, and the content is correct. It shows that the toggle for test2 is requested to be changed.
{'actionType': 'TOGGLE_UPDATE', ..., 'accountId': 'test2', 'enabled': '...'}
My question is, is the incorrect display of the accountId at 2. a problem with my code or environment? Because the incorrect accountId in the request would cause my code to call the wrong data when querying the toggle status from the database. If so, how can I solve this problem? Thank you