How to update or create entry in Notion database

Hi, all. This has got me stuck. I think I’m missing something so simple here!

I want my tally form to either 1. create a new database entry if it doesn’t exist or 2. update an existing database entry.

So if the person’s email in Tally form already exists in the Notion People database, then it should update that entry. If the email doesn’t exist, it should create a new entry.

I think I need to use a ‘branch’ to create it, but that doesn’t seem to be right.

Here’s a screenshot of what I have so far:

All help welcome, this has me so confused :sweat_smile:

Hi @nathanmaingard ,

It seems you’ve already figured out the solution; it just needs one more step to search for existing database items. Here’s how the final flow would look:

1. Tally New Submission Trigger:

This step will fetch new form submissions using webhooks. You can test it to ensure it includes the necessary Email field, which will be used in the next step.

2. Custom API Call (Search Database Item):

For Step 2, we’ll search for a record with a matching Email (received from the Tally response). Currently, the Notion piece doesn’t have a search action, but you can use a custom API call action.

In the URL field, include the database ID after /databases/ . You can find this ID in the URL of the Notion UI.

In the Body field, replace the property value with the actual column name of the Email field of database (in the image, it’s Email ) and replace the value of contains with the email value received in the Tally step response.

Now, test this step, and it will return a list of items matched with the email in the response. You can use it in the branch step.

Let me know if you face any issue with this flow.

Thanks a bunch for the help with this!

So I think I did good…but am stuck again :grin:. Not sure how to set u the branch… I can’t see an ‘email’ value to put in for the second value.


p

Have you set up the second step? Is it returning any data?

1 Like

Hi again! Sorry, I missed your reply. Yes, there is data coming back from the second step, but I don’t see an email in there.

Not sure if any of this is an issue to share here, but here’s what I’ve got:

{
  "body": {
    "type": "page_or_database",
    "object": "list",
    "results": [],
    "has_more": false,
    "request_id": "24e8c59f-5233-4291-b543-e2c39595b4fb",
    "next_cursor": null,
    "page_or_database": {}
  },
  "status": 200,
  "headers": {
    "date": "Mon, 15 Apr 2024 11:21:09 GMT",
    "etag": "W/\"a6-IFYbv51n359BZos4oJaQo9Ki5+E\"",
    "vary": "Accept-Encoding",
    "cf-ray": "874b8ce94c0439e8-FRA",
    "server": "cloudflare",
    "connection": "close",
    "set-cookie": "__cf_bm=UUsvO0a6rzGpxs3z4Pzwh3uye_XIgfkmK_tPLjPZ7Nc-1713180069-1.0.1.1-6pTxTeqUS0cgUoh8LZ7vUpngyWbyFLbdqBLlznfaLnc48PSI0yzTyILf6qC0_elbulhWk6_N5Qc_xRWzeI7kXg; path=/; expires=Mon, 15-Apr-24 11:51:09 GMT; domain=.notion.com; HttpOnly; Secure; SameSite=None",
    "content-type": "application/json; charset=utf-8",
    "x-powered-by": "Express",
    "cf-cache-status": "DYNAMIC",
    "transfer-encoding": "chunked",
    "x-notion-request-id": "24e8c59f-5233-4291-b543-e2c39595b4fb"
  }
}

Ok, thanks to the advice from @Gio on another thread, I gave ChatGPT a go, seeing if that could help! And it DID, up until a point :grin:.

Firstly, here is the whole flow overview:

The Challenge:
The data that ActivePieces receives from Tally is fine until it’s a multiple choice, or dropdown, multi-select, etc. Then the ‘value’ data from tally shows up as an ID rather than text.

ChatGPT suggested using a data mapper, which I did…but we got stuck here. Here is the code that ChatGPT gave me, which gives incorrect output in the mapper:

{
  "BLOCKS": "{{data.fields.find(f => f.label === 'What's blocking you from overcoming your big challenge(s)? ').value.map(id => mapping[id]).join(', ')}}",
  "mapping": {
    "06191923-6283-4d99-83ef-b4f2c78bbeab": "Procrastination",
    "0a1e14ed-d565-4215-af62-3c38896a29c2": "Relationships",
    "1625e30e-cd79-4137-ae73-3af7d5a7a5e9": "Lack of Clarity",
    "28a45ecd-a8ff-4dd1-8ba7-820a275834d2": "1-5 years",
    "341b80a0-ad85-4568-81c2-7576722a3dc8": "Coffee Chat Booked",
    "3e70629a-ec1d-4edb-8b3b-275cbc18bd62": "0-6 months",
    "42c53e5e-aba1-40fd-9c66-3becc139b1f6": "Fear of what others think",
    "6749adc1-0a79-42f0-9a93-54c03161b927": "Health & Wellness",
    "921e3169-50ae-458b-a98d-20654f63bc7c": "Self Doubt",
    "95f913de-1941-4ee6-b1ae-8d86ce488a08": "Other",
    "9e7d68a6-0936-4580-a848-4a68aa77e229": "Money",
    "bc706b9f-d573-49bf-bdfe-c02c361c18aa": "Other block(s)",
    "d452b265-f2d4-4fc6-9de8-01c0673f10ef": "More than 5 years",
    "e82a87ce-0462-4ad4-8d5c-d4a17bc5aa12": "6 months to 1 year",
    "f5f09540-c06f-4dbc-b852-d5a316e7643b": "Wealth/Abundance"
  },
  "Client Status": "{{mapping[data.fields.find(f => f.label === 'Client Status').value]}}",
  "AREAS EFFECTED": "{{data.fields.find(f => f.label === 'What area(s) of your life does it effect?').value.map(id => mapping[id]).join(', ')}}",
  "How long have you been feeling this way for?": "{{mapping[data.fields.find(f => f.label === 'How long have you had this challenge for?').value]}}"
}

And here was the output in Mapper:

{
  "BLOCKS": "",
  "mapping": {
    "06191923-6283-4d99-83ef-b4f2c78bbeab": "Procrastination",
    "0a1e14ed-d565-4215-af62-3c38896a29c2": "Relationships",
    "1625e30e-cd79-4137-ae73-3af7d5a7a5e9": "Lack of Clarity",
    "28a45ecd-a8ff-4dd1-8ba7-820a275834d2": "1-5 years",
    "341b80a0-ad85-4568-81c2-7576722a3dc8": "Coffee Chat Booked",
    "3e70629a-ec1d-4edb-8b3b-275cbc18bd62": "0-6 months",
    "42c53e5e-aba1-40fd-9c66-3becc139b1f6": "Fear of what others think",
    "6749adc1-0a79-42f0-9a93-54c03161b927": "Health & Wellness",
    "921e3169-50ae-458b-a98d-20654f63bc7c": "Self Doubt",
    "95f913de-1941-4ee6-b1ae-8d86ce488a08": "Other",
    "9e7d68a6-0936-4580-a848-4a68aa77e229": "Money",
    "bc706b9f-d573-49bf-bdfe-c02c361c18aa": "Other block(s)",
    "d452b265-f2d4-4fc6-9de8-01c0673f10ef": "More than 5 years",
    "e82a87ce-0462-4ad4-8d5c-d4a17bc5aa12": "6 months to 1 year",
    "f5f09540-c06f-4dbc-b852-d5a316e7643b": "Wealth/Abundance"
  },
  "Client Status": "",
  "AREAS EFFECTED": "",
  "How long have you been feeling this way for?": ""
}

As you can see, the Client Status, etc is empty.

At this point, after trying lots of things, ChatGPT said this:
"Given the persistent issues and the feedback from your tests, it seems clear that the approach to dynamically reference and apply the mapping object within the JSON configuration is not working as expected in Activepieces. This may be due to limitations in how Activepieces handles dynamic data referencing, or perhaps there’s a specific method required that isn’t being covered in our current approach.

