This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Deal Creation in Hubspot

The first use case in the Hubspot business scenario is deal creation. This page describes the relevant tasks and the operations you use in the Hubspot connector and the other ESB connectors. It contains the following sections:

Overview

The flow for deal creation is illustrated in the following diagram. The ESB connectors for ActiveCampaign and 123ContactForm will be used to connect to each service.

Creating campaigns, sending campaigns and creating a contact list

  1. Create an E-mail message in the ActiveCampaign API using the createMessage operation.
  2. Create a campaign in the ActiveCampaign API and send it using the createCampaign operation.
  3. Create a contact list associated to the campaign using the createMailingList operation in the ActiveCampaign API.
ActiveCampaign operations
Samples
Sample Proxy for creating and sending campaigns using ActiveCampaign and creating a contact list associated to the campaign in ActiveCampaign
<?xml version="1.0" encoding="UTF-8"?>
<!--
   Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
   WSO2 Inc. licenses this file to you under the Apache License,
   Version 2.0 (the "License"); you may not use this file except
   in compliance with the License.
   You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied. See the License for the
   specific language governing permissions and limitations
   under the License.
-->
<!-- Create a campaign and mailing list in ActiveCampaign API. -->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="hubSpot_createCampaignAndMailingList" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <!-- ActiveCampaign parameters. -->
         <property name="activeCampaign.apiUrl" expression="json-eval($.activeCampaign.apiUrl)" />
         <property name="activeCampaign.apiKey" expression="json-eval($.activeCampaign.apiKey)" />
         <property name="activeCampaign.campaign.format" expression="json-eval($.activeCampaign.campaign.format)" />
         <property name="activeCampaign.campaign.fromEmail" expression="json-eval($.activeCampaign.campaign.fromEmail)" />
         <property name="activeCampaign.campaign.fromName" expression="json-eval($.activeCampaign.campaign.fromName)" />
         <property name="activeCampaign.campaign.replyTo" expression="json-eval($.activeCampaign.campaign.replyTo)" />
         <property name="activeCampaign.campaign.listId" expression="json-eval($.activeCampaign.campaign.listId)" />
         <property name="activeCampaign.campaign.type" expression="json-eval($.activeCampaign.campaign.type)" />
         <property name="activeCampaign.campaign.name" expression="json-eval($.activeCampaign.campaign.name)" />
         <property name="activeCampaign.campaign.subject" expression="json-eval($.activeCampaign.campaign.subject)" />
         <property name="activeCampaign.campaign.emailTextContent" expression="json-eval($.activeCampaign.campaign.emailTextContent)" />
         <property name="activeCampaign.campaign.priority" expression="json-eval($.activeCampaign.campaign.priority)" />
         <property name="activeCampaign.campaign.charset" expression="json-eval($.activeCampaign.campaign.charset)" />
         <property name="activeCampaign.campaign.encoding" expression="json-eval($.activeCampaign.campaign.encoding)" />
         <property name="activeCampaign.campaign.htmlConstructor" expression="json-eval($.activeCampaign.campaign.htmlConstructor)" />
         <property name="activeCampaign.campaign.html" expression="json-eval($.activeCampaign.campaign.html)" />
         <property name="activeCampaign.campaign.htmlFetch" expression="json-eval($.activeCampaign.campaign.htmlFetch)" />
         <property name="activeCampaign.campaign.htmlFetchWhen" expression="json-eval($.activeCampaign.campaign.htmlFetchWhen)" />
         <property name="activeCampaign.campaign.textFetch" expression="json-eval($.activeCampaign.campaign.textFetch)" />
         <property name="activeCampaign.campaign.textFetchWhen" expression="json-eval($.activeCampaign.campaign.textFetchWhen)" />
         <property name="activeCampaign.campaign.isPublic" expression="json-eval($.activeCampaign.campaign.isPublic)" />
         <property name="activeCampaign.campaign.trackLinks" expression="json-eval($.activeCampaign.campaign.trackLinks)" />
         <property name="activeCampaign.mailingList.toName" expression="json-eval($.activeCampaign.mailingList.toName)" />
         <property name="activeCampaign.mailingList.senderAddr1" expression="json-eval($.activeCampaign.mailingList.senderAddress)" />
         <property name="activeCampaign.mailingList.senderZip" expression="json-eval($.activeCampaign.mailingList.senderZip)" />
         <property name="activeCampaign.mailingList.subscriptionNotifyList" expression="json-eval($.activeCampaign.mailingList.subscriptionNotifyList)" />
         <property name="activeCampaign.mailingList.senderCountry" expression="json-eval($.activeCampaign.mailingList.senderCountry)" />
         <property name="activeCampaign.mailingList.senderName" expression="json-eval($.activeCampaign.mailingList.senderName)" />
         <property name="activeCampaign.mailingList.unsubscriptionNotifyList" expression="json-eval($.activeCampaign.mailingList.unsubscriptionNotifyList)" />
         <property name="activeCampaign.mailingList.senderCity" expression="json-eval($.activeCampaign.mailingList.senderCity)" />
         <property name="activeCampaign.mailingList.senderUrl" expression="json-eval($.activeCampaign.mailingList.senderUrl)" />
         <property name="activeCampaign.mailingList.carbonCopyList" expression="json-eval($.activeCampaign.mailingList.carbonCopyList)" />
         <property name="activeCampaign.mailingList.bounceId" expression="json-eval($.activeCampaign.mailingList.bounceId)" />
         <property name="activeCampaign.mailingList.senderReminder" expression="json-eval($.activeCampaign.mailingList.senderReminder)" />
         <property name="activeCampaign.mailingList.stringId" expression="json-eval($.activeCampaign.mailingList.stringId)" />
         <script language="js">
         <![CDATA[                     
            var listId = "" + mc.getProperty("activeCampaign.campaign.listId");  
            var payload = {};  
            payload ["p[" +listId+"]"] = listId;           
            mc.setPayloadJSON(payload);    
         ]]>
         </script>
         <property name="activeCampaign.campaign.listDetails" expression="json-eval($.)" />
         <!-- Create Email message. -->
         <activecampaign.init>
            <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
            <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
            <apiOutput>json</apiOutput>
         </activecampaign.init>
         <activecampaign.createMessage>
            <format>{$ctx:activeCampaign.campaign.format}</format>
            <subject>{$ctx:activeCampaign.campaign.subject}</subject>
            <fromEmail>{$ctx:activeCampaign.campaign.fromEmail}</fromEmail>
            <fromName>{$ctx:activeCampaign.campaign.fromName}</fromName>
            <replyTo>{$ctx:activeCampaign.campaign.replyTo}</replyTo>
            <priority>{$ctx:activeCampaign.campaign.priority}</priority>
            <charset>{$ctx:activeCampaign.campaign.charset}</charset>
            <encoding>{$ctx:activeCampaign.campaign.encoding}</encoding>
            <htmlConstructor>{$ctx:activeCampaign.campaign.htmlConstructor}</htmlConstructor>
            <html>{$ctx:activeCampaign.campaign.html}</html>
            <htmlFetch>{$ctx:activeCampaign.campaign.htmlFetch}</htmlFetch>
            <htmlFetchWhen>{$ctx:activeCampaign.campaign.htmlFetchWhen}</htmlFetchWhen>
            <textConstructor>editor</textConstructor>
            <text>{$ctx:activeCampaign.campaign.emailTextContent}</text>
            <textFetch>{$ctx:activeCampaign.campaign.textFetch}</textFetch>
            <textFetchWhen>{$ctx:activeCampaign.campaign.textFetchWhen}</textFetchWhen>
            <listIds>{$ctx:activeCampaign.campaign.listDetails}</listIds>
         </activecampaign.createMessage>
         <property name="activeCampaign.message.id" expression="//jsonObject/id/text()" />
         <property name="activeCamapign.result.code" expression="//jsonObject/result_code/text()" />
         <!-- Check Email message created. -->
         <filter xpath="get-property('activeCamapign.result.code') = 0">
            <then>
               <property name="id" value="{}" />
               <property name="status" value="error" />
               <property name="message" expression="//jsonObject/result_message/text()" />
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="activeCampaign_createMessage" />
                  <with-param name="id" value="{$ctx:id}" />
                  <with-param name="status" value="{$ctx:status}" />
                  <with-param name="message" value="{$ctx:message}" />
               </call-template>
               <loopback />
            </then>
         </filter>

         <script language="js">
         <![CDATA[         
            //Construct message and list deatils.
            
            var messageId = mc.getProperty("activeCampaign.message.id");
            var listDetails = mc.getProperty("activeCampaign.campaign.listDetails");     
            var payload = eval('(' + listDetails + ')');  
            payload ["m[" +messageId+"]"] = "100";           
            mc.setPayloadJSON(payload);    
         ]]>
         </script>
         <property name="activeCampaign.campaign.listDetails" expression="json-eval($.)" />
         <property name="activeCampaign.campaign.sendDate" expression="get-property('SYSTEM_DATE', 'yyyy-MM-dd HH:mm:ss')" />
         <!-- Workaround to eliminate the Host header issue in ActiveCampaign. -->
         <property name="Host" value="host.wso2.com" scope="transport" />
         <!-- Create campaign. -->
         <activecampaign.init>
            <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
            <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
            <apiOutput>json</apiOutput>
         </activecampaign.init>
         <activecampaign.createCampaign>
            <type>{$ctx:activeCampaign.campaign.type}</type>
            <name>{$ctx:activeCampaign.campaign.name}</name>
            <sdate>{$ctx:activeCampaign.campaign.sendDate}</sdate>
            <isStatusScheduled>1</isStatusScheduled>
            <isPublic>{$ctx:activeCampaign.campaign.isPublic}</isPublic>
            <trackLinks>{$ctx:activeCampaign.campaign.trackLinks}</trackLinks>
            <listDetails>{$ctx:activeCampaign.campaign.listDetails}</listDetails>
         </activecampaign.createCampaign>
         <property name="activeCamapign.result.code" expression="//jsonObject/result_code/text()" />
         <!-- Check Email message created. -->
         <filter xpath="get-property('activeCamapign.result.code') = 0">
            <then>
               <property name="id" value="{}" />
               <property name="status" value="error" />
               <property name="message" expression="//jsonObject/result_message/text()" />
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="activeCampaign_createMessage" />
                  <with-param name="id" value="{$ctx:id}" />
                  <with-param name="status" value="{$ctx:status}" />
                  <with-param name="message" value="{$ctx:message}" />
               </call-template>
               <loopback />
            </then>
         </filter>

         <property name="activeCampaign.campaign.id" expression="//jsonObject/id/text()" />
         <property name="id" expression="fn:concat('activeCampaign_campaignId:', get-property('activeCampaign.campaign.id'))" />
         <call-template target="responseHandlerTemplate">
            <with-param name="activity" value="activeCampaign_createCampaign" />
            <with-param name="id" value="{$ctx:id}" />
            <with-param name="status" value="success" />
            <with-param name="message" value="Campaign has been successfully created." />
         </call-template>
         <!-- Workaround to eliminate the Host header issue in ActiveCampaign. -->
         <property name="Host" value="host.wso2.com" scope="transport" />
         <!-- Create mailing List. -->
         <activecampaign.init>
            <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
            <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
            <apiOutput>json</apiOutput>
         </activecampaign.init>
         <activecampaign.createMailingList>
            <toName>{$ctx:activeCampaign.mailingList.toName}</toName>
            <senderAddr1>{$ctx:activeCampaign.mailingList.senderAddr1}</senderAddr1>
            <senderZip>{$ctx:activeCampaign.mailingList.senderZip}</senderZip>
            <subscriptionNotifyList>{$ctx:activeCampaign.mailingList.subscriptionNotifyList}</subscriptionNotifyList>
            <senderCountry>{$ctx:activeCampaign.mailingList.senderCountry}</senderCountry>
            <senderName>{$ctx:activeCampaign.mailingList.senderName}</senderName>
            <unsubscriptionNotifyList>{$ctx:activeCampaign.mailingList.unsubscriptionNotifyList}</unsubscriptionNotifyList>
            <senderCity>{$ctx:activeCampaign.mailingList.senderCity}</senderCity>
            <name>{$ctx:activeCampaign.name}</name>
            <senderUrl>{$ctx:activeCampaign.mailingList.senderUrl}</senderUrl>
            <carbonCopyList>{$ctx:activeCampaign.mailingList.carbonCopyList}</carbonCopyList>
            <bounceId>{$ctx:activeCampaign.mailingList.bounceId}</bounceId>
            <senderReminder>{$ctx:activeCampaign.mailingList.senderReminder}</senderReminder>
            <stringId>{$ctx:activeCampaign.mailingList.stringId}</stringId>
         </activecampaign.createMailingList>
         <property name="activeCamapign.result.code" expression="//jsonObject/result_code/text()" />
         <!-- Check MailingList is created. -->
         <filter xpath="get-property('activeCamapign.result.code') = 0">
            <then>
               <property name="id" value="{}" />
               <property name="status" value="error" />
               <property name="message" expression="//jsonObject/result_message/text()" />
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="activeCampaign_createMailingList" />
                  <with-param name="id" value="{$ctx:id}" />
                  <with-param name="status" value="{$ctx:status}" />
                  <with-param name="message" value="{$ctx:message}" />
               </call-template>
               <loopback />
            </then>
         </filter>
         <property name="activeCampaignListId" expression="//jsonObject/id/text()" />
         <property name="id" expression="fn:concat('activeCampaign_listId:', get-property('activeCampaignListId'))" />
         <call-template target="responseHandlerTemplate">
            <with-param name="activity" value="activeCampaign_createMailingList" />
            <with-param name="id" value="{$ctx:id}" />
            <with-param name="status" value="success" />
            <with-param name="message" value="Mailing list has been successfully created." />
         </call-template>
         <loopback />
      </inSequence>
      <outSequence>
         <payloadFactory media-type="json">
            <format>{ "Response":{ "process":"hubSpot_createCampaignAndMailingList", "activityResponse":[$1] } }
            </format>
            <args>
               <arg expression="get-property('operation','responseString')" />
            </args>
         </payloadFactory>
         <property name="messageType" value="application/json" scope="axis2" />
         <send />
      </outSequence>
   </target>
   <description />
