Answered

Add email to Typeform logic using zappier

  • 19 March 2024
  • 6 replies
  • 27 views

Hello,

 

I need support with one topic.

 

I am creating a Zap to 'Add email to Typeform logic':

 

 

I have already defined the code to add the info of a New Event in Google Calendar in the JSON of the Typeform form:

 



await fetch("https://api.typeform.com/forms/---------")
    .then((response) => response.json())
    .then((data) => {
        const newCondition = {
            "op": "equal",
            "vars": [{
                    "type": "field",
                    "value": "18495f53-a5f0-4cf1-b8ab-097cfb608e99"
                },
                {
                    "type": "constant",
                    "value": newEmail
                }
            ]
        };

        // Add the new condition to the existing condition as a new "vars" object
        data.logic.forEach(logic => {
            if (logic.type === "field" && logic.ref === "18495f53-a5f0-4cf1-b8ab-097cfb608e99") {
                logic.actions[0].condition.vars.push(newCondition);
            }
        });

        const logic = {
            data
        }
        output = logic;
    });

Then I am pushing this output using a POST API Request in Typeform using API Request (Beta) in Typeform. But when I want to trigger the output, its showing me all data structure divided and obviously I am getting a 405. 

 

What I am trying to achieve is to send a new "logic" object to the form, adding the new condition with the email of the zap (apart from test@test.com):

 

 

icon

Best answer by mathio 26 March 2024, 12:16

View original

6 replies

Userlevel 7
Badge +5

@mathio or @picsoung might be able to help with this!

Userlevel 7
Badge +5

Sorry @Liz I have no experience with Zapier.

Hi @mathio I am trying to create the POST API Request by my own. Can you assist me on defining the endpoint and headers I should use?

Also, the body that I am planning to implement would be this one, do you see any errors?

{
  "logic": [
    {
      "type": "field",
      "ref": "18495f53-a5f0-4cf1-b8ab-097cfb608e99",
      "actions": [
        {
          "action": "jump",
          "details": {
            "to": {
              "type": "field",
              "value": "5dd4b524-4cc6-49e1-b270-183530f128e5"
            }
          },
          "condition": {
            "op": "or",
            "vars": [
              {
                "op": "equal",
                "vars": [
                  {
                    "type": "field",
                    "value": "18495f53-a5f0-4cf1-b8ab-097cfb608e99"
                  },
                  {
                    "type": "constant",
                    "value": "test@test.com"
                  }
                ]
              },
              {
                "op": "equal",
                "vars": [
                  {
                    "type": "field",
                    "value": "18495f53-a5f0-4cf1-b8ab-097cfb608e99"
                  },
                  {
                    "type": "constant",
                    "value": "second@second.com"
                  }
                ]
              },
              {
                "op": "equal",
                "vars": [
                  {
                    "type": "field",
                    "value": "18495f53-a5f0-4cf1-b8ab-097cfb608e99"
                  },
                  {
                    "type": "constant",
                    "value": "NewEmail"
                  }
                ]
              }
            ]
          }
        },
        {
          "action": "jump",
          "details": {
            "to": {
              "type": "thankyou",
              "value": "06634f10-d7b6-48df-8eb3-3f7ff6642119"
            }
          },
          "condition": {
            "op": "always",
            "vars": []
          }
        }
      ]
    }
  ]
}
 

Userlevel 7
Badge +5

]It is a bit hard to check your logic while I do not see the rest of the form, as refs in logic must match existing field refs

Error 405 means “method not allowed”. I see you are using method POST instead of PUT. Maybe that is your issue?

 

 

Trying to replicate the issue

Note: I think you can ignore this section, but below are the steps I used when trying to replicate the issue. At the time I overlooked the issue was with using incorrect method (POST instead of PUT). I am keeping it below anyway, in case someone has issues with creating logic via API.

 

I tried to replicate your approach. I created a form like this: https://form.typeform.com/to/UUEKzlC2 (via admin UI).

 

It returns a response like this when I fetch its definition from API:

{
"id": "UUEKzlC2",
"type": "quiz",
"title": "create logic via API",
"workspace": {
"href": "https://api.typeform.com/workspaces/U3zP9Z"
},
"theme": {
"href": "https://api.typeform.com/themes/qHWOQ7"
},
"settings": {
"language": "en",
"progress_bar": "proportion",
"meta": {
"allow_indexing": false
},
"hide_navigation": false,
"is_public": true,
"is_trial": false,
"show_progress_bar": true,
"show_typeform_branding": true,
"are_uploads_public": false,
"show_time_to_complete": true,
"show_number_of_submissions": false,
"show_cookie_consent": false,
"show_question_number": true,
"show_key_hint_on_choices": true,
"autosave_progress": true,
"free_form_navigation": false,
"use_lead_qualification": false,
"pro_subdomain_enabled": false,
"capabilities": {
"e2e_encryption": {
"enabled": false,
"modifiable": false
}
}
},
"thankyou_screens": [
{
"id": "A3B1QaiUc7rV",
"ref": "default-thank-you",
"title": "Thank you",
"type": "thankyou_screen",
"properties": {
"show_button": true,
"share_icons": true,
"button_mode": "default_redirect",
"button_text": "Create a typeform"
}
},
{
"id": "DefaultTyScreen",
"ref": "default_tys",
"title": "Thanks for completing this typeform\nNow *create your own* — it's free, easy, & beautiful",
"type": "thankyou_screen",
"properties": {
"show_button": true,
"share_icons": false,
"button_mode": "default_redirect",
"button_text": "Create a *typeform*"
},
"attachment": {
"type": "image",
"href": "https://images.typeform.com/images/2dpnUBBkz2VN"
}
}
],
"fields": [
{
"id": "bJty439GZPE2",
"title": "What is your email?",
"ref": "email-input-ref",
"properties": {
"description": "We already know some emails and will redirect you accordingly."
},
"validations": {
"required": false
},
"type": "email"
},
{
"id": "PK6LtdkC45lY",
"title": "We already know you email!",
"ref": "known-statement-ref",
"properties": {
"button_text": "Continue",
"hide_marks": false
},
"type": "statement"
}
],
"_links": {
"display": "https://lednicky.typeform.com/to/UUEKzlC2",
"responses": "https://api.typeform.com/forms/UUEKzlC2/responses"
}
}