It might be worth reaching out directly to Activepieces support for guidance:

  • Specific Features: Ask specifically how to handle dynamic data transformations or if there are any particular methods or tools within Activepieces that you should use.
  • Examples and Templates: Request examples or templates that achieve similar data handling goals.

Any support welcome, please team :pray:

Hello @nathanmaingard ,

The second step will return a results field, which is empty in your response because there is no record matching the email (provided in the first step) in the Notion database. We can use this field to set a branch condition. If you test this step with an existing email, it will return a result with an ID.

You can use this ID in the branch step. If the results contain the ID, that means the record exists, and it will return True.

1 Like

Great, that seemed to work for the branch, thank you!

Any suggestions on the last post I made about converting the tally ID values into something that Notion can read in multi-select properties, etc?

Thanks again!

Could you please share a sample tally form response with multi-select properties? It will be easier to create a mapping for Notion fields from them.

I think this is what you mean :grin:



Thanks for the response, Can you provide sample response from tally step as shown in image?

Ah, that makes sense :grin:.

{
  "data": {
    "fields": [
      {
        "key": "question_3y5yRp",
        "type": "CHECKBOXES",
        "label": "Connection type",
        "value": [
          "2c13b5cf-6cbf-4f38-aae8-55e34cf35d24"
        ],
        "options": [
          {
            "id": "2c13b5cf-6cbf-4f38-aae8-55e34cf35d24",
            "text": "Coaching Client"
          }
        ]
      },
      {
        "key": "question_3y5yRp_2c13b5cf-6cbf-4f38-aae8-55e34cf35d24",
        "type": "CHECKBOXES",
        "label": "Connection type (Coaching Client)",
        "value": true
      },
      {
        "key": "question_mD6Jxq",
        "type": "MULTIPLE_CHOICE",
        "label": "Client Status",
        "value": "341b80a0-ad85-4568-81c2-7576722a3dc8",
        "options": [
          {
            "id": "341b80a0-ad85-4568-81c2-7576722a3dc8",
            "text": "Coffee Chat Booked"
          }
        ]
      },
      {
        "key": "question_w4VkLr",
        "type": "INPUT_TEXT",
        "label": "First Name",
        "value": "FnameUpdate"
      },
      {
        "key": "question_3jAMLQ",
        "type": "INPUT_TEXT",
        "label": "Last Name",
        "value": "LnameUpdate"
      },
      {
        "key": "question_mJvRGJ_07473bc3-bea5-4e7c-93d6-4293191e6e09",
        "type": "CALCULATED_FIELDS",
        "label": "Full Name",
        "value": "FnameUpdate LnameUpdate"
      },
      {
        "key": "question_w2GkLe",
        "type": "INPUT_EMAIL",
        "label": "Email",
        "value": "natemain@gmail.com"
      },
      {
        "key": "question_wdeQMo",
        "type": "INPUT_LINK",
        "label": "Instagram Profile",
        "value": "https://instagram.com/IGupdate"
      },
      {
        "key": "question_mVRVrM",
        "type": "TEXTAREA",
        "label": "In your own words, what is your biggest challenge?",
        "value": "Biggest challenge own words update"
      },
      {
        "key": "question_mRyJbd",
        "type": "MULTIPLE_CHOICE",
        "label": "How long have you had this challenge for?",
        "value": "d452b265-f2d4-4fc6-9de8-01c0673f10ef",
        "options": [
          {
            "id": "3e70629a-ec1d-4edb-8b3b-275cbc18bd62",
            "text": "0-6 months"
          },
          {
            "id": "e82a87ce-0462-4ad4-8d5c-d4a17bc5aa12",
            "text": "6 months to 1 year"
          },
          {
            "id": "28a45ecd-a8ff-4dd1-8ba7-820a275834d2",
            "text": "1-5 years"
          },
          {
            "id": "d452b265-f2d4-4fc6-9de8-01c0673f10ef",
            "text": "More than 5 years"
          }
        ]
      },
      {
        "key": "question_wa8bq9",
        "type": "CHECKBOXES",
        "label": "What area(s) of your life does it effect?",
        "value": [
          "0a1e14ed-d565-4215-af62-3c38896a29c2",
          "95f913de-1941-4ee6-b1ae-8d86ce488a08"
        ],
        "options": [
          {
            "id": "0a1e14ed-d565-4215-af62-3c38896a29c2",
            "text": "Relationships"
          },
          {
            "id": "6749adc1-0a79-42f0-9a93-54c03161b927",
            "text": "Health & Wellness"
          },
          {
            "id": "f5f09540-c06f-4dbc-b852-d5a316e7643b",
            "text": "Wealth/Abundance"
          },
          {
            "id": "95f913de-1941-4ee6-b1ae-8d86ce488a08",
            "text": "Other"
          }
        ]
      },
      {
        "key": "question_wa8bq9_0a1e14ed-d565-4215-af62-3c38896a29c2",
        "type": "CHECKBOXES",
        "label": "What area(s) of your life does it effect? (Relationships)",
        "value": true
      },
      {
        "key": "question_wa8bq9_97ed00ce-5978-4a80-8e63-008055958fbb",
        "type": "CHECKBOXES",
        "label": "What area(s) of your life does it effect? (Romantic Partner(s))",
        "value": false
      },
      {
        "key": "question_wa8bq9_6749adc1-0a79-42f0-9a93-54c03161b927",
        "type": "CHECKBOXES",
        "label": "What area(s) of your life does it effect? (Health & Wellness)",
        "value": false
      },
      {
        "key": "question_wa8bq9_f5f09540-c06f-4dbc-b852-d5a316e7643b",
        "type": "CHECKBOXES",
        "label": "What area(s) of your life does it effect? (Wealth/Abundance)",
        "value": false
      },
      {
        "key": "question_wa8bq9_a55f061c-4fc4-4a9a-b09f-e7ba1d74d1d1",
        "type": "CHECKBOXES",
        "label": "What area(s) of your life does it effect? (Other)",
        "value": false
      },
      {
        "key": "question_wa8bq9_8d702feb-e392-4809-b8ac-40e8802e5b95",
        "type": "CHECKBOXES",
        "label": "What area(s) of your life does it effect? (Other)",
        "value": false
      },
      {
        "key": "question_wa8bq9_95f913de-1941-4ee6-b1ae-8d86ce488a08",
        "type": "CHECKBOXES",
        "label": "What area(s) of your life does it effect? (Other)",
        "value": true
      },
      {
        "key": "question_nPMloB",
        "type": "TEXTAREA",
        "label": "In your own words, what other area(s) of your life does this effect, and how?",
        "value": "Other areas effected update"
      },
      {
        "key": "question_obMzVP",
        "type": "LINEAR_SCALE",
        "label": "How clear are you on your life purpose?",
        "value": 1
      },
      {
        "key": "question_wLL52v",
        "type": "CHECKBOXES",
        "label": "What's blocking you from overcoming your big challenge(s)? ",
        "value": [
          "bc706b9f-d573-49bf-bdfe-c02c361c18aa"
        ],
        "options": [
          {
            "id": "42c53e5e-aba1-40fd-9c66-3becc139b1f6",
            "text": "Fear of what others think"
          },
          {
            "id": "06191923-6283-4d99-83ef-b4f2c78bbeab",
            "text": "Procrastination"
          },
          {
            "id": "1625e30e-cd79-4137-ae73-3af7d5a7a5e9",
            "text": "Lack of Clarity"
          },
          {
            "id": "9e7d68a6-0936-4580-a848-4a68aa77e229",
            "text": "Money"
          },
          {
            "id": "921e3169-50ae-458b-a98d-20654f63bc7c",
            "text": "Self Doubt"
          },
          {
            "id": "bc706b9f-d573-49bf-bdfe-c02c361c18aa",
            "text": "Other block(s)"
          }
        ]
      },
      {
        "key": "question_wLL52v_42c53e5e-aba1-40fd-9c66-3becc139b1f6",
        "type": "CHECKBOXES",
        "label": "What's blocking you from overcoming your big challenge(s)?  (Fear of what others think)",
        "value": false
      },
      {
        "key": "question_wLL52v_06191923-6283-4d99-83ef-b4f2c78bbeab",
        "type": "CHECKBOXES",
        "label": "What's blocking you from overcoming your big challenge(s)?  (Procrastination)",
        "value": false
      },
      {
        "key": "question_wLL52v_1625e30e-cd79-4137-ae73-3af7d5a7a5e9",
        "type": "CHECKBOXES",
        "label": "What's blocking you from overcoming your big challenge(s)?  (Lack of Clarity)",
        "value": false
      },
      {
        "key": "question_wLL52v_638b93d2-9ede-4a34-a143-41ed1cd49369",
        "type": "CHECKBOXES",
        "label": "What's blocking you from overcoming your big challenge(s)?  (Other)",
        "value": false
      },
      {
        "key": "question_wLL52v_9e7d68a6-0936-4580-a848-4a68aa77e229",
        "type": "CHECKBOXES",
        "label": "What's blocking you from overcoming your big challenge(s)?  (Money)",
        "value": false
      },
      {
        "key": "question_wLL52v_921e3169-50ae-458b-a98d-20654f63bc7c",
        "type": "CHECKBOXES",
        "label": "What's blocking you from overcoming your big challenge(s)?  (Self Doubt)",
        "value": false
      },
      {
        "key": "question_wLL52v_4e9e9ad1-74b3-429a-bf51-9fd8bbf5295a",
        "type": "CHECKBOXES",
        "label": "What's blocking you from overcoming your big challenge(s)?  (Other)",
        "value": false
      },
      {
        "key": "question_wLL52v_bc706b9f-d573-49bf-bdfe-c02c361c18aa",
        "type": "CHECKBOXES",
        "label": "What's blocking you from overcoming your big challenge(s)?  (Other block(s))",
        "value": true
      },
      {
        "key": "question_3EjLpB",
        "type": "TEXTAREA",
        "label": "What's other blocks are in the way of you overcoming your big challenge(s)?",
        "value": "Other blocks update (only other, no others selected)"
      },
      {
        "key": "question_wMxkzE",
        "type": "TEXTAREA",
        "label": "What might your life look like if you DO overcome your challenge(s)?",
        "value": "Overcome challenge updated"
      },
      {
        "key": "question_mVOl1y",
        "type": "INPUT_TEXT",
        "label": "Type 'YES'' in the box below if you are ready to take the next step",
        "value": "YES"
      }
    ],
    "formId": "wQ1dKY",
    "formName": "Discovery Chat with Nathan",
    "createdAt": "2024-04-24T11:30:40.000Z",
    "responseId": "pRVL8P",
    "respondentId": "bO4VLE",
    "submissionId": "pRVL8P"
  },
  "eventId": "fc7ccf54-c7d1-47a5-bcb6-6e12d47e28e7",
  "createdAt": "2024-04-24T11:30:41.195Z",
  "eventType": "FORM_RESPONSE"
}

Hey again, @kishanprmr !

Thank you again for your patient assistance here. I actually paid someone on Fiverr to help with this, as it was beyond me :sweat_smile:.

With his help, here is the working Flow. I’m concerned that the template shares too much of my info…but I’ve never shared one before, so is it ok?

Would love your thoughts, feedback, or critiques on it if you have time and space to share:
https://cloud.activepieces.com/templates/yLyrD20V0JBMfcbVU6U9O

Thanks again, much appreciation
nathan

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.