APIs & Integrations

joewang85jp
Miembro

Public App setting page returning same accountId

Hi, I am building a settings page for my public app. I am facing a problem similar to the one described in this question:

 

https://community.hubspot.com/t5/APIs-Integrations/Hubspot-Public-App-Settings/m-p/777367#M62788

 

According to the documentation, this is the JSON object I return to HubSpot:

{ "response": { "accounts": [ { "accountId": "test1", "accountName": "test1" }, { "accountId": "test2", "accountName": "test2" } ] } }

 

The issue is that for every toggle under each account, the toggle status only sends me the accountId at the top of the setting page (in this case, HubSpot always returns accountId as test1 even when I choose test2). The only way to fix it is to choose the account and refresh the page.

 

The strange part is that although the "toggle status" shows the wrong accountId, when I change the status of the toggle, the "toggle update" updates the correct AccountId.

 

For example, test1's toggle should be On, and test2's toggle should be Off. When I choose test2, HubSpot should return {'actionType': 'TOGGLE_FETCH', ..., "accountId": "test2"}, but it actually returns {'actionType': 'TOGGLE_FETCH', ..., "accountId": "test1"}, which makes test2's toggle show as On because test1's toggle in On. However, when I turn it Off, it returns {'actionType': 'TOGGLE_UPDATE', ..., 'accountId': 'test2', 'enabled': 'false'}, which shows accountId correctly. The only way to make it return the correct accountId when choosing another account is to refresh the page every time after you choose a new account.

 

Is there anything I can do to fix this problem? Or is it just something I'm doing wrong? Thanks for helping out.

0 Me gusta
3 Respuestas 3
Jaycee_Lewis
Administrador de la comunidad
Administrador de la comunidad

Public App setting page returning same accountId

Hey, @joewang85jp 👋 Thanks for your question. 

 

Because it's an ongoing development project and the specifics of your code can vary, it's quite challenging to pinpoint the exact issue without additional details. Would it be possible for you to share a snippet of your code, particularly the portion dealing with the accountId selection and display? Or any other relevant details that might help narrow down the root cause?

 

Thanks! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Me gusta
joewang85jp
Miembro

Public App setting page returning same accountId

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

0 Me gusta
joewang85jp
Miembro

Public App setting page returning same accountId

Hi @Jaycee_Lewis ,

 

Sorry for the bother, can someone help me?

I'm still facing the problem of toggle_fetch requesting the wrong accountId.

0 Me gusta