Working with Endpoints / API

What I’m trying to do:
I set up Tally.so form. It shows from Tally end that the data is being sent, but the server on anvil side is not getting anything. I checked logfiles and nothing

Tally server logs indicates they are sending it

What I’ve tried and what’s not working:
Anvil server code

@anvil.server.http_endpoint("/moving-leads", methods=["POST"])
def tally_webhook(**kwargs):
    print("Webhook received!")
    print(anvil.server.request.body_json) 
    # Extract JSON payload from the request
    json_payload = anvil.server.request.body_json

    # Example: Extract specific fields from Tally's JSON structure
    name = json_payload.get("fields", {}).get("question_Xro8JY", None)  # Replace "name" with actual field key
    email = json_payload.get("fields", {}).get("question_8zL6aP", None)  # Replace "email" with actual field key

    # Debugging: Log the entire payload
    print("Received JSON payload:", json_payload)

    # Store data in Data Tables (optional)
    if name and email:
        app_tables.leads.add_row(name=name, email=email)

    # Return a success message to Tally
    return {"status": "success", "message": "Data received successfully"}

Nothing in Anvil side

Any clues as to what is going on?

Clone link:
share a copy of your app

It appears that Anvil is suffering from a cyber attack.

I’ve also had no app logs, even though I was in the app and shoul’ve logs:

2 Likes

I found the answer to my own question with the help of ChatGPT. Thanks @gabriel.duro.s for letting me know that their was cyberattack.

Here is the code for anyone that might be interested.

@anvil.server.http_endpoint("/moving-leads", methods=["POST"])
def tally_webhook(**kwargs):
    print("Webhook received!")
    print(anvil.server.request.body_json) 
    # Extract JSON payload from the request
    json_payload = anvil.server.request.body_json

    # Debugging: Log the entire payload
    print("Received JSON payload:", json_payload)

    # Store data in Data Tables (optional)
    fields = json_payload.get("data", {}).get("fields", [])  # Get the "fields" array safely

    # Initialize variables
    name = None
    email = None

    # Loop through the array to find the specific fields
    for field in fields:
      if field.get("key") == "question_Xro8JY":  # Check for the key of the "name" field
        name = field.get("value")  # Extract the value
      elif field.get("key") == "question_8zL6aP":  # Check for the key of the "email" field
        email = field.get("value")  # Extract the value

    # Print the results for debugging
    print("Name:", name)
    print("Email:", email)

    #add to leads
    app_tables.leads.add_row(Name=name,Email=email)

1 Like