Code enables you to extend your integration's functionality. You can add Python code in the code step to apply any logic to your flow.
We will 'Create a contact in HubSpot when a subscriber is created in Mailchimp.' Let's say HubSpot needs a combination of first name and last name in the first name field. We'll add custom code to concatenate the first and last name of the subscriber created in Mailchimp.
- Go to the Flows tab from the top menu.
- Create a new flow.
- Add a trigger "Subscriber Created" in Mailchimp.
- Connect your Mailchimp account.
- If you don't have one, you can sign up for free.
- If you don't have one, you can sign up for free.
- Select the Audience you want to add the subscriber to and click Continue.
- Click Test.
- The test will be successful, if Integry successfully receives a trigger from your Mailchimp account.
- The test will be successful, if Integry successfully receives a trigger from your Mailchimp account.
- Search and select "Code" in the child step.
- A code editor will open up where you can write your custom code. For this example, we'll write the following code:
import json
first_name = {steps.mailchimp_subscriber_created_2.obj.contact_v1.custom_fields.FNAME}
last_name = {steps.mailchimp_subscriber_created_2.obj.contact_v1.custom_fields.LNAME}
code_app_output = first_name + ' ' + last_name- In the first line, we're importing the
json
module. - The next line creates a string variable called
first_name
and assigns it a string value of the object stored insteps.mailchimp_subscriber_created.obj.contact_v1.custom_fields.FNAME
- The next line creates a string variable called
last_name
and assigns it a string value of the object stored insteps.mailchimp_subscriber_created.obj.contact_v1.custom_fields.LNAME
- Finally, the
code_app_output
variable is assigned the result of the concatenation of the two variables,first_name,
andlast_name
- In the first line, we're importing the
- If you want to use values from the trigger in your code, add dynamic tags to access those values.
- Click the '+' on the top right corner of the code editor.
- Click on 'Subscriber Created.'
- Expand the output object "Obj" by clicking the index.
- Expand "contact_v1", which is the actual contact received in the trigger.
- Expand "custom_fields."
- Click "Add to Field" if you want to add a field and its value to your code. A tag for your selected field will be added to your code body.
- Complete your code body.
- Click on the three-dots menu on the far right and click Add Step.
- Add an action, "Create Contact" in HubSpot.
- Connect your HubSpot account.
- If you don't have one, you can sign up for free.
- If you don't have one, you can sign up for free.
- Enter Email, First Name, Last Name and additional attributes of HubSpot contact.
14. Click on the '+' sign in the far right of the field to which you want to add the output of code and then click Code App.
15. Click "Add to Fields." The output of code will be added as a tag to the First Name field. The first name of a contact created in HubSpot will be saved as the concatenation of the first, and last name of the Mailchimp subscriber.
16. You can continue to add more steps to your flow or save and publish your flow on a marketplace.
Comments
0 comments
Please sign in to leave a comment.