I has:

  • email input field with ref email-input-ref
  • a field with ref known-statement-ref (to be displayed based on logic)
  • thank you screen with ref default-thank-you

 

Then, using the PUT endpoint I updated the form by adding a logic to the payload. The full payload to update the form looks like this:

{
"id": "UUEKzlC2",
"type": "quiz",
"title": "create logic via API",
"workspace": {
"href": "https://api.typeform.com/workspaces/U3zP9Z"
},
"theme": {
"href": "https://api.typeform.com/themes/qHWOQ7"
},
"settings": {
"language": "en",
"progress_bar": "proportion",
"meta": {
"allow_indexing": false
},
"hide_navigation": false,
"is_public": true,
"is_trial": false,
"show_progress_bar": true,
"show_typeform_branding": true,
"are_uploads_public": false,
"show_time_to_complete": true,
"show_number_of_submissions": false,
"show_cookie_consent": false,
"show_question_number": true,
"show_key_hint_on_choices": true,
"autosave_progress": true,
"free_form_navigation": false,
"use_lead_qualification": false,
"pro_subdomain_enabled": false,
"capabilities": {
"e2e_encryption": {
"enabled": false,
"modifiable": false
}
}
},
"thankyou_screens": [
{
"id": "A3B1QaiUc7rV",
"ref": "default-thank-you",
"title": "Thank you",
"type": "thankyou_screen",
"properties": {
"show_button": true,
"share_icons": true,
"button_mode": "default_redirect",
"button_text": "Create a typeform"
}
}
],
"fields": [
{
"id": "bJty439GZPE2",
"title": "What is your email?",
"ref": "email-input-ref",
"properties": {
"description": "We already know some emails and will redirect you accordingly."
},
"validations": {
"required": false
},
"type": "email"
},
{
"id": "PK6LtdkC45lY",
"title": "We already know you email!",
"ref": "known-statement-ref",
"properties": {
"button_text": "Continue",
"hide_marks": false
},
"type": "statement"
}
],
"created_at": "2024-03-26T10:50:10+00:00",
"last_updated_at": "2024-03-26T10:57:29+00:00",
"published_at": "2024-03-26T10:52:11+00:00",
"_links": {
"display": "https://lednicky.typeform.com/to/UUEKzlC2",
"responses": "https://api.typeform.com/forms/UUEKzlC2/responses"
},
"logic": [
{
"type": "field",
"ref": "email-input-ref",
"actions": [
{
"action": "jump",
"details": {
"to": {
"type": "field",
"value": "known-statement-ref"
}
},
"condition": {
"op": "or",
"vars": [
{
"op": "equal",
"vars": [
{
"type": "field",
"value": "email-input-ref"
},
{
"type": "constant",
"value": "test@test.com"
}
]
},
{
"op": "equal",
"vars": [
{
"type": "field",
"value": "email-input-ref"
},
{
"type": "constant",
"value": "second@second.com"
}
]
},
{
"op": "equal",
"vars": [
{
"type": "field",
"value": "email-input-ref"
},
{
"type": "constant",
"value": "NewEmail"
}
]
}
]
}
},
{
"action": "jump",
"details": {
"to": {
"type": "thankyou",
"value": "default-thank-you2"
}
},
"condition": {
"op": "always",
"vars": []
}
}
]
}
]
}

 

This way I was able to add logic to the form like this:

  • if email is one of test@test.com, second@second.com, or NewEmail
    • go to “We already know your email”
  • for all other cases
    • go to “Thank you”

This is what I see after I refresh my admin UI:

 

Hi @mathio , thanks so much for your help! I’ve successfully added the PUT call using Zapier and the logic got updated accordingly.

However, this is not what I was trying to do, let me explain.

I want to add a new email in the condition logic everytime a user answers the form, so if that same user uses the form for the second time, I can redirect him to a specific step. Therefore, I can not use a PUT call with the same JSON everytime. I have to somehow add a new logic on top of the existing logic, and I dont know how to do it with PUT or POST.

I would need to do a GET and after a PUT + new email logic? Or theres any easier way?

Userlevel 7
Badge +5

I am afraid in this case you would need to do GET to retrieve current form definition, then update the logic part and make PUT request to update this. You can not update logic without sending the whole definition.

Reply