</proxy>
Sample Request for creating and sending campaigns using ActiveCampaign and creating a contact list associated to the campaign in ActiveCampaign
{
  "activeCampaign": {
    "apiUrl": "https://dilanilaj.api-us1.com",
    "apiKey": "f81ff28823532452d6e5caf080d516fec3d5385c0983f618913e90753e0d456d91ea2561",
    "campaign": {
      "fromEmail": "testapp.mahesh2@gmail.com",
      "fromName": "Admin",
      "format": "text",
      "replyTo": "testapp.mahesh2@gmail.com",
      "priority": "1",
      "charset": "utf-8",
      "encoding": "quoted-printable",
      "htmlConstructor": "editor",
      "html": "HTML Content",
      "htmlFetch": "https://www.google.lk/admin.html",
      "htmlFetchWhen": "pers",
      "textFetch": "https://www.google.lk/admin.txt",
      "textFetchWhen": "pers",
      "listId": "2",
      "type": "single",
      "name": "World Cup Campaign",
      "isPublic": "1",
      "trackLinks": "all",
      "subject": "Fifa world cup",
      "emailTextContent": "Fifa will held on 2015-06-12"
    },
    "mailingList": {
      "toName": "recepient",
      "senderAddress": "Kandy Rd",
      "senderZip": "94",
      "subscriptionNotifyList": "testapp.mahesh@gmail.com",
      "senderCountry": "Sri Lanka",
      "senderName": "WSO2",
      "unsubscriptionNotifyList": "testapp.mahesh@gmail.com",
      "senderCity": "Colombo",
      "senderUrl": "https://www.google.lk",
      "carbonCopyList": "testapp.mahesh@gmail.com",
      "bounceId": "testapp.mahesh@gmail.com",
      "senderReminder": "Send",
      "stringId": "worldcup"
    }
  }
}

Note

 The following are the parameter descriptions:

  • activeCampaign.campaign.format: Format of the campaign message.
  • activeCampaign.campaign.fromEmail: E-mail address from which the campaign message is sent from.
  • activeCampaign.campaign.fromName: Name from which the campaign message is sent from.
  • activeCampaign.campaign.replyTo: E-mail address for the campaign message to reply.
  • activeCampaign.campaign.listId: Mailing list ID which the campaign is sent to.
  • activeCampaign.campaign.type: Type of the campaign.
  • activeCampaign.campaign.name: Name of the campaign.
  • activeCampaign.campaign.subject: Subject for the campaign message.
  • activeCampaign.campaign.emailTextContent: Text content for the campaign message.
  • activeCampaign.campaign.priority: Priority of the campaign message.
  • activeCampaign.campaign.charset: Charset of the campaign message.
  • activeCampaign.campaign.encoding: Encoding used to the campaign message.
  • activeCampaign.campaign.htmlConstructor: HTML version of the campaign message.
  • activeCampaign.campaign.html: HTML version content of the campaign message.
  • activeCampaign.campaign.htmlFetch: URL to fetch the body for the campaign message.
  • activeCampaign.campaign.htmlFetchWhen: When to fetch the HTML body.
  • activeCampaign.campaign.textFetch: URL to fetch the body for the campaign message.
  • activeCampaign.campaign.textFetchWhen: When to fetch the text body.
  • activeCampaign.campaign.isPublic: Visibility of the campaign.
  • activeCampaign.campaign.trackLinks: Types of the links to track.
  • activeCampaign.mailingList.toName: To name for the mailing list.
  • activeCampaign.mailingList.senderAddress: Address of the sender.
  • activeCampaign.mailingList.senderZip: Zip of the sender.
  • activeCampaign.mailingList.subscriptionNotifyList: E-mail addresses to notify new subscriptions for the mailing list.
  • activeCampaign.mailingList.senderCountry: Country of the sender.
  • activeCampaign.mailingList.senderName: Name of the sender.
  • activeCampaign.mailingList.unsubscriptionNotifyList: E-mail addresses to notify unsubscriptions for the mailing list.
  • activeCampaign.mailingList.senderCity : City of the sender.
  • activeCampaign.mailingList.senderUrl: URL of the sender.
  • activeCampaign.mailingList.carbonCopyList: E-mail addresses to send a copy of all mailings to upon send.
  • activeCampaign.mailingList.bounceId: Bounce management accounts.
  • activeCampaign.mailingList.senderReminder: Reminder for the mailing list.
  • activeCampaign.mailingList.stringId: URL safe list name for the mailing list.

