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/.

Initiation Subscription in Recurly

The first use case in the Recurly business scenario is used for initiation subscription. This page describes the relevant tasks and the operations you use in the Recurly connector and the other ESB connectors. It contains the following sections:

Overview

The flow for initiation subscription is illustrated in the following diagram. The ESB connectors for Base CRM and ActiveCampaign will be used to connect to each service. 

Note

When creating accounts in Recurly, the contact will be a person in Base CRM and not a company.

Prerequisite

ActiveCampaign contacts and contact lists should be created as an offline process.

Marketing subscription plan

  1. Create a subscription plan in the Recurly API using the createPlan operation and create the e-mail message to be used for the campaign in the ActiveCampaign API using the createMessage operation.
  2. Create the campaign in ActiveCampaign API using the createCampaign operation and send it to the relevant contacts.
Recurly operations
ActiveCampaign operations
Samples 
Sample proxy for creating a subscription plan in the Recurly API, and creating the email message to be used for the campaign in the ActiveCampaign API
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="recurly_marketingSubscriptionPlans" transports="https,http"
   statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <!-- Recurly parameters -->
         <property name="recurlyApiUrl" expression="json-eval($.recurlyApiUrl)" />
         <property name="recurlyApiKey" expression="json-eval($.recurlyApiKey)" />
         <property name="recurlyPlanCode" expression="json-eval($.recurlyPlanCode)" />
         <property name="recurlyPlanName" expression="json-eval($.recurlyPlanName)" />
         <property name="recurlyUnitAmountInCents" expression="json-eval($.recurlyUnitAmountInCents)" />
         <property name="recurlyDescription" expression="json-eval($.recurlyDescription)" />
         <property name="recurlyAccountingCode" expression="json-eval($.recurlyAccountingCode)" />
         <property name="recurlyPlanIntervalUnit" expression="json-eval($.recurlyPlanIntervalUnit)" />
         <property name="recurlyPlanIntervalLength" expression="json-eval($.recurlyPlanIntervalLength)" />
         <property name="recurlyTrialIntervalUnit" expression="json-eval($.recurlyTrialIntervalUnit)" />
         <property name="recurlyTrialIntervalLength" expression="json-eval($.recurlyTrialIntervalLength)" />
         <property name="recurlySetupFeeInCents" expression="json-eval($.recurlySetupFeeInCents)" />
         <property name="recurlyTotalBillingCycles" expression="json-eval($.recurlyTotalBillingCycles)" />
         <property name="recurlyUnitName" expression="json-eval($.recurlyUnitName)" />
         <property name="recurlyDisplayQuantity" expression="json-eval($.recurlyDisplayQuantity)" />
         <property name="recurlySuccessUrl" expression="json-eval($.recurlySuccessUrl)" />
         <property name="recurlyCancelUrl" expression="json-eval($.recurlyCancelUrl)" />
         <property name="recurlyTaxExempt" expression="json-eval($.recurlyTaxExempt)" />
         <property name="recurlyTaxCode" expression="json-eval($.recurlyTaxCode)" />
         <!-- ActiveCampaign parameters. -->
         <property name="activeCampaignApiUrl" expression="json-eval($.activeCampaignApiUrl)" />
         <property name="activeCampaignApiKey" expression="json-eval($.activeCampaignApiKey)" />
         <property name="activeCampaignFormat" expression="json-eval($.activeCampaignFormat)" />
         <property name="activeCampaignFromEmail" expression="json-eval($.activeCampaignFromEmail)" />
         <property name="activeCampaignFromName" expression="json-eval($.activeCampaignFromName)" />
         <property name="activeCampaignReplyTo" expression="json-eval($.activeCampaignReplyTo)" />
         <property name="activeCampaignPriority" expression="json-eval($.activeCampaignPriority)" />
         <property name="activeCampaignCharset" expression="json-eval($.activeCampaignCharset)" />
         <property name="activeCampaignEncoding" expression="json-eval($.activeCampaignEncoding)" />
         <property name="activeCampaignHtmlConstructor" expression="json-eval($.activeCampaignHtmlConstructor)" />
         <property name="activeCampaignHtml" expression="json-eval($.activeCampaignHtml)" />
         <property name="activeCampaignHtmlFetch" expression="json-eval($.activeCampaignHtmlFetch)" />
         <property name="activeCampaignHtmlFetchWhen" expression="json-eval($.activeCampaignHtmlFetchWhen)" />
         <property name="activeCampaignTextFetch" expression="json-eval($.activeCampaignTextFetch)" />
         <property name="activeCampaignTextFetchWhen" expression="json-eval($.activeCampaignTextFetchWhen)" />
         <property name="activeCampaignListIds" expression="json-eval($.activeCampaignListIds)" />
         <property name="activeCampaignType" expression="json-eval($.activeCampaignType)" />
         <property name="activeCampaignName" expression="json-eval($.activeCampaignName)" />
         <property name="activeCampaignIsPublic" expression="json-eval($.activeCampaignIsPublic)" />
         <property name="activeCampaignTrackLinks" expression="json-eval($.activeCampaignTrackLinks)" />
         <!-- Constructing UnitAmmountInCent and SetupFeeInCents in order to send to Recurly API by converting JSON to XML
            tags. -->
         <script language="js">
          <![CDATA[
            var currencyObject = mc.getProperty("recurlyUnitAmountInCents");
            var setupCurrencyObject = mc.getProperty("recurlySetupFeeInCents");
            if (currencyObject != null && currencyObject != "") {
               var currencyObject = eval("(" + currencyObject + ")");
               var currencyString = "<values>";
               for(var i = 0; i < currencyObject.length; i++) {
                  var obj = currencyObject[i];
                  currencyString = currencyString + "<" + obj.currencyCode + ">" + obj.units + "</" + obj.currencyCode + ">" ;
               }
               currencyString = currencyString + "</values>";
               mc.setProperty("recurlyUnitAmountInCents",currencyString);
            }
            if (setupCurrencyObject != null && setupCurrencyObject != "") {
               var setupCurrencyObject = mc.getProperty("setupCurrencyObject");
               var currencyString = "<values>";
               for(var i = 0; i < setupCurrencyObject.length; i++) {
                  var obj = setupCurrencyObject[i];
                  currencyString = currencyString + "<" + obj.currencyCode + ">" + obj.units + "</" + obj.currencyCode + ">" ;
               }
               currencyString = currencyString + "</values>";
               mc.setProperty("recurlySetupFeeInCents",currencyString);
            }
          ]]>
         </script>
         <property name="messageType" value="application/xml" scope="axis2" />
         <!-- Creating plan. -->
         <recurly.init>
            <apiUrl>{$ctx:recurlyApiUrl}</apiUrl>
            <apiKey>{$ctx:recurlyApiKey}</apiKey>
         </recurly.init>
         <recurly.createPlan>
            <unitAmountInCents>{$ctx:recurlyUnitAmountInCents}</unitAmountInCents>
            <planCode>{$ctx:recurlyPlanCode}</planCode>
            <name>{$ctx:recurlyPlanName}</name>
            <accountingCode>{$ctx:recurlyAccountingCode}</accountingCode>
            <setupFeeInCents>{$ctx:recurlySetupFeeInCents}</setupFeeInCents>
            <taxCode>{$ctx:recurlyTaxCode}</taxCode>
            <successUrl>{$ctx:recurlySuccessUrl}</successUrl>
            <trialIntervalLength>{$ctx:recurlyTrialIntervalLength}</trialIntervalLength>
            <planIntervalLength>{$ctx:recurlyPlanIntervalLength}</planIntervalLength>
            <trialIntervalUnit>{$ctx:recurlyTrialIntervalUnit}</trialIntervalUnit>
            <description>{$ctx:recurlyDescription}</description>
            <unitName>{$ctx:recurlyUnitName}</unitName>
            <displayQuantity>{$ctx:recurlyDisplayQuantity}</displayQuantity>
            <cancelUrl>{$ctx:recurlyCancelUrl}</cancelUrl>
            <totalBillingCycles>{$ctx:recurlyTotalBillingCycles}</totalBillingCycles>
            <planIntervalUnit>{$ctx:recurlyPlanIntervalUnit}</planIntervalUnit>
            <taxExempt>{$ctx:recurlyTaxExempt}</taxExempt>
         </recurly.createPlan>
         <sequence key="removeResponseHeaders" />
         <!-- Check plan created. -->
         <filter source="$axis2:HTTP_SC" regex="201">
            <then>
               <!-- Creating a subscription link. -->
               <property name="subscriptionLink"
                  expression="fn:concat(get-property('recurlyApiUrl'), '/subscribe/', get-property('recurlyPlanCode'))" />
               <property name="activeCampaignSubject" expression="fn:concat('Subscribe for the ',get-property('recurlyPlanName'),' plan')" />
               <property name="activeCampaignEmailTextContent"
                  expression="fn:concat('Dear User,\n\n This is to inform that we have introduced a ', get-property('recurlyPlanName'),' plan, which you might be interested in.\n\n To subscribe please click on ', get-property('subscriptionLink'))" />
               <!-- Workaround to eliminate the Host header issue in ActiveCampaign. -->
               <property name="Host" value="host.wso2.com" scope="transport" />
               <!-- Create Email message. -->
               <activecampaign.init>
                  <apiUrl>{$ctx:activeCampaignApiUrl}</apiUrl>
                  <apiKey>{$ctx:activeCampaignApiKey}</apiKey>
                  <apiOutput>json</apiOutput>
               </activecampaign.init>
               <activecampaign.createMessage>
                  <format>{$ctx:activeCampaignFormat}</format>
                  <subject>{$ctx:activeCampaignSubject}</subject>
                  <fromEmail>{$ctx:activeCampaignFromEmail}</fromEmail>
                  <fromName>{$ctx:activeCampaignFromName}</fromName>
                  <replyTo>{$ctx:activeCampaignReplyTo}</replyTo>
                  <priority>{$ctx:activeCampaignPriority}</priority>
                  <charset>{$ctx:activeCampaignCharset}</charset>
                  <encoding>{$ctx:activeCampaignEncoding}</encoding>
                  <htmlConstructor>{$ctx:activeCampaignHtmlConstructor}</htmlConstructor>
                  <html>{$ctx:activeCampaignHtml}</html>
                  <htmlFetch>{$ctx:activeCampaignHtmlFetch}</htmlFetch>
                  <htmlFetchWhen>{$ctx:activeCampaignHtmlFetchWhen}</htmlFetchWhen>
                  <textConstructor>editor</textConstructor>
                  <text>{$ctx:activeCampaignEmailTextContent}</text>
                  <textFetch>{$ctx:activeCampaignTextFetch}</textFetch>
                  <textFetchWhen>{$ctx:activeCampaignTextFetchWhen}</textFetchWhen>
                  <listIds>{$ctx:activeCampaignListIds}</listIds>
               </activecampaign.createMessage>
               <sequence key="removeResponseHeaders" />
               <property name="activeCamapignResultCode" expression="//jsonObject/result_code/text()" />
               <!-- Check Email message created. -->
               <filter xpath="get-property('activeCamapignResultCode') = 0">
                  <then>
                     <property name="id" expression="fn:concat('PlanCode :',get-property('recurlyPlanCode'))" />
                     <property name="status" value="Failed" />
                     <property name="message" expression="fn:concat('ActiveCampaign create message failed : ', //jsonObject/result_message/text())" />
                     <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="activecampaign_createCampaign" />
                        <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>
                  <else>
                     <property name="activeCampaignMessageId" expression="//jsonObject/id/text()" />
                     <!-- Set messageId parameter and set it to 100 percent and combine it with list details. -->
                     <script language="js">
                     <![CDATA[
                     
                        //Construct message and list deatils.
                        var payload = new Object();
                        var messageId = mc.getProperty("activeCampaignMessageId");
                        var listDetails = mc.getProperty("activeCampaignListIds");
                                                
                        payload = eval('(' + listDetails + ')');
                        payload ["m[" +messageId+"]"] = 100;
                       
                        mc.setPayloadJSON(payload);    
                     ]]>
                     </script>
                     <property name="activeCampaignListDetails" expression="json-eval($.)" />
                     <property name="activeCampaignSDate" 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:activeCampaignApiUrl}</apiUrl>
                        <apiKey>{$ctx:activeCampaignApiKey}</apiKey>
                        <apiOutput>json</apiOutput>
                     </activecampaign.init>
                     <activecampaign.createCampaign>
                        <type>{$ctx:activeCampaignType}</type>
                        <name>{$ctx:activeCampaignName}</name>
                        <sdate>{$ctx:activeCampaignSDate}</sdate>
                        <isStatusScheduled>1</isStatusScheduled>
                        <isPublic>{$ctx:activeCampaignIsPublic}</isPublic>
                        <trackLinks>{$ctx:activeCampaignTrackLinks}</trackLinks>
                        <listDetails>{$ctx:activeCampaignListDetails}</listDetails>
                     </activecampaign.createCampaign>
                     <sequence key="removeResponseHeaders" />
                     <property name="activeCamapignResultCode" expression="//jsonObject/result_code/text()" />
                     <!-- Check campaign created. -->
                     <filter xpath="get-property('activeCamapignResultCode') = 0">
                        <then>
                           <property name="id" expression="fn:concat('PlanCode:',get-property('recurlyPlanCode'),',MessageID:',get-property('activeCampaignMessageId'))" />
                           <property name="status" value="Failed" />
                           <property name="message" expression="//jsonObject/result_message/text()" />
                           <call-template target="responseHandlerTemplate">
                              <with-param name="activity" value="activeCampaign_createCampaign" />
                              <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>
                        <else>
                           <property name="activeCamapignCampaignId" expression="//jsonObject/id/text()" />
                           <property name="id"
                              expression="fn:concat('PlanCode:',get-property('recurlyPlanCode'),',MessageID:',get-property('activeCampaignMessageId'),',CampaignID:',get-property('activeCamapignCampaignId'))" />
                           <property name="status" value="Success" />
                           <property name="message" value="Campaign has been created successfully and scheduled to be sent." />
                           <call-template target="responseHandlerTemplate">
                              <with-param name="activity" value="activeCampaign_createCampaign" />
                              <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>
                  </else>
               </filter>
            </then>
            <else>
               <property name="id" expression="fn:concat('PlanCode:',get-property('recurlyPlanCode'))" />
               <property name="status" value="Failed" />
               <filter source="$axis2:HTTP_SC" regex="401">
                  <then>
                     <property name="message" value="Unauthorized API call" />
                     <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="recurly_createPlan" />
                        <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>
                  <else>
                     <property name="errorCount" expression="count(//error)" scope="operation" />
                     <property name="errorIndex" value="0" scope="operation" />
                     <iterate continueParent="true" id="accountDetailsIterator" preservePayload="true"
                        expression="//error" sequential="true">
                        <target>
                           <sequence>
                              <property name="errorField" expression="//error/@field" scope="operation" />
                              <property name="errorMessage" expression="//error/text()" scope="operation" />
                              <filter xpath="(get-property('operation', 'errorIndex')=0)">
                                 <then>
                                    <property name="message"
                                       expression="fn:concat(get-property('operation','errorField'),': ', get-property('operation','errorMessage'))"
                                       scope="operation" />
                                 </then>
                                 <else>
                                    <property name="message"
                                       expression="fn:concat(get-property('operation','message'),', ',get-property('operation','errorField'),': ', get-property('operation','errorMessage'))"
                                       scope="operation" />
                                 </else>
                              </filter>
                              <property name="errorIndex" expression="get-property('operation','errorIndex') + 1"
                                 scope="operation" />
                           </sequence>
                        </target>
                     </iterate>
                     <filter xpath="(get-property('operation', 'errorCount') = get-property('operation', 'errorIndex'))">
                        <then>
                           <property name="message" expression="get-property('operation','message')" />
                           <call-template target="responseHandlerTemplate">
                              <with-param name="activity" value="recurly_createPlan" />
                              <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>
                  </else>
               </filter>
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <payloadFactory media-type="json">
            <format>{ "Response":{ "process":"recurly_initiateSubscription", "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 a subscription plan in the Recurly API, and creating the email message to be used for the campaign in the ActiveCampaign API
{
  "recurlyApiUrl": "https://emobile.recurly.com",
  "recurlyApiKey": "91150438ccd84681b562e4d5995707e9",
  "recurlyPlanCode":"worldcup7",
  "recurlyPlanName":"World Cup",
  "recurlyUnitAmountInCents":[{"currencyCode":"USD","units":"6000"}],
  "recurlyDescription":"",
  "recurlyAccountingCode":"",
  "recurlyPlanIntervalUnit":"",
  "recurlyPlanIntervalLength":"",
  "recurlyTrialIntervalUnit":"",
  "recurlyTrialIntervalLength":"",
  "recurlySetupFeeInCents":"",
  "recurlyTotalBillingCycles":"",
  "recurlyUnitName":"",
  "recurlyDisplayQuantity":"",
  "recurlySuccessUrl":"",
  "recurlyCancelUrl":"",
  "recurlyTaxExempt":"",
  "recurlyTaxCode":"",
  "activeCampaignApiUrl": "https://acme731.api-us1.com",
  "activeCampaignApiKey": "13dbd00c11b8715001051d62e97c9bf5fe9aa33a3b06097d340aa30baf9366deac14cb2c",
  "activeCampaignFormat": "text",
  "activeCampaignFromEmail": "mobiletechnologypvtltd@gmail.com",
  "activeCampaignFromName": "ICB",
  "activeCampaignReplyTo": "mobiletechnologypvtltd@gmail.com",
  "activeCampaignPriority": "1",
  "activeCampaignCharset": "utf-8",
  "activeCampaignEncoding": "quoted-printable",
  "activeCampaignHtmlConstructor": "editor",
  "activeCampaignHtml": "Test",
  "activeCampaignHtmlFetch": "",
  "activeCampaignHtmlFetchWhen": "",
  "activeCampaignTextFetch": "",
  "activeCampaignTextFetchWhen": "",
  "activeCampaignListIds": {"p[1]": "1"},
  "activeCampaignType": "single",
  "activeCampaignName": "World Cup Campaign",
  "activeCampaignIsPublic": "1",
  "activeCampaignTrackLinks": "all"
}

Creating leads

  1. Retrieve campaign clickers from the ActiveCampaign API using the getCampaignClickers operation and create leads in the Base CRM API using the createLead operation.
  2. Leads should be converted to contacts in Base CRM, which is an offline process.
Base CRM operations
ActiveCampaign operations
Samples
Sample proxy for retrieving campaign clickers from ActiveCampaign API and creating leads in the Base CRM API
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="recurly_createLeadsInBaseCRM" transports="https,http"
   statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <!-- Active Campaign parameters. -->
         <property name="activeCampaignApiUrl" expression="json-eval($.activeCampaignApiUrl)" />
         <property name="activeCampaignApiKey" expression="json-eval($.activeCampaignApiKey)" />
         <property name="activeCampaignApiOutput" value="json" />
         <property name="activeCampaignCampaignId" expression="json-eval($.activeCampaignCampaignId)" />
         <property name="activeCampaignMessageId" expression="json-eval($.activeCampaignMessageId)" />
         <!-- Base CRM parameters. -->
         <property name="baseCRMApiUrl" expression="json-eval($.baseCRMApiUrl)" />
         <property name="baseCRMnLeadUrl" expression="json-eval($.baseCRMnLeadUrl)" />
         <property name="baseCRMEmail" expression="json-eval($.baseCRMEmail)" />
         <property name="baseCRMPassword" expression="json-eval($.baseCRMPassword)" />
         <!-- Workaround to eliminate the Host header issue in ActiveCampaign. -->
         <property name="Host" value="host.wso2.com" scope="transport" />
         <!-- Get campaign clickers. -->
         <activecampaign.init>
            <apiOutput>{$ctx:activeCampaignApiOutput}</apiOutput>
            <apiUrl>{$ctx:activeCampaignApiUrl}</apiUrl>
            <apiKey>{$ctx:activeCampaignApiKey}</apiKey>
         </activecampaign.init>
         <activecampaign.getCampaignClickers>
            <campaignId>{$ctx:activeCampaignCampaignId}</campaignId>
            <messageId>{$ctx:activeCampaignMessageId}</messageId>
         </activecampaign.getCampaignClickers>
         <sequence key="removeResponseHeaders" />
         <property name="noUniqueClickers" expression="count(//jsonObject/_JsonReader_PD_0/info)" scope="operation" />
         <property name="uniqueClickersIndex" value="0" scope="operation" />
         <!-- Check if there are unique clickers. -->
         <filter xpath="get-property('operation', 'noUniqueClickers') = 0">
            <then>
               <property name="id" expression="get-property('activeCampaignCampaignId')" />
               <property name="status" value="Failed" />
               <property name="message" expression="//jsonObject/result_message/text()" />
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="activecampaign_listCampaignClickers" />
                  <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>
            <else>
               <iterate continueParent="true" id="clicker" expression="//jsonObject/_JsonReader_PD_0/info"
                  sequential="true">
                  <target>
                     <sequence>
                        <property name="activeCampaingClickerEmail" expression="//info/email/text()" />
                        <!-- Workaround to eliminate the Host header issue in ActiveCampaign. -->
                        <property name="Host" value="host.wso2.com" scope="transport" />
                        <!-- Get clicker details. -->
                        <activecampaign.init>
                           <apiUrl>{$ctx:activeCampaignApiUrl}</apiUrl>
                           <apiKey>{$ctx:activeCampaignApiKey}</apiKey>
                           <apiOutput>{$ctx:activeCampaignApiOutput}</apiOutput>
                        </activecampaign.init>
                        <activecampaign.getContactByEmail>
                           <email>{$ctx:activeCampaingClickerEmail}</email>
                        </activecampaign.getContactByEmail>
                        <sequence key="removeResponseHeaders" />
                        <property name="activeCamapignResultCode" expression="//jsonObject/result_code/text()" />
                        <!-- Check clicker detail received successfully. -->
                        <filter xpath="get-property('activeCamapignResultCode') &gt; 0">
                           <then>
                              <property name="activeCampaingClickerID" expression="//jsonObject/id/text()" />
                              <property name="activeCampaingClickerFirstName" expression="//jsonObject/first_name/text()" />
                              <property name="activeCampaingClickerLastName" expression="//jsonObject/last_name/text()" />
                              <property name="activeCampaingClickerOrgName" expression="//jsonObject/orgname/text()" />
                              <property name="activeCampaingClickerPhone" expression="//jsonObject/phone/text()" />
                              <!-- Create lead for clicker. -->
                              <basecrm.init>
                                 <apiUrl>{$ctx:baseCRMApiUrl}</apiUrl>
                                 <email>{$ctx:baseCRMEmail}</email>
                                 <password>{$ctx:baseCRMPassword}</password>
                              </basecrm.init>
                              <basecrm.createLead>
                                 <leadServiceUrl>{$ctx:baseCRMnLeadUrl}</leadServiceUrl>
                                 <leadLastName>{$ctx:activeCampaingClickerLastName}</leadLastName>
                                 <leadCompanyName>{$ctx:activeCampaingClickerOrgName}</leadCompanyName>
                                 <leadFirstName>{$ctx:activeCampaingClickerFirstName}</leadFirstName>
                                 <leadEmail>{$ctx:activeCampaingClickerEmail}</leadEmail>
                                 <leadPhone>{$ctx:activeCampaingClickerPhone}</leadPhone>
                              </basecrm.createLead>
                              <sequence key="removeResponseHeaders" />
                              
                              <property name="baseCRMLeadCreationStatus" expression="//jsonObject/success/text()"
                                 scope="operation" />
                              <!-- Check weather the lead was created. -->
                              <filter xpath="get-property('operation', 'baseCRMLeadCreationStatus') = 'true'">
                                 <then>
                                    <property name="baseCRMLeadID" expression="//jsonObject/lead/id/text()" />
                                    <property name="id" expression="fn:concat('LeadID:',get-property('baseCRMLeadID'))" />
                                    <property name="status" value="Success" />
                                    <property name="message" value="Lead has been created successfully." />
                                    <call-template target="responseHandlerTemplate">
                                       <with-param name="activity" value="baseCRM_createLead" />
                                       <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>
                                     <filter source="$axis2:HTTP_SC" regex="401">
                                       <then>
                                          <property name="id" expression="fn:concat('Clicker ID:',get-property('activeCampaingClickerID'))" />
                                          <property name="status" value="Failed" />
                                          <property name="message" value="Unauthorized API call" />
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="baseCRM_createlead" />
                                             <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="id"
                                       expression="fn:concat('Clicker ID:',get-property('activeCampaingClickerID'))" />
                                    <property name="status" value="Failed" />
                                    <property name="message" value="Lead creation Failed." />
                                    <call-template target="responseHandlerTemplate">
                                       <with-param name="activity" value="baseCRM_createLead" />
                                       <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="id" expression="get-property('activeCampaingClickerEmail')" />
                              <property name="status" value="Failed" />
                              <property name="message" value="Clicker details not found." />
                              <call-template target="responseHandlerTemplate">
                                 <with-param name="activity" value="activeCampaing_getClicker" />
                                 <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>
                        <property name="uniqueClickersIndex" expression="get-property('operation','uniqueClickersIndex') + 1"
                           scope="operation" />
                     </sequence>
                  </target>
               </iterate>
               <filter
                  xpath="(get-property('operation', 'noUniqueClickers') = get-property('operation', 'uniqueClickersIndex'))">
                  <then>
                     <loopback />
                  </then>
               </filter>
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <payloadFactory media-type="json">
            <format>{ "Response":{ "process":"recurly_initiateSubscription", "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 API and creating leads in the Base CRM API
{
   "activeCampaignApiUrl":"https://acme731.api-us1.com",
   "activeCampaignApiKey":"13dbd00c11b8715001051d62e97c9bf5fe9aa33a3b06097d340aa30baf9366deac14cb2c",
   "activeCampaignCampaignId":"26",
   "activeCampaignMessageId":"32",
   "baseCRMApiUrl":"https://sales.futuresimple.com",
   "baseCRMnLeadUrl":"https://leads.futuresimple.com",
   "baseCRMEmail":"mobiletechnologypvtltd@gmail.com",
   "baseCRMPassword":"1qaz2wsx@"
}

Creating customers

  1. Retrieve the details of the contact from Base CRM using the getContactById operation. If contact does not exist, create them as accounts in the Recurly API using the createAccount operation and then create subscription for them.
  2. If contacts (accounts) exist then retrieve them from the Recurly API using the getAccountByCode operation and then create subscriptions for these accounts in the Recurly API using the createSubscription operation.
Base CRM operations
Recurly operations
Samples
Sample proxy for retrieving contacts from the Base CRM API and creating accounts in Recurly and creating subscriptions for those accounts
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="recurly_createCustomers" transports="https,http" statistics="disable"
   trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <!-- Base CRM parameters -->
         <property name="baseCRMApiUrl" expression="json-eval($.baseCRMApiUrl)" />
         <property name="baseCRMEmail" expression="json-eval($.baseCRMEmail)" />
         <property name="baseCRMPassword" expression="json-eval($.baseCRMPassword)" />
         <property name="baseCRMApiOutput" value="json" />
         <!-- Recurly parameters -->
         <property name="recurlyApiUrl" expression="json-eval($.recurlyApiUrl)" />
         <property name="recurlyApiKey" expression="json-eval($.recurlyApiKey)" />
         <property name="recurlyPlanCode" expression="json-eval($.recurlyPlanCode)" />
         <property name="recurlyCurrency" expression="json-eval($.recurlyCurrency)" />
         <property name="recurlyAccountCount" expression="count(//customerIds)" scope="operation" />
         <property name="accountIndex" value="0" scope="operation" />
         <!-- Check if there are contacts. -->
         <filter xpath="get-property('operation', 'recurlyAccountCount') = 0">
            <then>
               <property name="status" value="Failed" />
               <property name="message" value="No account details are found." />
               <call-template target="responseHandlerTemplate">
                  <with-param name="activity" value="recurly_createCustomers" />
                  <with-param name="status" value="{$ctx:status}" />
                  <with-param name="message" value="{$ctx:message}" />
               </call-template>
               <loopback />
            </then>
            <else>
               <iterate continueParent="true" id="accountDetailsIterator" preservePayload="true" expression="//customerIds"
                  sequential="true">
                  <target>
                     <sequence>
                        <property name="recurlyAccountCode" expression="//customerIds/text()" />
                        <filter xpath="boolean(get-property('recurlyAccountCode'))">
                           <then>
                              <property name="messageType" value="application/xml" scope="axis2" />
                              <!-- Get account details. -->
                              <recurly.init>
                                 <apiUrl>{$ctx:recurlyApiUrl}</apiUrl>
                                 <apiKey>{$ctx:recurlyApiKey}</apiKey>
                              </recurly.init>
                              <recurly.getAccountByCode>
                                 <accountCode>{$ctx:recurlyAccountCode}</accountCode>
                              </recurly.getAccountByCode>
                              <sequence key="removeResponseHeaders" />
                              <!-- Check account exists. -->
                              <filter source="$axis2:HTTP_SC" regex="404">
                                 <then>
                                    <property name="messageType" value="application/json" scope="axis2" />
                                    <!-- Get contact details. -->
                                    <basecrm.init>
                                       <email>{$ctx:baseCRMEmail}</email>
                                       <responseType>json</responseType>
                                       <apiUrl>{$ctx:baseCRMApiUrl}</apiUrl>
                                       <password>{$ctx:baseCRMPassword}</password>
                                    </basecrm.init>
                                    <basecrm.getContactById>
                                       <contactId>{$ctx:recurlyAccountCode}</contactId>
                                    </basecrm.getContactById>
                                    <sequence key="removeResponseHeaders" />
                                    <!-- Check contact exists. -->
                                    <filter source="$axis2:HTTP_SC" regex="200">
                                       <then>
                                          <property name="baseCRMContactEmail" expression="//jsonObject/contact/email/text()" />
                                          <property name="baseCRMContactFirstName" expression="//jsonObject/contact/first_name/text()" />
                                          <property name="baseCRMContactLastName" expression="//jsonObject/contact/last_name/text()" />
                                          <property name="baseCRMContactOrgName" expression="//jsonObject/contact/organisation_name/text()" />
                                          <property name="baseCRMContactAddress"
                                             expression="//jsonObject/contact/sales_account/billing_address/street/text()" />
                                          <property name="baseCRMContactCity"
                                             expression="//jsonObject/contact/sales_account/billing_address/city/text()" />
                                          <property name="baseCRMContactState"
                                             expression="//jsonObject/contact/sales_account/billing_address/region/text()" />
                                          <property name="baseCRMContactCountry"
                                             expression="//jsonObject/contact/sales_account/billing_address/country/text()" />
                                          <property name="baseCRMContactZip"
                                             expression="//jsonObject/contact/sales_account/billing_address/zip/text()" />
                                          <property name="baseCRMContactDesc" expression="//jsonObject/contact/description/text()" />
                                          <property name="baseCRMPhone" expression="//jsonObject/contact/phone/text()" />
                                          <!-- Getting card number. -->
                                          <property name="baseCRMContactCardNumber"
                                             expression="fn:substring(fn:substring-after(get-property('baseCRMContactDesc'),'Card Number :'),1,19)" />
                                          <!-- Create billingInfo string for account. -->
                                          <property name="recurlyBillingInfo"
                                             expression="fn:concat('&lt;values&gt;&lt;first_name&gt;',
                                             get-property('baseCRMContactFirstName'),'&lt;/first_name&gt;&lt;last_name&gt;',get-property('baseCRMContactLastName'),
                                             '&lt;/last_name&gt;&lt;address1&gt;',get-property('baseCRMContactAddress'),'&lt;/address1&gt;&lt;city&gt;',
                                             get-property('baseCRMContactCity'),'&lt;/city&gt;&lt;state&gt;',get-property('baseCRMContactState'),'&lt;/state&gt;&lt;country&gt;',
                                             get-property('baseCRMContactCountry'),'&lt;/country&gt;&lt;zip&gt;',get-property('baseCRMContactZip'),'&lt;/zip&gt;&lt;number&gt;',
                                             get-property('baseCRMContactCardNumber'),'&lt;/number&gt;&lt;phone&gt;',get-property('baseCRMPhone'),'&lt;/phone&gt;&lt;/values&gt;')" />
                                          <property name="messageType" value="application/xml" scope="axis2" />
                                          <!-- Create account. -->
                                          <recurly.init>
                                             <apiUrl>{$ctx:recurlyApiUrl}</apiUrl>
                                             <apiKey>{$ctx:recurlyApiKey}</apiKey>
                                          </recurly.init>
                                          <recurly.createAccount>
                                             <accountCode>{$ctx:recurlyAccountCode}</accountCode>
                                             <email>{$ctx:baseCRMContactEmail}</email>
                                             <firstName>{$ctx:baseCRMContactFirstName}</firstName>
                                             <lastName>{$ctx:baseCRMContactLastName}</lastName>
                                             <companyName>{$ctx:baseCRMContactOrgName}</companyName>
                                             <billingInfo>{$ctx:recurlyBillingInfo}</billingInfo>
                                          </recurly.createAccount>
                                          <sequence key="removeResponseHeaders" />
                                          <!-- Check weather the account was created. -->
                                          <filter source="$axis2:HTTP_SC" regex="201">
                                             <then>
                                                <property name="recurlyAccountDetail"
                                                   expression="fn:concat('&lt;values&gt;&lt;account_code&gt;',get-property('recurlyAccountCode'))" />
                                                <property name="recurlyAccountDetail"
                                                   expression="fn:concat(get-property('recurlyAccountDetail'),'&lt;/account_code&gt;&lt;/values&gt;')" />
                                                <property name="messageType" value="application/xml" scope="axis2" />
                                                <!-- Create subscription. -->
                                                <recurly.init>
                                                   <apiUrl>{$ctx:recurlyApiUrl}</apiUrl>
                                                   <apiKey>{$ctx:recurlyApiKey}</apiKey>
                                                </recurly.init>
                                                <recurly.createSubscription>
                                                   <currency>{$ctx:recurlyCurrency}</currency>
                                                   <planCode>{$ctx:recurlyPlanCode}</planCode>
                                                   <account>{$ctx:recurlyAccountDetail}</account>
                                                </recurly.createSubscription>
                                                <sequence key="removeResponseHeaders" />
                                                <!-- Check subscription created. -->
                                                <filter source="$axis2:HTTP_SC" regex="201">
                                                   <then>
                                                      <property name="id"
                                                         expression="fn:concat('AcountCode:',get-property('recurlyAccountCode'))" />
                                                      <property name="status" value="Success" />
                                                      <property name="message"
                                                         value="Account created and subscribed successfully" />
                                                      <call-template target="responseHandlerTemplate">
                                                         <with-param name="activity" value="recurly_addSubscription" />
                                                         <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('AcountCode:',get-property('recurlyAccountCode'))" />
                                                      <property name="status" value="Failed" />
                                                      <filter source="$axis2:HTTP_SC" regex="400">
                                                         <then>
                                                            <property name="message" expression="//error/description/text()" />
                                                         </then>
                                                         <else>
                                                            <filter source="$axis2:HTTP_SC" regex="422">
                                                               <then>
                                                                  <property name="message" value="" />
                                                                  <property name="errors" expression="//errors/self::*" />
                                                                  <payloadFactory media-type="xml">
                                                                     <format>
                                                                        <errorList xmlns="">$1</errorList>
                                                                     </format>
                                                                     <args>
                                                                        <arg expression="get-property('errors')" />
                                                                     </args>
                                                                  </payloadFactory>
                                                                  <script language="js">
                                                                  <![CDATA[
                                                                     var payload = mc.getPayloadXML();
                                                                     var errors = payload.errors;
                                                                     var message="";
                                                                     for (i = 0; i < errors.error.length(); i++) { 
                                                                        var field = errors.error[i].@field;
                                                                        var value = errors.error[i];
                                                                        message = message + field + " " + value +", " ;
                                                                     }
                                                                     message = message.substring(0, message.length - 2);
                                                                     mc.setProperty("message",message);
                                                                  ]]>
                                                                  </script>
                                                               </then>
                                                               <else>
                                                                  <property name="message"
                                                                     value="Subscription creation failed." />
                                                               </else>
                                                            </filter>
                                                         </else>
                                                      </filter>
                                                      <call-template target="responseHandlerTemplate">
                                                         <with-param name="activity" value="recurly_addSubscription" />
                                                         <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="id"
                                                   expression="fn:concat('AcountCode:',get-property('recurlyAccountCode'))" />
                                                <property name="status" value="Failed" />
                                                <property name="message" value="Creating account failed." />
                                                <call-template target="responseHandlerTemplate">
                                                   <with-param name="activity" value="recurly_createAccount" />
                                                   <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>
                                          <filter source="$axis2:HTTP_SC" regex="401">
                                             <then>
                                                <property name="id" expression="fn:concat('AccountCode:',get-property('recurlyAccountCode'))" />
                                                <property name="status" value="Failed" />
                                                <property name="message" value="Unauthorized API call" />
                                                <call-template target="responseHandlerTemplate">
                                                   <with-param name="activity" value="baseCRM_getContact" />
                                                   <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="id"
                                             expression="fn:concat('AcountCode:',get-property('recurlyAccountCode'))" />
                                          <property name="status" value="Failed" />
                                          <property name="message" value="No contact details are found." />
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="baseCRM_getContact" />
                                             <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>
                                    <!-- Create Account string for Subscription. -->
                                    <property name="recurlyAccountDetail"
                                       expression="fn:concat('&lt;values&gt;&lt;account_code&gt;',get-property('recurlyAccountCode'))" />
                                    <property name="recurlyAccountDetail"
                                       expression="fn:concat(get-property('recurlyAccountDetail'),'&lt;/account_code&gt;&lt;/values&gt;')" />
                                    <property name="messageType" value="application/xml" scope="axis2" />
                                    <!-- Create Subscription. -->
                                    <recurly.init>
                                       <apiUrl>{$ctx:recurlyApiUrl}</apiUrl>
                                       <apiKey>{$ctx:recurlyApiKey}</apiKey>
                                    </recurly.init>
                                    <recurly.createSubscription>
                                       <currency>{$ctx:recurlyCurrency}</currency>
                                       <planCode>{$ctx:recurlyPlanCode}</planCode>
                                       <account>{$ctx:recurlyAccountDetail}</account>
                                    </recurly.createSubscription>
                                    <sequence key="removeResponseHeaders" />
                                    <!-- Check subscription created. -->
                                    <filter source="$axis2:HTTP_SC" regex="201">
                                       <then>
                                          <property name="id"
                                             expression="fn:concat('AcountCode:',get-property('recurlyAccountCode'))" />
                                          <property name="status" value="Success" />
                                          <property name="message" value="Subscription has been created successfully" />
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="recurly_addSubscription" />
                                             <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('AcountCode:',get-property('recurlyAccountCode'))" />
                                          <property name="status" value="Failed" />
                                          <filter source="$axis2:HTTP_SC" regex="400">
                                             <then>
                                                <property name="message" expression="//error/description/text()" />
                                             </then>
                                             <else>
                                                <filter source="$axis2:HTTP_SC" regex="422">
                                                   <then>
                                                      <property name="message" value="" />
                                                      <property name="errors" expression="//errors/self::*" />
                                                      <payloadFactory media-type="xml">
                                                         <format>
                                                            <errorList xmlns="">$1</errorList>
                                                         </format>
                                                         <args>
                                                            <arg expression="get-property('errors')" />
                                                         </args>
                                                      </payloadFactory>
                                                      <script language="js">
                                                      <![CDATA[
                                                         var payload = mc.getPayloadXML();
                                                         var errors = payload.errors;
                                                         var message="";
                                                         for (i = 0; i < errors.error.length(); i++) { 
                                                            var field = errors.error[i].@field;
                                                            var value = errors.error[i];
                                                            message = message + field + " " + value +", " ;
                                                         }
                                                         message = message.substring(0, message.length - 2);
                                                         mc.setProperty("message",message);
                                                      ]]>
                                                      </script>
                                                   </then>
                                                   <else>
                                                      <property name="message" value="Subscription creation failed." />
                                                   </else>
                                                </filter>
                                             </else>
                                          </filter>
                                          <call-template target="responseHandlerTemplate">
                                             <with-param name="activity" value="recurly_addSubscription" />
                                             <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>
                           <else>
                              <property name="id" expression="fn:concat('AcountCode:',get-property('recurlyAccountCode'))" />
                              <property name="status" value="Failed" />
                              <property name="message" value="Account code not provided." />
                              <call-template target="responseHandlerTemplate">
                                 <with-param name="activity" value="recurly_createAccount" />
                                 <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>
                        <property name="accountIndex" expression="get-property('operation','accountIndex') + 1"
                           scope="operation" />
                     </sequence>
                  </target>
               </iterate>
               <filter xpath="(get-property('operation', 'recurlyAccountCount') = get-property('operation', 'accountIndex'))">
                  <then>
                     <loopback />
                  </then>
               </filter>
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <payloadFactory media-type="json">
            <format>{ "Response":{ "process":"recurly_initiateSubscription", "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 contacts from the Base CRM API and creating accounts in Recurly and creating subscriptions for those accounts
{
  "baseCRMApiUrl": "https://sales.futuresimple.com",
  "baseCRMnLeadUrl": "https://leads.futuresimple.com",
  "baseCRMEmail": "testapp.mahesh2@gmail.com",
  "baseCRMPassword": "Colombo1",
  
  "recurlyApiUrl": "https://virtusax.recurly.com",
  "recurlyApiKey": "09da0279537848789809f1f86e349afb",
  "recurlyPlanCode":"worldcup4",
  "recurlyCurrency":"USD",
  "customerIds": ["81362861","82565888"]
}
Â