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 receives a trigger from your Mailchimp account.
- The test will be successful, if Integry 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.obj.contact_v1.custom_fields.FNAME}
last_name = {steps.mailchimp_subscriber_created.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
return
key word is used to return 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" in front of FNAME to add its value to your code. Learn how to add dynamic tags here.
- Complete your code body.
- Click the "Add Step" button.
- 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.
- Click on the '+' button in the far right of the First Name field and then click "Code App."
- Click "Add to Fields" in front of the the 'Out' object. 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.
- 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.
- Select the List in HubSpot to which you want the contact to be added and click Continue.
- Click Test.
- Save and publish your flow.
- When you set up an integration against this flow, a contact will be created in HubSpot with first name as the concatenation of first and last name from the Mailchimp contact.
- 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.