Retrieving campaign clickers, form submissions and adding contacts to the list

  1. Retrieve contact lists from the ActiveCampaign API using the listMailingLists operation.
  2. Retrieve the fields of a particular form using the getFields operation in the 123ContactForm API.
  3. Retrieve form submissions (contact details) from the 123ContactForm API using the getFormSubmissions operation.
  4. Retrieve a list of contacts from the ActiveCampaign API using the listContacts operation.
  5. Update the existing contact in the ActiveCampaign API using the updateContact operation.
  6. If the contact does not exist, create the contact in the ActiveCampaign API using the createContact operation.
  7. Retrieve campaigns from the ActiveCampaign API using the listCampaigns operation.
  8. Retrieve campaign clickers from the ActiveCampaign API using the getCampaignClickers operation.
  9. Retrieve contacts from the ActiveCampaign API using the listContacts operation.
  10. Update the contact in the ActiveCampaign API using the updateContact operation.
123ContactForm operations
ActiveCampaign operations
Samples
Sample Proxy for retrieving campaign clickers from ActiveCampaign and form submissions from 123ContactForm and adding them as contacts to the campaign contacts list (contact list named with the campaign name) in ActiveCampaign
<?xml version="1.0" encoding="UTF-8"?>
<!--
   Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
   WSO2 Inc. licenses this file to you under the Apache License,
   Version 2.0 (the "License"); you may not use this file except
   in compliance with the License.
   You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied. See the License for the
   specific language governing permissions and limitations
   under the License.
-->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="hubSpot_addContactsToContactList" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <!-- ActiveCampaign parameters. -->
         <property name="activeCampaign.apiUrl" expression="json-eval($.activeCampaign.apiUrl)" />
         <property name="activeCampaign.apiKey" expression="json-eval($.activeCampaign.apiKey)" />
         <property name="activeCampaign.campaignName" expression="json-eval($.activeCampaign.campaignName)" />
         <property name="activeCampaign.isFull" value="1" />
         <!-- 123Contactform parameters. -->
         <property name="contactform.apiKey" expression="json-eval($.contactForm.apiKey)" />
         <property name="contactform.apiUrl" value="https://www.123contactform.com" />
         <property name="contactform.formId" expression="json-eval($.contactForm.formId)" />
         <!-- Common properties -->
         <property name="output" value="json" />
         <property name="submissionIndex" value="0.0" scope="operation" />
         <property name="clickerIndex" value="0" scope="operation" />
         <property name="noOfSubmissionIds" value="0.0" scope="operation" />
         <property name="emptyID" value="{}" />
         <property name="noOfContactsExist" value="0.0" scope="operation" />
         <property name="noOfFormContactsExist" value="0.0" scope="operation" />
         <!-- Listing contact lists -->
         <activecampaign.init>
            <apiOutput>{$ctx:output}</apiOutput>
            <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
            <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
         </activecampaign.init>
         <activecampaign.listMailingLists>
            <isFull>{$ctx:activeCampaign.isFull}</isFull>
            <nameFilter>{$ctx:activeCampaign.campaignName}</nameFilter>
         </activecampaign.listMailingLists>
         <property name="listMailingListsResultCode" expression="json-eval($.result_code)" />
         <filter xpath="get-property('listMailingListsResultCode') > 0">
            <then>
               <property name="activeCampaign.listId" expression="json-eval($.0.id)" />
               <filter xpath="boolean(get-property('contactform.apiKey'))">
                  <then>
                     <contactform.init>
                        <apiOutput>{$ctx:output}</apiOutput>
                        <apiUrl>{$ctx:contactform.apiUrl}</apiUrl>
                        <apiKey>{$ctx:contactform.apiKey}</apiKey>
                     </contactform.init>
                     <contactform.getFields>
                        <formId>{$ctx:contactform.formId}</formId>
                     </contactform.getFields>
                     <property name="getFieldsError" expression="json-eval($.errorMessage)" />
                     <filter source="boolean(get-property('getFieldsError'))" regex="false">
                        <then>
                           <property name="contactform.fields" expression="json-eval($.fields)" />
                           <script language="js">
                              <![CDATA[
                                 var filedList = eval("(" + mc.getProperty("contactform.fields") +")");
                                 for (var i = 0;i<filedList.length;i++) {
                                    var fieldTitle = "" + filedList[i].fieldTitle;
                                    if(fieldTitle == "Email") {
                                       mc.setProperty("contactform.email.id",filedList[i].fieldId);
                                    } else if(fieldTitle == "First Name") {
                                       mc.setProperty("contactform.firstName.id",filedList[i].fieldId);
                                    } else if(fieldTitle == "Last Name") {
                                       mc.setProperty("contactform.lastName.id",filedList[i].fieldId);
                                    }else if(fieldTitle == "Company") {
                                       mc.setProperty("contactform.company.id",filedList[i].fieldId);
                                    }
                                 }
                              ]]>
                           </script>
                           <contactform.init>
                              <apiOutput>{$ctx:output}</apiOutput>
                              <apiUrl>{$ctx:contactform.apiUrl}</apiUrl>
                              <apiKey>{$ctx:contactform.apiKey}</apiKey>
                           </contactform.init>
                           <contactform.getFormSubmissions>
                              <formId>{$ctx:contactform.formId}</formId>
                           </contactform.getFormSubmissions>
                           <property name="getFormSubmissionsError" expression="json-eval($.errorMessage)" />
                           <filter source="boolean(get-property('getFormSubmissionsError'))" regex="false">
                              <then>
                                 <property name="noOfSubmissionIds" expression="count(//submissions)" scope="operation" />
                                 <filter xpath="get-property('operation','noOfSubmissionIds') > '0'">
                                    <then>

                                       <iterate id="submissionIterator" expression="//submissions" continueParent="true" sequential="true">
                                          <target>
                                             <sequence>
                                                <property name="contcatform.submissions" expression="json-eval($.submissions.fields)" />
                                                <script language="js">
                                                   <![CDATA[       
                                                      var submission =  eval("(" + mc.getProperty("contcatform.submissions") +")");
                                                      var emailId = mc.getProperty('contactform.email.id');
                                                      var firstNameId = mc.getProperty('contactform.firstName.id');
                                                      var lastNameId = mc.getProperty('contactform.lastName.id');
                                                      var companyId = mc.getProperty('contactform.company.id');
                                                      var listId = mc.getProperty('activeCampaign.listId');
                                                      for (var i = 0;i<submission.length;i++) {
                                                         var fieldId = submission[i].fieldid;
                                                         if(fieldId == emailId) {
                                                            mc.setProperty("contactform.email.value",submission[i].fieldvalue);
                                                         } else if(fieldId == firstNameId) {
                                                            mc.setProperty("contactform.firstName.value",submission[i].fieldvalue);
                                                         } else if(fieldId == lastNameId) {
                                                            mc.setProperty("contactform.lastName.value",submission[i].fieldvalue);
                                                         } else if(fieldId == companyId) {
                                                            mc.setProperty("contactform.company.value",submission[i].fieldvalue);
                                                         } 
                        
                                                      }
                                                                                   
                                                       var payload = {};
                                                       var listKey = 'p['+listId+']';
                                                       payload[listKey] = listId;
                                                       var statusKey = 'status['+listId+']';
                                                       payload[statusKey] = 1;
                                                       mc.setPayloadJSON(payload);                         
                                                                                                                                              
                                                   ]]>
                                                </script>
                                                <property name="listDetails" expression="json-eval($.)" />
                                                <property name="Host" value="host.wso2.com" scope="transport" />
                                                <activecampaign.init>
                                                   <apiOutput>{$ctx:output}</apiOutput>
                                                   <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
                                                   <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
                                                </activecampaign.init>
                                                <activecampaign.listContacts>
                                                   <emailFilter>{$ctx:contactform.email.value}</emailFilter>
                                                   <isFull>1</isFull>
                                                </activecampaign.listContacts>
                                                <property name="listContactsResultCode" expression="json-eval($.result_code)" />
                                                <property name="tags" expression="fn:concat('Campaign name:',get-property('activeCampaign.campaignName'),'(123ContactForm)')" />
                                                <filter xpath="get-property('listContactsResultCode') > '0'">
                                                   <then>
                                                      <property name="listLists" expression="json-eval($.0.listslist)" />
                                                      <property name="existingContactListId" expression="json-eval($.0.listid)" />
                                                      <property name="orgName" expression="json-eval($.0.orgname)" />
                                                      <script language="js">
                                                         <![CDATA[  
                                                            var campaignList =  "" + mc.getProperty("activeCampaign.listId") ;     
                                                            var listLists =  "" +  mc.getProperty("listLists") ;
                                                            var existingContactListId =   mc.getProperty("existingContactListId") ;
                                                            if(existingContactListId == campaignList){
                                                               mc.setProperty("listDetails",'');
                                                            }
                                                            else{                                                                                                                       
                                                               var listListsArray = listLists.split("-");
                                                               for (var i = 0;i<listListsArray.length;i++) {  
                                                                  if(listListsArray[i] == campaignList) {
                                                                     mc.setProperty("listDetails",'');
                                                                     break;
                                                                  } 
                                                               } 
                                                            }                                                                               
                                                                                                                                                    
                                                         ]]>
                                                      </script>

                                                      <filter source="boolean(get-property('listDetails'))" regex="false">
                                                         <then>
                                                            <property name="noOfFormContactsExist" expression="get-property('operation','noOfFormContactsExist') + 1" scope="operation" />
                                                         </then>
                                                      </filter>

                                                      <property name="contactId" expression="json-eval($.0.id)" />
                                                      <property name="Host" value="host.wso2.com" scope="transport" />
                                                      <activecampaign.init>
                                                         <apiOutput>{$ctx:output}</apiOutput>
                                                         <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
                                                         <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
                                                      </activecampaign.init>
                                                      <activecampaign.updateContact>
                                                         <contactId>{$ctx:contactId}</contactId>
                                                         <email>{$ctx:contactform.email.value}</email>
                                                         <tags>{$ctx:tags}</tags>
                                                         <listDetails>{$ctx:listDetails}</listDetails>
                                                      </activecampaign.updateContact>
                                                      <property name="updateContactResultCode" expression="json-eval($.result_code)" />
                                                      <filter xpath="get-property('listContactsResultCode') > '0'">
                                                         <then>
                                                            <filter xpath="get-property('listDetails') != ''">
                                                               <then>
                                                                  <property name="id" expression="fn:concat('activeCampaign_contactId:', get-property('contactId'))" />
                                                                  <property name="message" value="Contact has been successfully added to the campaign contact list." />
                                                                  <call-template target="responseHandlerTemplate">
                                                                     <with-param name="id" value="{$ctx:id}" />
                                                                     <with-param name="status" value="success" />
                                                                     <with-param name="activity" value="activeCampaign_updateContact" />
                                                                     <with-param name="message" value="{$ctx:message}" />
                                                                  </call-template>
                                                               </then>
                                                            </filter>
                                                         </then>
                                                         <else>
                                                            <property name="updateContactError" expression="json-eval($.)" />
                                                            <property name="id" expression="fn:concat('activeCampaign_contactId:', get-property('contactId'))" />
                                                            <call-template target="responseHandlerTemplate">
                                                               <with-param name="id" value="{$ctx:id}" />
                                                               <with-param name="status" value="error" />
                                                               <with-param name="activity" value="activeCampaign_updateContact" />
                                                               <with-param name="message" value="{$ctx:updateContactError}" />
                                                            </call-template>
                                                         </else>
                                                      </filter>
                                                   </then>
                                                   <else>
                                                      <property name="Host" value="host.wso2.com" scope="transport" />
                                                      <activecampaign.init>
                                                         <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
                                                         <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
                                                         <apiOutput>{$ctx:output}</apiOutput>
                                                      </activecampaign.init>
                                                      <activecampaign.createContact>
                                                         <email>{$ctx:contactform.email.value}</email>
                                                         <firstName>{$ctx:contactform.firstName.value}</firstName>
                                                         <lastName>{$ctx:contactform.lastName.value}</lastName>
                                                         <orgName>{$ctx:contactform.company.value}</orgName>
                                                         <tags>{$ctx:tags}</tags>
                                                         <listDetails>{$ctx:listDetails}</listDetails>
                                                      </activecampaign.createContact>

                                                      <property name="createContactResultCode" expression="json-eval($.result_code)" />
                                                      <filter xpath="get-property('createContactResultCode') > '0'">
                                                         <then>
                                                            <property name="subscriberId" expression="json-eval($.subscriber_id)" />
                                                            <property name="id" expression="fn:concat('activeCampaign_contactId:', get-property('subscriberId'))" />
                                                            <property name="message" expression="fn:concat('Contact has been successfully created for ',get-property('contactform.email.value'),' and added to the campaign contact list.')" />
                                                            <call-template target="responseHandlerTemplate">
                                                               <with-param name="id" value="{$ctx:id}" />
                                                               <with-param name="status" value="success" />
                                                               <with-param name="activity" value="activeCampaign_createContact" />
                                                               <with-param name="message" value="{$ctx:message}" />
                                                            </call-template>
                                                         </then>
                                                         <else>
                                                            <property name="createContactError" expression="json-eval($.)" />
                                                            <call-template target="responseHandlerTemplate">
                                                               <with-param name="id" value="{$ctx:emptyID}" />
                                                               <with-param name="status" value="error" />
                                                               <with-param name="activity" value="activeCampaign_createContact" />
                                                               <with-param name="message" value="{$ctx:createContactError}" />
                                                            </call-template>
                                                         </else>
                                                      </filter>
                                                   </else>
                                                </filter>

                                                <property name="submissionIndex" expression="get-property('operation','submissionIndex') + 1" scope="operation" />
                                                <filter xpath="get-property('operation', 'submissionIndex') = get-property('operation', 'noOfSubmissionIds')">
                                                   <then>
                                                      <filter xpath="get-property('operation', 'noOfFormContactsExist') = get-property('operation', 'noOfSubmissionIds')">
                                                         <then>
                                                            <property name="id" expression="fn:concat('contactForm_formId:', get-property('contactform.formId'))" />
                                                            <property name="message" value="There are no new contacts to be added to the campaign contact list." />
                                                            <call-template target="responseHandlerTemplate">
                                                               <with-param name="id" value="{$ctx:id}" />
                                                               <with-param name="status" value="skipped" />
                                                               <with-param name="activity" value="activeCampaign_createContactFromSubmissions" />
                                                               <with-param name="message" value="{$ctx:message}" />
                                                            </call-template>
                                                         </then>
                                                      </filter>
                                                   </then>
                                                </filter>
                                             </sequence>
                                          </target>
                                       </iterate>
                                    </then>
                                 </filter>
                              </then>
                              <else>
                                 <property name="id" expression="fn:concat('contactForm_formId:', get-property('contactform.formId'))" />
                                 <property name="getSubmissionsError" expression="json-eval($.)" />
                                 <call-template target="responseHandlerTemplate">
                                    <with-param name="id" value="{$ctx:id}" />
                                    <with-param name="status" value="error" />
                                    <with-param name="activity" value="contactForm_getFormSubmissions" />
                                    <with-param name="message" value="{$ctx:getSubmissionsError}" />
                                 </call-template>
                              </else>
                           </filter>
                        </then>
                        <else>
                           <property name="id" expression="fn:concat('contactForm_formId:', get-property('contactform.formId'))" />
                           <property name="getFormFieldsError" expression="json-eval($.)" />
                           <call-template target="responseHandlerTemplate">
                              <with-param name="id" value="{$ctx:id}" />
                              <with-param name="status" value="error" />
                              <with-param name="activity" value="contactForm_getFields" />
                              <with-param name="message" value="{$ctx:getFormFieldsError}" />
                           </call-template>
                        </else>
                     </filter>
                  </then>
               </filter>
               <filter xpath="get-property('operation', 'submissionIndex') = get-property('operation', 'noOfSubmissionIds')">
                  <then>
                     <property name="Host" value="host.wso2.com" scope="transport" />
                     <activecampaign.init>
                        <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
                        <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
                        <apiOutput>{$ctx:output}</apiOutput>
                     </activecampaign.init>
                     <activecampaign.listCampaigns>
                        <isFull>{$ctx:activeCampaign.isFull}</isFull>
                        <nameFilter>{$ctx:activeCampaign.campaignName}</nameFilter>
                     </activecampaign.listCampaigns>
                     <property name="listCampaignsResultCode" expression="json-eval($.result_code)" />
                     <filter xpath="get-property('listCampaignsResultCode') > '0'">
                        <then>
                           <property name="activeCampaign.campaignId" expression="json-eval($.0.id)" />
                           <property name="activeCampaign.messageId" expression="json-eval($.0.messages[0].id)" />
                           <property name="Host" value="host.wso2.com" scope="transport" />
                           <activecampaign.init>
                              <apiOutput>{$ctx:output}</apiOutput>
                              <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
                              <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
                           </activecampaign.init>
                           <activecampaign.getCampaignClickers>
                              <campaignId>{$ctx:activeCampaign.campaignId}</campaignId>
                              <messageId>{$ctx:activeCampaign.messageId}</messageId>
                           </activecampaign.getCampaignClickers>
                           <property name="getCampaignClickersResultCode" expression="json-eval($.result_code)" />
                           <filter xpath="get-property('getCampaignClickersResultCode') > '0'">
                              <then>
                                 <property name="activeCampaign.clickers" expression="json-eval($.)" />
                                 <script language="js">
                                    <![CDATA[ 
                                       var clickersList =  eval("(" + mc.getProperty("activeCampaign.clickers") +")");
                                       var contactExist = 'false';
                                       var payload = {clickers:[]};
                                       for (var key in clickersList) {
                                          if (clickersList.hasOwnProperty(key)) {
                                             if(clickersList[key].hasOwnProperty("id")) {
                                                var clickersArray = clickersList[key].info;                                                                                                                    
                                                for (var index in clickersArray) {                                                                                              
                                                   for(var x in payload.clickers){
                                                      if(payload.clickers[x].subscriberId == clickersArray[index].subscriberid){
                                                         contactExist = 'true';
                                                      }
                                                   }                                                
                                                   if(contactExist != 'true'){                                           
                                                      payload.clickers.push({
                                                      "subscriberId": clickersArray[index].subscriberid,
                                                      "email": clickersArray[index].email                        
                                                      });                                               
                                                   }
                                                   else{
                                                      contactExist = 'false';
                                                   }                                               
                                                }                             
                                             }
                                          }
                                        }
                                    
                                      mc.setPayloadJSON(payload);                   
                                    ]]>
                                 </script>
                                 <property name="noOfClickers" expression="count(//clickers)" scope="operation" />
                                 <filter xpath="get-property('operation','noOfClickers') > '0'">
                                    <then>
                                       <iterate id="clickerIterator" expression="//clickers" continueParent="true" sequential="true">
                                          <target>
                                             <sequence>
                                                <property name="clickerContactId" expression="json-eval($.clickers.subscriberId)" />
                                                <property name="clickerEmail" expression="json-eval($.clickers.email)" />

                                                <property name="Host" value="host.wso2.com" scope="transport" />
                                                <activecampaign.init>
                                                   <apiOutput>{$ctx:output}</apiOutput>
                                                   <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
                                                   <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
                                                </activecampaign.init>
                                                <activecampaign.listContacts>
                                                   <emailFilter>{$ctx:clickerEmail}</emailFilter>
                                                   <isFull>1</isFull>
                                                </activecampaign.listContacts>
                                                <property name="listContactsCode" expression="json-eval($.result_code)" />
                                                <filter xpath="get-property('listContactsCode') > '0'">
                                                   <then>
                                                      <property name="clickerListLists" expression="json-eval($.0.listslist)" />
                                                      <property name="clickerExistingContactListId" expression="json-eval($.0.listid)" />
                                                      <property name="clickerOrgName" expression="json-eval($.0.orgname)" />
                                                      <script language="js">
                                                         <![CDATA[  
                                                            var campaignList =  "" + mc.getProperty("activeCampaign.listId") ;     
                                                            var clickerListLists =  "" +  mc.getProperty("clickerListLists") ;
                                                            var clickerExistingContactListId =   mc.getProperty("clickerExistingContactListId") ;
                                                            if(clickerExistingContactListId == campaignList){
                                                               mc.setProperty("inList",'true');
                                                            }
                                                            else{                                                                                                                       
                                                               var clickerListListsArray = clickerListLists.split("-");
                                                               for (var i = 0;i<clickerListListsArray.length;i++) {  
                                                                  if(clickerListListsArray[i] == campaignList) {
                                                                     mc.setProperty("inList",'true');
                                                                     break;
                                                                  } 
                                                               } 
                                                            }                                                                               
                                                                                                                                                    
                                                         ]]>
                                                      </script>
                                                      <filter source="get-property('inList') = 'true'" regex="false">
                                                         <then>
                                                            <script language="js">
                                                               <![CDATA[
                                                                  var listId = mc.getProperty('activeCampaign.listId');
                                                                  var payload = {};
                                                                  var listKey = 'p['+listId+']';
                                                                  payload[listKey] = listId;
                                                                  var statusKey = 'status['+listId+']';
                                                                  payload[statusKey] = 1;
                                                                  mc.setPayloadJSON(payload);
                                                               ]]>
                                                            </script>
                                                            <property name="clickerListDetails" expression="json-eval($.)" />
                                                            <property name="uri.var.firstName" action="remove" />
                                                            <property name="uri.var.lastName" action="remove" />
                                                            <property name="uri.var.tags" action="remove" />
                                                            <property name="Host" value="host.wso2.com" scope="transport" />
                                                            <activecampaign.init>
                                                               <apiOutput>{$ctx:output}</apiOutput>
                                                               <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
                                                               <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
                                                            </activecampaign.init>
                                                            <activecampaign.updateContact>
                                                               <contactId>{$ctx:clickerContactId}</contactId>
                                                               <email>{$ctx:clickerEmail}</email>
                                                               <orgName>{$ctx:clickerOrgName}</orgName>
                                                               <listDetails>{$ctx:clickerListDetails}</listDetails>
                                                            </activecampaign.updateContact>
                                                            <property name="updateContactListResultCode" expression="json-eval($.result_code)" />
                                                            <filter xpath="get-property('updateContactListResultCode') > '0'">
                                                               <then>
                                                                  <property name="id" expression="fn:concat('activeCampaign_contactId:', get-property('clickerContactId'))" />
                                                                  <property name="message" value="Contact has been successfully added to the campaign contact list." />
                                                                  <call-template target="responseHandlerTemplate">
                                                                     <with-param name="id" value="{$ctx:id}" />
                                                                     <with-param name="status" value="success" />
                                                                     <with-param name="activity" value="activeCampaign_updateContact" />
                                                                     <with-param name="message" value="{$ctx:message}" />
                                                                  </call-template>
                                                               </then>
                                                               <else>
                                                                  <property name="id" expression="fn:concat('activeCampaign_contactId:', get-property('clickerContactId'))" />
                                                                  <property name="updateContactListError" expression="json-eval($.)" />
                                                                  <call-template target="responseHandlerTemplate">
                                                                     <with-param name="id" value="{$ctx:id}" />
                                                                     <with-param name="status" value="error" />
                                                                     <with-param name="activity" value="activeCampaign_updateContact" />
                                                                     <with-param name="message" value="{$ctx:updateContactListError}" />
                                                                  </call-template>
                                                               </else>
                                                            </filter>
                                                         </then>
                                                         <else>
                                                            <property name="noOfContactsExist" expression="get-property('operation','noOfContactsExist') + 1" scope="operation" />
                                                         </else>
                                                      </filter>
                                                   </then>
                                                </filter>
                                                <property name="clickerIndex" expression="get-property('operation','clickerIndex') + 1" scope="operation" />
                                                <filter xpath="get-property('operation', 'clickerIndex') = get-property('operation', 'noOfClickers')">
                                                   <then>
                                                      <filter xpath="get-property('operation', 'noOfContactsExist') = get-property('operation', 'noOfClickers')">
                                                         <then>
                                                            <property name="message" value="There are no new contacts to be added to the campaign contact list." />
                                                            <property name="id" expression="fn:concat('activeCampaign_campaignId:',get-property('activeCampaign.campaignId'),',message_id:',get-property('activeCampaign.messageId')) " />
                                                            <call-template target="responseHandlerTemplate">
                                                               <with-param name="id" value="{$ctx:id}" />
                                                               <with-param name="status" value="skipped" />
                                                               <with-param name="activity" value="activeCampaign_updateContactFromClickers" />
                                                               <with-param name="message" value="{$ctx:message}" />
                                                            </call-template>
                                                         </then>
                                                      </filter>
                                                      <loopback />
                                                   </then>
                                                </filter>
                                             </sequence>
                                          </target>
                                       </iterate>
                                    </then>
                                    <else>
                                       <property name="getCampaignClickersError" expression="json-eval($.result_message)" />
                                       <property name="message" value="Clickers have not been found for the campaign." />
                                       <property name="id" expression="fn:concat('activeCampaign_campaignId:',get-property('activeCampaign.campaignId'),',message_id:',get-property('activeCampaign.messageId')) " />
                                       <call-template target="responseHandlerTemplate">
                                          <with-param name="id" value="{$ctx:id}" />
                                          <with-param name="status" value="skipped" />
                                          <with-param name="activity" value="activeCampaign_getCampaignClickers" />
                                          <with-param name="message" value="{$ctx:message}" />
                                       </call-template>
                                       <loopback />
                                    </else>
                                 </filter>
                              </then>
                              <else>
                                 <property name="getCampaignClickersError" expression="json-eval($.)" />
                                 <property name="id" expression="fn:concat('activeCampaign_campaignId:',get-property('activeCampaign.campaignId'),',message_id:',get-property('activeCampaign.messageId')) " />
                                 <call-template target="responseHandlerTemplate">
                                    <with-param name="id" value="{$ctx:id}" />
                                    <with-param name="status" value="error" />
                                    <with-param name="activity" value="activeCampaign_getCampaignClickers" />
                                    <with-param name="message" value="{$ctx:getCampaignClickersError}" />
                                 </call-template>
                                 <loopback />
                              </else>
                           </filter>
                        </then>
                        <else>
                           <property name="listCampaignsError" expression="json-eval($.)" />
                           <call-template target="responseHandlerTemplate">
                              <with-param name="id" value="{$ctx:emptyID}" />
                              <with-param name="status" value="error" />
                              <with-param name="activity" value="activeCampaign_listCampaigns" />
                              <with-param name="message" value="{$ctx:listCampaignsError}" />
                           </call-template>
                           <loopback />
                        </else>
                     </filter>
                  </then>
               </filter>
            </then>
            <else>
               <property name="listMailingListsError" expression="json-eval($.)" />
               <call-template target="responseHandlerTemplate">
                  <with-param name="id" value="{$ctx:emptyID}" />
                  <with-param name="status" value="error" />
                  <with-param name="activity" value="activeCampaign_listMailingLists" />
                  <with-param name="message" value="{$ctx:listMailingListsError}" />
               </call-template>
               <loopback />
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <payloadFactory media-type="json">
            <format>{ "Response":{ "process":"hubSpot_addContactsToContactList", "activityResponse":[$1] } }
            </format>
            <args>
               <arg expression="get-property('operation','responseString')" />
            </args>
         </payloadFactory>
         <property name="messageType" value="application/json" scope="axis2" />
         <send />
      </outSequence>
   </target>
   <description />
</proxy>
Sample Request for retrieving campaign clickers from ActiveCampaign and form submissions from 123ContactForm and adding them as contacts to the campaign contacts list (contact list named with the campaign name) in ActiveCampaign
{
  "activeCampaign": {
    "apiUrl": "https://dilanilaj.activehosted.com",
    "apiKey": "f81ff28823532452d6e5caf080d516fec3d5385c0983f618913e90753e0d456d91ea2561",
    "campaignName":"testCampaign"
  },
  "contactForm": {
	"apiKey":"743401-1438926394-tzsh7xqrgu8a9wb34",
	"formId":"1564707"
  }
} 

Note

 The following are the parameter descriptions:

  • activeCampaign.campaignName: The name of the campaign.
  • contactForm.formId : The ID of the form which will be used by the people who are submitting their details. 

Retrieving deals, creating companies, contacts and deals

  1. Deals should be created in the ActiveCampaign API as an offline process.
  2. Retrieve deal stage ID for the 'Contacted' stage from the ActiveCampaign API using the listDealStages operation.
  3. Retrieve deals from the ActiveCampaign API using the listDeals operation.
  4. Retrieve the contact from the ActiveCampaign API using the getContactByEmail operation.
  5. Retrieve companies from the Hubspot API using the listRecentlyModifiedCompanies operation.
  6. If the company does not exist, create the company in the Hubspot API using the createCompany operation.
  7. If the contact does not exist, create the contact in the Hubspot API using the createContact operation.
  8. Add the contact to a company in the Hubspot API using the addContactToCompany operation.
  9. Create the deal in the Hubspot API using the createDeal operation.
  10. Update the contact in the ActiveCampaign API using the updateContact operation.
ActiveCampaign operations
Hubspot operations

Prerequisites

  1. Create a custom property for deal as 'Active Campaign Id' with the field type 'Single-line text' in Hubspot API.
  2. Create a deal stage in the ActiveCampaign API named "Contacted".
Samples
Sample Proxy for retrieving the deals in stage "Contacted" from ActiveCampaign and creating the respective company, contact and deal in Hubspot
<?xml version="1.0" encoding="UTF-8"?>
<!--
   Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
   WSO2 Inc. licenses this file to you under the Apache License,
   Version 2.0 (the "License"); you may not use this file except
   in compliance with the License.
   You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied. See the License for the
   specific language governing permissions and limitations
   under the License.
-->
<!-- Create deals, companies and contacts in HubSpot API for the deals which are in Contacted stage in ActiveCampaign API. -->
<proxy xmlns="http://ws.apache.org/ns/synapse" name="hubSpot_createDealsCompaniesAndContacts" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <!-- ActiveCampaign parameters. -->
         <property name="activeCampaign.apiUrl" expression="json-eval($.activeCampaign.apiUrl)" />
         <property name="activeCampaign.apiKey" expression="json-eval($.activeCampaign.apiKey)" />
         <property name="hubspot.apiUrl" value="https://api.hubapi.com" />
         <property name="hubspot.apiKey" expression="json-eval($.hubSpot.apiKey)" />
         <!-- List deal stages. -->
         <activecampaign.init>
            <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
            <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
            <apiOutput>json</apiOutput>
         </activecampaign.init>
         <activecampaign.listDealStages>
         </activecampaign.listDealStages>
         <property name="activeCampaign.result.code" expression="//jsonObject/result_code/text()" />
         <filter xpath="get-property('activeCampaign.result.code') = 0">
            <then>
               <property name="id" value="{}" />
               <property name="status" value="error" />
               <property name="message" expression="//jsonObject/result_message/text()" />
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="activeCampaign_listDealStages" />
                  <with-param name="id" value="{$ctx:id}" />
                  <with-param name="status" value="{$ctx:status}" />
                  <with-param name="message" value="{$ctx:message}" />
               </call-template>
               <loopback />
            </then>
         </filter>
         <property name="activeCampaign.stages" expression="json-eval($.)" />
         <script language="js">
         <![CDATA[     
            //Getting 'Contacted' stage Id.
            var stageList =  eval("(" + mc.getProperty("activeCampaign.stages") +")");
            var stage = "";     
            for (var key in stageList) {
              if (stageList.hasOwnProperty(key)) {
                 if (stageList[key].hasOwnProperty('title')) {
                     stage = "" + stageList[key]['title'];
                     if(stage == "Contacted") {
                         mc.setProperty('activeCampaign.stageId',stageList[key]['id']);
                         break;
                     }
                 }
              }
            }
         ]]>
         </script>
         <filter source="boolean(get-property('activeCampaign.stageId'))" regex="false">
            <then>
               <property name="id" value="{}" />
               <property name="status" value="skipped" />
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="activeCampaign_listDealStages" />
                  <with-param name="id" value="{$ctx:id}" />
                  <with-param name="status" value="{$ctx:status}" />
                  <with-param name="message" value="Contacted deal stage has not been found." />
               </call-template>
               <loopback />
            </then>
         </filter>
         <!-- Workaround to eliminate the Host header issue in ActiveCampaign. -->
         <property name="Host" value="host.wso2.com" scope="transport" />
         <!-- List deals. -->
         <activecampaign.init>
            <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
            <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
            <apiOutput>json</apiOutput>
         </activecampaign.init>
         <activecampaign.listDeals>
            <stageFilter>{$ctx:activeCampaign.stageId}</stageFilter>
         </activecampaign.listDeals>
         <property name="activeCampaign.result.code" expression="//jsonObject/result_code/text()" />
         <filter xpath="get-property('activeCampaign.result.code') = 0">
            <then>
               <property name="id" value="{}" />
               <property name="status" value="error" />
               <property name="message" expression="//jsonObject/result_message/text()" />
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="activeCampaign_listDeals" />
                  <with-param name="id" value="{$ctx:id}" />
                  <with-param name="status" value="{$ctx:status}" />
                  <with-param name="message" value="{$ctx:message}" />
               </call-template>
               <loopback />
            </then>
         </filter>
         <property name="activeCampaign.deals" expression="json-eval($.)" />
         <script language="js">
         <![CDATA[       
            //Create a deal array. 
            var count = 0;
            var payload = {deals:[]};                                 
            var dealList =  eval( "(" + mc.getProperty("activeCampaign.deals") + ")" );  
            for (var key in dealList) {
               if (dealList.hasOwnProperty(key)) {
                  if(dealList[key].hasOwnProperty("id")) {                       
                         count++;
                         payload.deals.push({
                           "dealId": dealList[key].id,
                           "dealTitle" : dealList[key].title,
                           "contactEmail" : dealList[key].contact_email                            
                           });                      
                   }
                }
           }
           mc.setProperty('dealCount',count);
           mc.setPayloadJSON(payload);
         ]]>
         </script>
         <property name="dealCount" expression="get-property('dealCount')" scope="operation" />
         <property name="dealIndex" value="0.0" scope="operation" />
         <property name="companyTags" value="" scope="operation" />
         <!-- Deal iterator. -->
         <iterate continueParent="true" id="dealIterator" expression="//deals" sequential="true">
            <target>
               <sequence>
                  <property name="activeCampaign.contact.email" expression="json-eval($.deals.contactEmail)" />
                  <property name="activeCampaign.deal.id" expression="json-eval($.deals.dealId)" />
                  <property name="activeCampaign.deal.title" expression="json-eval($.deals.dealTitle)" />
                  <!-- Workaround to eliminate the Host header issue in ActiveCampaign. -->
                  <property name="Host" value="host.wso2.com" scope="transport" />
                  <!-- List deals. -->
                  <activecampaign.init>
                     <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
                     <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
                     <apiOutput>json</apiOutput>
                  </activecampaign.init>
                  <activecampaign.getContactByEmail>
                     <email>{$ctx:activeCampaign.contact.email}</email>
                  </activecampaign.getContactByEmail>
                  <property name="activeCampaign.result.code" expression="//jsonObject/result_code/text()" />
                  <filter source="get-property('activeCampaign.result.code') = 0" regex="false">
                     <then>
                        <property name="activeCampaign.contact.id" expression="json-eval($.id)" />
                        <property name="activeCampaign.contact.firstName" expression="json-eval($.first_name)" />
                        <property name="activeCampaign.contact.lastName" expression="json-eval($.last_name)" />
                        <property name="activeCampaign.contact.phone" expression="json-eval($.phone)" />
                        <property name="activeCampaign.contact.orgName" expression="json-eval($.orgname)" />
                        <property name="activeCampaign.contact.tags" expression="json-eval($.tags)" />
                        <property name="activeCampaign.contact.updateTags" value="" />

                        <script language="js">
                        <![CDATA[       
                           //Store tag details.
                           var tags = mc.getProperty('activeCampaign.contact.tags');
                           var dealId = mc.getProperty('activeCampaign.deal.id');
                           var contactId = "";
                           var companyId = "";
                           var dealCreated ="false"; 
                           if(tags != null && tags !="" && tags!= [] ){
                              if(tags.indexOf("[") > -1) {
                                 tags = eval("("+tags+")");            
                                 for(var i = 0; i<tags.length;i++) {
                                    if(tags[i].indexOf("CompanyId") > -1) {                              
                                       companyId = tags[i].split(":")[1];
                                    } else if(tags[i].indexOf("ContactId")  > -1) {
                                       contactId = tags[i].split(":")[1];
                                    } else if(tags[i].indexOf("DealId:" + dealId)  > -1) {
                                       dealCreated = "true";
                                    }
                                 }
                              } else { 
                                 if(tags.indexOf("CompanyId") > -1) {                              
                                    companyId = tags.split(":")[1];
                                 } else if(tags.indexOf("ContactId")  > -1) {
                                    contactId = tags.split(":")[1];
                                 } else if(tags.indexOf("DealId:" + dealId)  > -1) {
                                    dealCreated = "true";
                                 }
                              }
                              
                           } 
                           mc.setProperty('hubspot.companyId',companyId);
                           mc.setProperty('hubspot.contactId',contactId);
                           mc.setProperty('hubspot.deal.created', dealCreated); 
                        ]]>
                        </script>
                        <filter source="boolean(get-property('hubspot.companyId'))" regex="false">
                           <then>
                              <filter xpath="boolean(get-property('activeCampaign.contact.orgName'))">
                                 <then>
                                    <!-- List companies. -->
                                    <hubspot.init>
                                       <apiKey>{$ctx:hubspot.apiKey}</apiKey>
                                       <apiUrl>{$ctx:hubspot.apiUrl}</apiUrl>
                                    </hubspot.init>
                                    <hubspot.listRecentlyModifiedCompanies>
                                    </hubspot.listRecentlyModifiedCompanies>
                                    <property name="hubspot.companies" expression="json-eval($.results)" />
                                    <filter source="$axis2:HTTP_SC" regex="200">
                                       <then>
                                          <script language="js">
                                          <![CDATA[       
                                             //Extracting company Id.
                                             var companies = mc.getProperty('hubspot.companies');
                                             var organization = mc.getProperty('activeCampaign.contact.orgName');
                                             if(companies != null && companies !="" ){
                                                companies = eval("("+companies+")");            
                                                for(var i = 0; i<companies.length;i++) {                                       
                                                   if(companies[i].properties.name.value == organization) {
                                                   mc.setProperty('hubspot.companyId',companies[i].companyId);
                                                   }
                                                }
                                             }
                                          ]]>
                                          </script>
                                          <filter source="boolean(get-property('hubspot.companyId'))" regex="false">
                                             <then>
                                                <property name="companyTags" expression="get-property('operation','companyTags')" />
                                                <script language="js">
                                                <![CDATA[       
                                                   //Constructing inputs for create company.
                                                   var orgName = mc.getProperty('activeCampaign.contact.orgName');
                                                   var createdCompanies = mc.getProperty('companyTags').split(",");
                                                   var payload = {properties:[]};
                                                   for(var i = 0; i<createdCompanies.length;i++) {
                                                      if(createdCompanies[i].indexOf(orgName) > -1) {                              
                                                         var companyId = createdCompanies[i].split(":")[1];
                                                         mc.setProperty("hubspot.companyId",companyId);
                                                      } 
                                                   }
                                                   payload.properties.push({ 
                                                               "name" : "name",     
                                                               "value" : "" + orgName});
                                                   mc.setPayloadJSON(payload);
                                                ]]>
                                                </script>
                                                <property name="hubspot.company.properties" expression="json-eval($.properties)" />
                                                <filter source="boolean(get-property('hubspot.companyId'))" regex="false">
                                                   <then>
                                                      <!-- Create company. -->
                                                      <hubspot.init>
                                                         <apiKey>{$ctx:hubspot.apiKey}</apiKey>
                                                         <apiUrl>{$ctx:hubspot.apiUrl}</apiUrl>
                                                      </hubspot.init>
                                                      <hubspot.createCompany>
                                                         <properties>{$ctx:hubspot.company.properties}</properties>
                                                      </hubspot.createCompany>
                                                      <filter source="$axis2:HTTP_SC" regex="200">
                                                         <then>
                                                            <property name="hubspot.companyId" expression="json-eval($.companyId)" />
                                                            <property name="companyTags" expression="fn:concat(get-property('operation','companyTags'),get-property('activeCampaign.contact.orgName'),':',get-property('hubspot.companyId'),',')" scope="operation" />
                                                            <property name="activeCampaign.contact.updateTags" expression="fn:concat(get-property('activeCampaign.contact.updateTags'),'CompanyId:',get-property('hubspot.companyId'),',')" />
                                                            <property name="id" expression="fn:concat('activeCampaign_contactId:',get-property('activeCampaign.contact.id'),',hubSpot_companyId:',get-property('hubspot.companyId'))" />
                                                            <property name="status" value="success" />
                                                            <property name="message" value="Company has been successfully created." />
                                                            <call-template target="responseHandlerTemplate">
                                                               <with-param name="activity" value="hubSpot_createCompany" />
                                                               <with-param name="id" value="{$ctx:id}" />
                                                               <with-param name="status" value="{$ctx:status}" />
                                                               <with-param name="message" value="{$ctx:message}" />
                                                            </call-template>
                                                         </then>
                                                         <else>
                                                            <property name="id" expression="fn:concat('activeCampaign_contactId:',get-property('activeCampaign.contact.id'))" />
                                                            <property name="status" value="error" />
                                                            <property name="message" expression="//jsonObject/message/text()" />
                                                            <call-template target="responseHandlerTemplate">
                                                               <with-param name="activity" value="hubSpot_createCompany" />
                                                               <with-param name="id" value="{$ctx:id}" />
                                                               <with-param name="status" value="{$ctx:status}" />
                                                               <with-param name="message" value="{$ctx:message}" />
                                                            </call-template>
                                                         </else>
                                                      </filter>
                                                   </then>
                                                   <else>
                                                      <property name="activeCampaign.contact.updateTags" expression="fn:concat(get-property('activeCampaign.contact.updateTags'),'CompanyId:',get-property('hubspot.companyId'),',')" />
                                                   </else>
                                                </filter>
                                             </then>
                                             <else>
                                                <property name="activeCampaign.contact.updateTags" expression="fn:concat(get-property('activeCampaign.contact.updateTags'),'CompanyId:',get-property('hubspot.companyId'),',')" />
                                             </else>
                                          </filter>
                                       </then>
                                       <else>
                                          <property name="id" value="{}" />
                                          <property name="status" value="error" />
                                          <property name="message" expression="//jsonObject/message/text()" />
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="hubSpot_listCompanies" />
                                             <with-param name="id" value="{$ctx:id}" />
                                             <with-param name="status" value="{$ctx:status}" />
                                             <with-param name="message" value="{$ctx:message}" />
                                          </call-template>
                                          <loopback />
                                       </else>
                                    </filter>
                                 </then>
                              </filter>
                           </then>
                        </filter>
                        <filter source="boolean(get-property('hubspot.contactId'))" regex="false">
                           <then>
                              <script language="js">
                              <![CDATA[       
                                 //Construct inputs for create contact. 
                                 var firstName = mc.getProperty('activeCampaign.contact.firstName'); 
                                 var lastName = mc.getProperty('activeCampaign.contact.lastName');
                                 var phone = mc.getProperty('activeCampaign.contact.phone');
                                 var email = mc.getProperty('activeCampaign.contact.email');
                                 var payload = {properties:[]};
                                 payload.properties.push({ 
                                             "property" : "email",     
                                             "value" : "" + email});
                                 if(firstName != "null" && firstName != "") {
                                    payload.properties.push({ 
                                             "property" : "firstname",     
                                             "value" : "" + firstName});
                                 }
                                 if(lastName != "null" && lastName != "") {
                                    payload.properties.push({ 
                                             "property" : "lastname",     
                                             "value" : "" + lastName});
                                 }
                                 if(phone != "null" && phone != "") {
                                    payload.properties.push({ 
                                             "property" : "phone",     
                                             "value" : "" + phone});
                                 }
                                 mc.setPayloadJSON(payload);
                              ]]>
                              </script>
                              <property name="hubspot.contact.properties" expression="json-eval($.properties)" />
                              <!-- Create contact. -->
                              <hubspot.init>
                                 <apiKey>{$ctx:hubspot.apiKey}</apiKey>
                                 <apiUrl>{$ctx:hubspot.apiUrl}</apiUrl>
                              </hubspot.init>
                              <hubspot.createContact>
                                 <properties>{$ctx:hubspot.contact.properties}</properties>
                              </hubspot.createContact>
                              <filter source="$axis2:HTTP_SC" regex="200">
                                 <then>
                                    <property name="hubspot.contactId" expression="json-eval($.vid)" />
                                    <property name="activeCampaign.contact.updateTags" expression="fn:concat(get-property('activeCampaign.contact.updateTags'),'ContactId:',get-property('hubspot.contactId'),',')" />
                                    <property name="id" expression="fn:concat('activeCampaign_contactId:',get-property('activeCampaign.contact.id'),',hubSpot_contactId:',get-property('hubspot.contactId'))" />
                                    <property name="status" value="success" />
                                    <property name="message" value="Contact has been successfully created." />
                                    <call-template target="responseHandlerTemplate">
                                       <with-param name="activity" value="hubSpot_createContact" />
                                       <with-param name="id" value="{$ctx:id}" />
                                       <with-param name="status" value="{$ctx:status}" />
                                       <with-param name="message" value="{$ctx:message}" />
                                    </call-template>
                                    <filter source="boolean(get-property('hubspot.companyId'))" regex="true">
                                       <then>
                                          <!-- Add contact to a company. -->
                                          <hubspot.init>
                                             <apiKey>{$ctx:hubspot.apiKey}</apiKey>
                                             <apiUrl>{$ctx:hubspot.apiUrl}</apiUrl>
                                          </hubspot.init>
                                          <hubspot.addContactToCompany>
                                             <companyId>{$ctx:hubspot.companyId}</companyId>
                                             <contactVId>{$ctx:hubspot.contactId}</contactVId>
                                          </hubspot.addContactToCompany>
                                          <property name="hubspot.statusResponse" expression="$axis2:HTTP_SC" />
                                          <filter source="get-property('hubspot.statusResponse') = 200" regex="false">
                                             <then>
                                                <property name="id" expression="fn:concat('activeCampaign_contactId:',get-property('activeCampaign.contact.id'),',hubSpot_companyId:',get-property('hubspot.companyId'),',hubSpot_contactVId:',get-property('hubspot.contactId'))" />
                                                <property name="status" value="skipped" />
                                                <property name="message" expression="//jsonObject/message/text()" />
                                                <call-template target="responseHandlerTemplate">
                                                   <with-param name="activity" value="hubSpot_addContactToCompany" />
                                                   <with-param name="id" value="{$ctx:id}" />
                                                   <with-param name="status" value="{$ctx:status}" />
                                                   <with-param name="message" value="{$ctx:message}" />
                                                </call-template>
                                             </then>
                                          </filter>
                                       </then>
                                    </filter>
                                 </then>
                                 <else>
                                    <filter source="$axis2:HTTP_SC" regex="409">
                                       <then>
                                          <property name="hubspot.contactId" expression="json-eval($.identityProfile.vid)" />
                                          <property name="activeCampaign.contact.updateTags" expression="fn:concat(get-property('activeCampaign.contact.updateTags'),'ContactId:',get-property('hubspot.contactId'),',')" />
                                       </then>
                                       <else>
                                          <property name="id" expression="fn:concat('activeCampaign_contactId:',get-property('activeCampaign.contact.id'))" />
                                          <property name="status" value="error" />
                                          <property name="message" expression="//jsonObject/message/text()" />
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="hubSpot_createContact" />
                                             <with-param name="id" value="{$ctx:id}" />
                                             <with-param name="status" value="{$ctx:status}" />
                                             <with-param name="message" value="{$ctx:message}" />
                                          </call-template>
                                       </else>
                                    </filter>
                                 </else>
                              </filter>
                           </then>
                        </filter>

                        <filter xpath="boolean(get-property('hubspot.contactId'))">
                           <then>
                              <filter source="get-property('hubspot.deal.created') = 'true'" regex="false">
                                 <then>
                                    <payloadFactory media-type="json">
                                       <format>
                                          {
                                          "associatedVIds":[$1],
                                          "dealProperties":[{
                                          "value":"$2",
                                          "name":"dealname" },
                                          {
                                          "value":"$3",
                                          "name":"active_campaign_id"
                                          }]
                                          }
                                       </format>
                                       <args>
                                          <arg expression="get-property('hubspot.contactId')" />
                                          <arg expression="get-property('activeCampaign.deal.title')" />
                                          <arg expression="get-property('activeCampaign.deal.id')" />
                                       </args>
                                    </payloadFactory>
                                    <property name="hubspot.deal.associatedVIds" expression="json-eval($.associatedVIds)" />
                                    <property name="hubspot.deal.dealProperties" expression="json-eval($.dealProperties)" />
                                    <!-- Create deal. -->
                                    <hubspot.init>
                                       <apiKey>{$ctx:hubspot.apiKey}</apiKey>
                                       <apiUrl>{$ctx:hubspot.apiUrl}</apiUrl>
                                    </hubspot.init>
                                    <hubspot.createDeal>
                                       <properties>{$ctx:hubspot.deal.dealProperties}</properties>
                                       <associatedVIds>{$ctx:hubspot.deal.associatedVIds}</associatedVIds>
                                    </hubspot.createDeal>
                                    <filter source="$axis2:HTTP_SC" regex="200">
                                       <then>
                                          <property name="hubspot.dealId" expression="json-eval($.dealId)" />
                                          <property name="activeCampaign.contact.updateTags" expression="fn:concat(get-property('activeCampaign.contact.updateTags'),'DealId:',get-property('activeCampaign.deal.id'),',')" />
                                          <property name="id" expression="fn:concat('hubSpot_contactId:',get-property('hubspot.contactId'),',activeCampaign_dealId:',get-property('activeCampaign.deal.id'),',hubSpot_dealId:',get-property('hubspot.dealId'))" />
                                          <property name="status" value="success" />
                                          <property name="message" value="Deal has been successfully created." />
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="hubSpot_createDeal" />
                                             <with-param name="id" value="{$ctx:id}" />
                                             <with-param name="status" value="{$ctx:status}" />
                                             <with-param name="message" value="{$ctx:message}" />
                                          </call-template>
                                       </then>
                                       <else>
                                          <property name="id" expression="fn:concat('hubspot_contactId:',get-property('hubspot.contactId'),',activeCampaign_dealId:',get-property('activeCampaign.deal.id'))" />
                                          <property name="status" value="error" />
                                          <property name="message" expression="//jsonObject/message/text()" />
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="hubSpot_createDeal" />
                                             <with-param name="id" value="{$ctx:id}" />
                                             <with-param name="status" value="{$ctx:status}" />
                                             <with-param name="message" value="{$ctx:message}" />
                                          </call-template>
                                       </else>
                                    </filter>
                                 </then>
                              </filter>
                           </then>
                        </filter>
                     </then>
                     <else>
                        <property name="id" value="{}" />
                        <property name="status" value="error" />
                        <property name="message" expression="//jsonObject/result_message/text()" />
                        <call-template target="responseHandlerTemplate">
                           <with-param name="activity" value="activeCampaign_getContactByEmail" />
                           <with-param name="id" value="{$ctx:id}" />
                           <with-param name="status" value="{$ctx:status}" />
                           <with-param name="message" value="{$ctx:message}" />
                        </call-template>
                     </else>
                  </filter>
                  <filter xpath="boolean(get-property('activeCampaign.contact.updateTags'))">
                     <then>
                        <!-- Workaround to eliminate the Host header issue in ActiveCampaign. -->
                        <property name="Host" value="host.wso2.com" scope="transport" />
                        <!-- List contacts. -->
                        <activecampaign.init>
                           <apiUrl>{$ctx:activeCampaign.apiUrl}</apiUrl>
                           <apiKey>{$ctx:activeCampaign.apiKey}</apiKey>
                           <apiOutput>json</apiOutput>
                        </activecampaign.init>
                        <activecampaign.updateContact>
                           <tags>{$ctx:activeCampaign.contact.updateTags}</tags>
                           <contactId>{$ctx:activeCampaign.contact.id}</contactId>
                           <email>{$ctx:activeCampaign.contact.email}</email>
                           <overwrite>0</overwrite>
                           <orgName>{$ctx:activeCampaign.contact.orgName}</orgName>
                        </activecampaign.updateContact>
                     </then>
                  </filter>
                  <property name="dealIndex" expression="get-property('operation','dealIndex') + 1" scope="operation" />
               </sequence>
            </target>
         </iterate>
         <filter xpath="get-property('operation', 'dealIndex') = get-property('operation', 'dealCount')">
            <then>
               <loopback />
            </then>
         </filter>
      </inSequence>
      <outSequence>
         <filter source="boolean(get-property('operation', 'responseString'))" regex="false">
            <then>
               <payloadFactory media-type="json">
                  <format>{
                     "Response":{
                     "process":"hubSpot_createDealsCompaniesAndContacts",
                     "activityResponse":[{"activity": "activeCampaign_listDeals",
                     "id": { },
                     "status": "skipped",		 
                     "message": "Couldn't find deals to be processed."}]
                     }
                     }
                  </format>
                  <args />
               </payloadFactory>
            </then>
            <else>
               <payloadFactory media-type="json">
                  <format>{ "Response":{ "process":"hubSpot_createDealsCompaniesAndContacts", "activityResponse":[$1] } }
                  </format>
                  <args>
                     <arg expression="get-property('operation','responseString')" />
                  </args>
               </payloadFactory>
            </else>
         </filter>
         <property name="messageType" value="application/json" scope="axis2" />
         <send />
      </outSequence>
   </target>
   <description />
</proxy> 
Sample Request for retrieving the deals in stage "Contacted" from ActiveCampaign and creating the respective company, contact and deal in Hubspot
{
  "activeCampaign": {
     "apiUrl":"https://dilanijtest2412.api-us1.com",
	"apiKey":"82a26a1ac9f04da7b150ac83e6c9bb764936787dc992f2532c985eb90fa5d01578c9c13e"
},
  "hubSpot": {
  	"apiKey":"982855ac-b43b-4c89-833b-eb9002379825"
  }
}