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

Process Monitoring in eBay

The second use case in the  eBay business scenario is process monitoring. This page describes the related tasks and the operations you use in the eBay connector and the other ESB connectors. 

Overview

The flow for process monitoring is illustrated in the following diagram. The ESB connectors for TradeGecko and Campaign Monitor will be used to connect to each service. 

  1. First, let's monitor sold items. Retrieve details of selling status "Sold Items" from eBay using the getMyeBaySelling operation. This operation retrieves information on the quantity sold and the buyer's name and email address. The sold items retrieved are for the specified day.
  2. In TradeGecko, update the stock details (quantity) retrieved from eBay using the  createStockAdjustment operation.      
  3. In Campaign Monitor, feed the buyer's contact details retrieved from eBay into campaigns as subscriptions using the addSubscribersToLists operation in order to subscribe for future campaign drafts. 
  4. Now, let's monitor active items. Retrieve details of selling status "Active Items" from eBay using the getMyeBaySelling operation, after which you can retrieve the unsold items using the getItem  operation. Items are considered unsold when the whole listed item quantity sold is '0'. (For example, Listed items Quantity = 10, Available Quantity = 10, and Sold Quantity = 0).
  5. In Campaign Monitor, create a campaign for all those unsold items using the createCampaignFromTemplate operation.
TradeGecko operations
eBay operations
Campaign Monitor operations
Sample Proxy for Monitoring Sold Items
<?xml version="1.0" encoding="UTF-8" ?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ebay_retrieveAndUpdateSoldListItemsStocks" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
    <target>
        <inSequence onError="faultHandlerSeq">
            <!--eBay Trading related properties-->
            <property name="ebayApiUrl" expression="json-eval($.ebayApiUrl)"/>
			<property name="ebayAppId" expression="json-eval($.ebayAppId)"/>
			<property name="ebayVersion" expression="json-eval($.ebayVersion)"/>
			<property name="ebayRouting" expression="json-eval($.ebayRouting)"/>
			<property name="ebaySiteId" expression="json-eval($.ebaySiteId)"/>
			<property name="ebayAuthToken" expression="json-eval($.ebayAuthToken)"/>
			<property name="ebayMessageId" expression="json-eval($.ebayMessageId)"/>
			<property name="ebayErrorLanguage" expression="json-eval($.ebayErrorLanguage)"/>
			<property name="ebayWarningLevel" expression="json-eval($.ebayWarningLevel)"/>			
			<!--Tradegecko related properties-->
			<property name="tradegeckoApiUrl" expression="json-eval($.tradegeckoApiUrl)"/>
			<property name="tradegeckoAccessToken" expression="json-eval($.tradegeckoAccessToken)"/>
			<property name="tradegeckoAdjustmentNumber" expression="json-eval($.tradegeckoAdjustmentNumber)"/>
			<property name="tradegeckoNotes" expression="json-eval($.tradegeckoNotes)"/>
			<property name="tradegeckoReason" expression="json-eval($.tradegeckoReason)"/>
			<property name="tradegeckoStockLocationId" expression="json-eval($.tradegeckoStockLocationId)"/>			
			<!-- Campaign Monitor related properties -->
			<property name="cmAccessToken" expression="json-eval($.cmAccessToken)"/>
			<property name="cmApiUrl" expression="json-eval($.cmApiUrl)"/>
			<property name="cmListId" expression="json-eval($.cmListId)"/>			
			<!-- Mapping list of the Tradegecko product variants with eBay item Ids. -->
			<property name="itemsMap" expression="json-eval($.itemsMap)"/>
            <script language="js">
				 var currentDate=new Date();
				 var currentday=""+currentDate.getDate();
				 if(currentday.length==1){
					currentday="0"+currentday;
				 }
				 var dateString=currentDate.getFullYear() + "-" + Number(currentDate.getMonth()+1) + "-" + currentday ;
				 mc.setProperty('currentTime', dateString);
		 	</script>		 	
		 	<payloadFactory media-type="xml">
		        <format>
						<ebl:ebaySoldList xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
							<ebl:values>
								<ebl:Include>true</ebl:Include>
								<ebl:IncludeNotes>true</ebl:IncludeNotes>
							</ebl:values>
						</ebl:ebaySoldList>
				</format>
        	</payloadFactory>         
         	<property name="ebaySoldList" expression="//ebl:ebaySoldList/*"  xmlns:ebl="urn:ebay:apis:eBLBaseComponents"/>			
			<!--Call eBay getMyEbaySellig method to retrieve sold items-->
			<ebay.init-trading>
				<apiUrl>{$ctx:ebayApiUrl}</apiUrl>
				<appId>{$ctx:ebayAppId}</appId>
				<routing>{$ctx:ebayRouting}</routing>
				<authToken>{$ctx:ebayAuthToken}</authToken>
				<siteId>{$ctx:ebaySiteId}</siteId>
				<warningLevel>{$ctx:ebayWarningLevel}</warningLevel>
				<messageId>{$ctx:ebayMessageId}</messageId>
				<errorLanguage>{$ctx:ebayErrorLanguage}</errorLanguage>
				<version>{$ctx:ebayVersion}</version>
			</ebay.init-trading>
			<ebay.getMyeBaySelling>
				<soldList>{$ctx:ebaySoldList}</soldList>
			</ebay.getMyeBaySelling> 
<property name="ack" expression="//ebl:Ack"  xmlns:ebl="urn:ebay:apis:eBLBaseComponents"/>
            <filter source="boolean(get-property('ack'))" regex="Failure">
                <then>
                    <property name="messageType" value="application/json" scope="axis2"/>
					<property name="status" expression="get-property('ack')" />
					<property name="message" expression="json-eval($.Envelope.Body.)" />					
					<call-template target="responseHandlerTemplate">
						<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>			
			<!--Operation scoped Properties to keep track of Global Parameters.-->
           <property name="buyersCount" expression="count(//ebl:OrderTransactionArray/ebl:OrderTransaction)" 
						xmlns:ebl="urn:ebay:apis:eBLBaseComponents" scope="operation" />	
		   <property name="transactionCount" expression="0" scope="operation" />
			<property name="transactionIndex" expression="0" scope="operation" />			
           <property name="stockAdjustmentLineItems" value="" scope="operation" />
           <property name="subscribers" value="" scope="operation" />
		   <property name="transactionIds" value="" scope="operation"/>        
		   <filter xpath="get-property('operation','buyersCount' ) = 0">
			<then>
				<property name="id" value="" />
				<property name="status" value="Skipped" />
				<property name="message" value="No transaction(s) found." />				
				<call-template target="responseHandlerTemplate">
					<with-param name="activity" value="campaignMonitor_addSubscribersToList" />
					<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>
			 <!--FOR EACH SoldItems : BEGIN-->
            <iterate continueParent="true" id="buyers" expression="//ebl:OrderTransactionArray/ebl:OrderTransaction"
					sequential="true" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" >
	            <target>
		            <sequence>					
						<!--Extract SoldListItem Details from the Message.-->
						<property name="userId" expression="//ebl:Transaction[1]/ebl:Buyer/ebl:UserID/text()" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" />
						<property name="buyerEmail" expression="//ebl:Transaction[1]/ebl:Buyer/ebl:Email/text()" xmlns:ebl="urn:ebay:apis:eBLBaseComponents"/>
						
						<!--Concatenate and build the subscribers array.-->
						<property name="subscribers" expression="fn:concat(get-property('operation','subscribers'), '{ &quot;EmailAddress&quot; : &quot;', get-property('buyerEmail'), '&quot; , &quot;Name&quot; : &quot;', get-property('userId'), '&quot; },')" scope="operation" />
												
						<property name="transactionCount" expression="get-property('operation','transactionCount') + count(//ebl:Transaction)" scope="operation"/>
								
								<iterate continueParent="true" id="transactions" expression="//ebl:Transaction" sequential="true" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" >
									<target>
										<sequence>
											<property name="transactionCreatedDateTemp" expression="//ebl:Transaction/ebl:CreatedDate/text()"  xmlns:ebl="urn:ebay:apis:eBLBaseComponents"/>
											<property name="transactionCreatedDate" expression="fn:substring-before(get-property('transactionCreatedDateTemp'),'T')"  xmlns:ebl="urn:ebay:apis:eBLBaseComponents"/>
										
											<filter xpath="get-property('currentTime' ) = get-property('transactionCreatedDate')">
												<then>
													<property name="currentTransactionId" expression="//ebl:TransactionID/text()" xmlns:ebl="urn:ebay:apis:eBLBaseComponents"/>
													<property name="transactionIds" expression="fn:concat(get-property('operation','transactionIds'), get-property('currentTransactionId'), ',')" scope="operation"/>
													
													<property name="itemId" expression="//ebl:ItemID/text()" xmlns:ebl="urn:ebay:apis:eBLBaseComponents"/>
													<property name="quantitySold" expression="//ebl:QuantityPurchased/text()" xmlns:ebl="urn:ebay:apis:eBLBaseComponents"/>
															
															<script language="js">
																<![CDATA[
																	var itemId = mc.getProperty('itemId');
																	var itemsMap = eval("(" + mc.getProperty('itemsMap') + ")");
																	var varientId = "";
																	varientId = itemsMap[itemId];
											
																	mc.setProperty("varientId", varientId); 
																]]>
															</script>
													
													<property name="stockAdjustmentLineItems" expression="fn:concat(get-property('operation','stockAdjustmentLineItems'), '{ &quot;quantity&quot; : -', get-property('quantitySold'), ' , &quot;variant_id&quot; : &quot;', get-property('varientId'), '&quot; },')" scope="operation" />
												</then>
											</filter>	
											<property name="transactionIndex" expression="get-property('operation','transactionIndex') + 1" scope="operation" />											
											<property name="transactionCount" expression="get-property('operation','transactionCount')"/>
											<property name="transactionIndex" expression="get-property('operation','transactionIndex')"/>											
										</sequence>
									</target>
								</iterate>								
		            </sequence>
	            </target>
            </iterate>
			<!--FOR EACH SoldItems : END-->
			<filter xpath="get-property('operation','transactionCount') = get-property('operation','transactionIndex')">
 <then>
					<property name="subscribers" expression="fn:substring(get-property('operation','subscribers'), 1, fn:string-length(get-property('operation','subscribers'))-1)" />
					<property name="id" expression="fn:substring(get-property('operation','transactionIds'), 1, fn:string-length(get-property('operation','transactionIds'))-1)" />
					<property name="id" expression="fn:concat('{transaction_ids:[',get-property('id'),']}')"/>
<payloadFactory media-type="json">
						<format>
							{
								"subscribers": [$1]
							}
						</format>
						<args>
							<arg expression="get-property('subscribers')" />
						</args>
		            </payloadFactory>		            
		            <property name="cmSubscribers" expression="json-eval($.subscribers)" />					
					<filter source="boolean(get-property('subscribers'))" regex="true">
						<then>
					<property name="messageType" value="application/json" scope="axis2" />
							<!-- Call Campaign Monitor addSubscriberToList method to import buyers contact information -->
							<campaignmonitor.init>
								<accessToken>{$ctx:cmAccessToken}</accessToken>
								<apiUrl>{$ctx:cmApiUrl}</apiUrl>
							</campaignmonitor.init>
							<campaignmonitor.addSubscribersToList>
								<listId>{$ctx:cmListId}</listId>
								<subscribers>{$ctx:cmSubscribers}</subscribers>
								<resubscribe>true</resubscribe>
								<queueSubscriptionBasedAutoResponders>true</queueSubscriptionBasedAutoResponders>
								<restartSubscriptionBasedAutoresponders>true</restartSubscriptionBasedAutoresponders>
							</campaignmonitor.addSubscribersToList>
							<property name="totalUniqueEmailsSubmitted" expression="json-eval($.TotalUniqueEmailsSubmitted)" />
							<filter source="boolean(get-property('totalUniqueEmailsSubmitted'))" regex="true">
							   <then>
									<property name="status" value="Success" />
									<property name="message" expression="json-eval($.)" />
							   </then>
							   <else>
									<property name="status" value="Error" />
									<property name="message" expression="json-eval($.)"  />
							   </else>
							</filter>
						</then>
						<else>
							<property name="status" value="Skipped" />
							<property name="message" value="No Subscriber(s) to add." />
						</else>
					</filter>
					<call-template target="responseHandlerTemplate">
						<with-param name="activity" value="campaignMonitor_addSubscribersToList" />
						<with-param name="id" value="{$ctx:id}" />
						<with-param name="status" value="{$ctx:status}" />
						<with-param name="message" value="{$ctx:message}" />
					</call-template>					
					<property name="stockAdjustmentLineItems" expression="fn:substring(get-property('operation','stockAdjustmentLineItems'), 1, fn:string-length(get-property('operation','stockAdjustmentLineItems'))-1)" />
					
					<payloadFactory media-type="json">
						<format>
							{
								"StockAdjustmentLineItemsArray": [$1]
							}
						</format>
						<args>
							<arg expression="get-property('stockAdjustmentLineItems')" />
						</args>
					</payloadFactory>					
					<property name="tradegeckoStockAdjustmentLineItems" expression="json-eval($.StockAdjustmentLineItemsArray)"/>				
					<filter source="boolean(get-property('stockAdjustmentLineItems'))" regex="true">
						<then>
							<!-- Call Tradegecko createStockAdjustment method -->
							<property name="messageType" value="application/json" scope="axis2" />
							<tradegecko.init>
								<apiUrl>{$ctx:tradegeckoApiUrl}</apiUrl>
								<accessToken>{$ctx:tradegeckoAccessToken}</accessToken>
							</tradegecko.init>
							<tradegecko.createStockAdjustment>
								<adjustmentNumber>{$ctx:tradegeckoAdjustmentNumber}</adjustmentNumber>
								<notes>{$ctx:tradegeckoNotes}</notes>
								<reason>{$ctx:tradegeckoReason}</reason>
								<stockAdjustmentLineItems>{$ctx:tradegeckoStockAdjustmentLineItems}</stockAdjustmentLineItems>
								<stockLocationId>{$ctx:tradegeckoStockLocationId}</stockLocationId>
							</tradegecko.createStockAdjustment>							
						<property name="stockAdjustmentsResult" expression="json-eval($.stock_adjustment)" />
						<filter source="boolean(get-property('stockAdjustmentsResult'))" regex="true">
						   <then>
								<property name="status" value="Success" />
								<property name="message" value="Item stock adjustment added successfully." />
						   </then>
						   <else>
								<filter source="$axis2:HTTP_SC" regex="401">
									<then>
										<property name="status" value="Error" />
										<property name="message" value="Invalid access token."  />
									</then>
									<else>
										<property name="status" value="Error" />
										<property name="message" expression="json-eval($.)"  />
									</else>
								</filter>
						   </else>
						</filter>						
						</then>
						<else>
							<property name="status" value="Skipped" />
							<property name="message" value="No Stock Adjustments" />
						</else>
					</filter>							
					<call-template target="responseHandlerTemplate">
						<with-param name="activity" value="tradegecko_stockAdjustment" />
						<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>
        </inSequence>
        <outSequence>
          <property name="messageType" value="application/json" scope="axis2" />
            <payloadFactory media-type="json">
            <format>
				{
					"Response":{
						"process":"ebay_retrieveAndUpdateSoldItemsStocks",
						"activityResponse":[$1]
					}
				}
			</format>
            <args>
                <arg expression="get-property('operation', 'responseString')"/>
            </args>
        </payloadFactory>
         <send/>
        </outSequence>
    </target>
    <description/>
</proxy>					
                                                              
Sample Request for Monitoring Sold Items
 {
    "ebayApiUrl": "https://api.sandbox.ebay.com/wsapi",
    "ebayAppId": "Virtusa37-a57a-43a3-8f97-fa1e9e2f195",
    "ebayVersion": "843",
    "ebayRouting": "default",
    "ebaySiteId": "203",
    "ebayAuthToken": "AgAAAA**AQAAAA**aAAAAA**lXzgUw**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wFk4GhDJWLowmdj6x9nY+seQ**VPkCAA**AAMAAA**x9umxS4e6RYDx2DT56ufBcZ+QI+deNI4+Eb78MmDsW57egJgGVTx7vUXRygKTlIQOmNbMyh4cNSwAYFz2q896JZ5f5xxjInZiJqPk+rlmgvN3rqgKYDSS4t0tjmD/UrcPXGYeqNViZIvyYWq0SW67wsvNQTI0IAr3h6So3QcTOR9NPr+lKgQixYzWPrP2Xuy+XkuGraWP5zcNOF0hrKu9iUmSYO8/DgfhGXsfBsamGDTh3vRlltEcDzKNV4RznNudC/eBt4cmB271EppOT16N7NaYXoQ0zwiBZHOrsYvOm3ae36Rjbdo/k94Nd61gBSbnt3U2QFn6I9D2pZ1FFATMXiCiPoXPL2v20f+ZzZX0cTostBZmYDJn1XwiXAnFH+km7Emb91atesP1F22nmzKbP4hIJch86Ll515/wsoVPf7AMxwtUn0s75jeqX/LGpQUSXLL0JPQZPWpanz1q58r+7NwQza9fGHPHzia3kfVd+11UnTomxK1U66IVPmVeyyVe7z9vYTqvD+PzKVCWFqLMooa/Q1KjwbHcFsOnBTGLnoLTqK21t6GQsmkbPnYrNiWpfzd+NGWG/3WajNn7nTtvOS1MBFBaJm2sw6SqAxuINSPv1Rr/8o4W7YWJdN6YiB7VbY/Xml6dO+GF47ePQm1x4su5DrrgpVc9H3FwqpJEE+XJ2qlY2OfrguxGbQK/Xqr85ExXujxxDb/YIbOnHCKi+DNfjO9Z4Nbv6QZHsXbopl9UbPqj0zHhbdvM8dUh8BJ",
    "ebayMessageId": "",
    "ebayErrorLanguage": "en_US",
    "ebayWarningLevel": "",
    "ebaySoldList": {
        "Include": "true",
        "IncludeNotes": "true"
    },
    "itemsMap": {
        "110153633522": "3882476",
        "110153633523": "3882500"
    },
    "tradegeckoApiUrl": "https://api.tradegecko.com",
    "tradegeckoAccessToken": "77bbe0db8f906c3cd29c680616d0d7a700422ba5c7063282beb00594540c0641",
    "tradegeckoAdjustmentNumber": "123",
    "tradegeckoNotes": "sold item stock adjustment",
    "tradegeckoReason": "shrinkage",
    "tradegeckoStockLocationId": "1",
    "cmAccessToken": "AdDDpeowRVtNg5xdWG7bQRsxOA==",
    "cmApiUrl": "https://api.createsend.com",
    "cmListId": "b66a0dd588113232acc2b04e6ae454c8"
}
Sample Template for Creating a Campaign in Campaign Monitor and Creating a Wall Post in Facebook According to the Given Access Token of Campaign Monitor and Facebook with Other Parameters
<?xml version="1.0" ?>
<!-- This template is responsible for creating a campaign in Campaign Monitor and creating a wall post in Facebook 
     according to the given access token of Campaign Monitor & Facebook with other parameters. -->
<template name="ebay-publishItemDetailsOnSocialMedia" xmlns="http://ws.apache.org/ns/synapse">
	<!-- Campaign Monitor related template parameters. -->
	<parameter name="cmApiUrl" description="The API URL of Campaign Monitor." />
	<parameter name="cmAccessToken" description="The access token to authorize the requests to Campaign Monitor." />
	<parameter name="cmClientId" description="The ID of the client for whom the campaign should be created." />
	<parameter name="cmName" description="The name of the campaign." />
	<parameter name="cmSubject" description="The subject of the campaign." />
	<parameter name="cmFromName" description="The campaign sender's name." />
	<parameter name="cmFromEmail" description="The campaign sender's email." />
	<parameter name="cmReplyTo" description="The email address to reply for the campaign." />
	<parameter name="cmListIds" description="The list of subscriber IDs." />
	<parameter name="cmSegmentIds" description="The list of segment IDs." />
	<parameter name="cmTemplateId" description="The ID of the template." />
	<parameter name="cmTemplateContent" description="The content of the campaign template." />
	<!-- Facebook related template parameters. -->
	<parameter name="fbApiUrl" description="The API URL of Facebook." />
	<parameter name="fbAccessToken" description="The access token which provides temporary, secure access to Facebook APIs." />
	<parameter name="fbConnection" description="The connection which belongs to an object." />
	<parameter name="fbMessageBody" description="The main message body of the post." />
	<parameter name="fbLink" description="The URL of a link to attach to the post." />
	<parameter name="fbPicture" description="Determines the preview image associated with the link." />
	<parameter name="fbName" description="Overwrites the title of the link preview." />
	<parameter name="fbCaption" description="Overwrites the caption under the title in the link preview." />
	<parameter name="fbDescription" description="Overwrites the description in the link preview." />
	<parameter name="fbActions" description="The action links attached to the post." />
	<parameter name="fbPlace" description="Page ID of a location associated with this post." />
	<parameter name="fbTags" description="The list of user IDs of people tagged in this post." />
	<parameter name="fbPrivacy" description="Determines the privacy settings of the post." />
	<parameter name="fbObjectAttachment" description="Facebook ID for an existing picture in the person's photo albums to be used as the thumbnail image." />
    <sequence>
		<!-- Campaign Monitor related template properties. -->
		<property name="uri.var.cmApiUrl" expression="$func:cmApiUrl"/>
		<property name="uri.var.cmAccessToken" expression="$func:cmAccessToken"/>
		<property name="uri.var.cmClientId" expression="$func:cmClientId"/>
		<property name="uri.var.cmName" expression="$func:cmName"/>
		<property name="uri.var.cmSubject" expression="$func:cmSubject"/>
		<property name="uri.var.cmFromName" expression="$func:cmFromName"/>
		<property name="uri.var.cmFromEmail" expression="$func:cmFromEmail"/>
		<property name="uri.var.cmReplyTo" expression="$func:cmReplyTo"/>
		<property name="uri.var.cmListIds" expression="$func:cmListIds"/>
		<property name="uri.var.cmSegmentIds" expression="$func:cmSegmentIds"/>
		<property name="uri.var.cmTemplateId" expression="$func:cmTemplateId"/>
		<property name="uri.var.cmTemplateContent" expression="$func:cmTemplateContent"/>
	
		<!-- Facebook related template properties. -->
		<property name="uri.var.fbApiUrl" expression="$func:fbApiUrl" />
		<property name="uri.var.fbAccessToken" expression="$func:fbAccessToken" />
		<property name="uri.var.fbConnection" expression="$func:fbConnection" />
		<property name="uri.var.fbMessageBody" expression="$func:fbMessageBody" />
		<property name="uri.var.fbLink" expression="$func:fbLink" />
		<property name="uri.var.fbPicture" expression="$func:fbPicture" />
		<property name="uri.var.fbName" expression="$func:fbName" />
		<property name="uri.var.fbCaption" expression="$func:fbCaption" />
		<property name="uri.var.fbDescription" expression="$func:fbDescription" />
		<property name="uri.var.fbActions" expression="$func:fbActions" />
		<property name="uri.var.fbPlace" expression="$func:fbPlace" />
		<property name="uri.var.fbTags" expression="$func:fbTags" />
		<property name="uri.var.fbPrivacy" expression="$func:fbPrivacy" />
		<property name="uri.var.fbObjectAttachment" expression="$func:fbObjectAttachment" />
		<property name="messageType" value="application/json" scope="axis2"/>
		
		<!-- If the Campaign Monitor access token is available, proceed with the Campaign Monitor call. -->
		<filter source="boolean(get-property('uri.var.cmAccessToken'))" regex="true">
            <then>           
				<!-- Calling the Campaign Monitor connector. -->
				<campaignmonitor.init>
					<apiUrl>{$ctx:uri.var.cmApiUrl}</apiUrl>
					<accessToken>{$ctx:uri.var.cmAccessToken}</accessToken>
				</campaignmonitor.init>
				<campaignmonitor.createCampaignFromTemplate>
					<clientId>{$ctx:uri.var.cmClientId}</clientId>
					<name>{$ctx:uri.var.cmName}</name>
					<subject>{$ctx:uri.var.cmSubject}</subject>
					<fromName>{$ctx:uri.var.cmFromName}</fromName>
					<fromEmail>{$ctx:uri.var.cmFromEmail}</fromEmail>
					<replyTo>{$ctx:uri.var.cmReplyTo}</replyTo>
					<listIds>{$ctx:uri.var.cmListIds}</listIds>
					<segmentIds>{$ctx:uri.var.cmSegmentIds}</segmentIds>
					<templateId>{$ctx:uri.var.cmTemplateId}</templateId>
					<templateContent>{$ctx:uri.var.cmTemplateContent}</templateContent>
				</campaignmonitor.createCampaignFromTemplate>
				
				<!-- Getting the created campaign ID. -->
				<property name="cmpaignId" value="" />
							
				<!-- According to the successful or unsuccessful response status code, construct the custom messages. -->
				<filter source="$axis2:HTTP_SC" regex="201">
					<then>
						<property name="status" value="Success" />
						<property name="message" expression="fn:concat('The campaign was successfully created with the campaign ID ',get-property('cmpaignId'),'.')" />
					</then>
					<else>				
						<property name="messageType" value="application/json" scope="axis2"/>
						<property name="status" value="Error" />
						<property name="message" expression="json-eval($.)" />
					</else>
				</filter>
            </then>
		</filter>
		
		<!-- If the Facebook access token is available, proceed with the Facebook wall post creation call. -->
		<filter source="boolean(get-property('uri.var.fbAccessToken'))" regex="true">
            <then>           
				<!-- Calling the Facebook connector. -->
				<facebook.init>
					<apiUrl>{$ctx:uri.var.fbApiUrl}</apiUrl>
					<accessToken>{$ctx:uri.var.fbAccessToken}</accessToken>
					<connection>{$ctx:uri.var.fbConnection}</connection> 
				</facebook.init>
				<facebook.createPost> 
					<message>{$ctx:uri.var.fbMessageBody}</message> 
					<link>{$ctx:uri.var.fbLink}</link> 
					<picture>{$ctx:uri.var.fbPicture}</picture>
					<name>{$ctx:uri.var.fbName}</name>
					<caption>{$ctx:uri.var.fbCaption}</caption>
					<description>{$ctx:uri.var.fbDescription}</description>
					<actions>{$ctx:uri.var.fbActions}</actions> 
					<place>{$ctx:uri.var.fbPlace}</place> 
					<tags>{$ctx:uri.var.fbTags}</tags> 
					<privacy>{$ctx:uri.var.fbPrivacy}</privacy> 
					<objectAttachment>{$ctx:uri.var.fbObjectAttachment}</objectAttachment>  
				</facebook.createPost>
				
				<!-- Getting the created wall post ID. -->
				<property name="fbPostId" expression="json-eval($.id)" />
							
				<!-- According to the availability of the created post ID, construct the custom messages. -->
				<filter source="boolean(get-property('fbPostId'))" regex="false">
					<then>
						<property name="messageType" value="application/json" scope="axis2"/>
						<property name="status" value="Error" />
						<property name="message" expression="json-eval($.)" />
					</then>
					<else>				
						<property name="status" value="Success" />
						<property name="message" expression="fn:concat('The Facebook wall post was successfully created with the wall post ID ',get-property('fbPostId'),'.')" />
					</else>
				</filter>
            </then>
		</filter>
    </sequence>
</template>
Sample Proxy for Monitoring Unsold Items
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ebay_retrieveUnsoldItemsAndCreateCampaign" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq"> 
       
        <!--eBay Trading related properties.-->
         <property name="ebayApiUrl" expression="json-eval($.ebayApiUrl)"/>
         <property name="ebayAppId" expression="json-eval($.ebayAppId)"/>
         <property name="ebayVersion" expression="json-eval($.ebayVersion)"/>
         <property name="ebayRouting" expression="json-eval($.ebayRouting)"/>
         <property name="ebaySiteId" expression="json-eval($.ebaySiteId)"/>
         <property name="ebayAuthToken" expression="json-eval($.ebayAuthToken)"/>
         <property name="ebayMessageId" expression="json-eval($.ebayMessageId)"/>
         <property name="ebayErrorLanguage" expression="json-eval($.ebayErrorLanguage)"/>
         <property name="ebayWarningLevel" expression="json-eval($.ebayWarningLevel)"/>
         <property name="ebayDetailLevel" expression="json-eval($.ebayDetailLevel)"/>
         
         <!--Campaign Monitor related properties.-->
         <property name="cmApiUrl" expression="json-eval($.cmApiUrl)"/>
         <property name="cmAccessToken" expression="json-eval($.cmAccessToken)"/>
         <property name="cmClientId" expression="json-eval($.cmClientId)"/>
         <property name="cmName" expression="json-eval($.cmName)"/>
         <property name="cmSubject" expression="json-eval($.cmSubject)"/>
         <property name="cmFromName" expression="json-eval($.cmFromName)"/>
         <property name="cmReplyTo" expression="json-eval($.cmReplyTo)"/>
         <property name="cmFromEmail" expression="json-eval($.cmFromEmail)"/>
         <property name="cmListIds" expression="json-eval($.cmListIds)"/>
         <property name="cmSegmentIds" expression="json-eval($.cmSegmentIds)"/>
         <property name="cmTemplateId" expression="json-eval($.cmTemplateId)"/>
         <property name="responseString" value="" scope="operation"/>
         
         <payloadFactory media-type="xml">
          <format>
     <ebl:ebayActiveList xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
      <ebl:values>
       <ebl:Include>true</ebl:Include>
      </ebl:values>
     </ebl:ebayActiveList>
    </format>
         </payloadFactory>
         
         <property name="ebayActiveList" expression="//ebl:ebayActiveList/*"  xmlns:ebl="urn:ebay:apis:eBLBaseComponents"/>
         
         <!--Call the eBay getMyEbaySellig method to retrieve the active item list.-->
         <ebay.init-trading>
            <apiUrl>{$ctx:ebayApiUrl}</apiUrl>
            <appId>{$ctx:ebayAppId}</appId>
            <routing>{$ctx:ebayRouting}</routing>
            <authToken>{$ctx:ebayAuthToken}</authToken>
            <siteId>{$ctx:ebaySiteId}</siteId>
            <warningLevel>{$ctx:ebayWarningLevel}</warningLevel>
            <messageId>{$ctx:ebayMessageId}</messageId>
            <errorLanguage>{$ctx:ebayErrorLanguage}</errorLanguage>
            <version>{$ctx:ebayVersion}</version>
         </ebay.init-trading>
         <ebay.getMyeBaySelling>
            <activeList>{$ctx:ebayActiveList}</activeList>
         </ebay.getMyeBaySelling>
         
         <property name="ack" expression="//ebl:Ack" xmlns:ebl="urn:ebay:apis:eBLBaseComponents"/>
         <filter source="boolean(get-property('ack'))" regex="Failure">
          <then>
           <property name="messageType" value="application/json" scope="axis2"/>
     <property name="status" expression="get-property('ack')" />
     <property name="message" expression="json-eval($.Envelope.Body.)" />
       
     <call-template target="responseHandlerTemplate">
      <with-param name="id" value="{$ctx:uri.var.id}" />
      <with-param name="status" value="{$ctx:status}" />
      <with-param name="message" value="{$ctx:message}" />
     </call-template>
           <loopback/>
          </then>
         </filter>
         
         <property name="itemCount" expression="count(//ebl:ItemArray/ebl:Item)" xmlns:ebl="urn:ebay:apis:eBLBaseComponents"  scope="operation"/>
         <property name="itemIndex" expression="0" scope="operation"/>
         <property name="itemContent" value="" scope="operation"/>
         <property name="proceed" value="false" scope="operation"/>
         <property name="itemIds" value="" scope="operation"/>
         
         <!--FOR EACH ActiveItems : BEGIN-->
         <iterate continueParent="true" id="items" expression="//ebl:ItemArray/ebl:Item" sequential="true" xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
            <target>
               <sequence>
               
                  <!--Extract ActiveItem details from the message.-->
                  <property name="itemTitle" expression="//ebl:Item/ebl:Title/text()"/>
                  <property name="itemUrl" expression="//ebl:Item/ebl:ListingDetails/ebl:ViewItemURL/text()"/>
                  <property name="itemId" expression="//ebl:Item/ebl:ItemID/text()"/>
                  <property name="itemIds" expression="fn:concat(get-property('operation','itemIds'), get-property('itemId'), ',')" scope="operation"/>
                  
                  <!--Call ebay.getItem to retrieve the active item picture URL and the item quantity sold.-->
                  <ebay.init-trading>
                     <apiUrl>{$ctx:ebayApiUrl}</apiUrl>
                     <appId>{$ctx:ebayAppId}</appId>
                     <routing>{$ctx:ebayRouting}</routing>
                     <authToken>{$ctx:ebayAuthToken}</authToken>
                     <siteId>{$ctx:ebaySiteId}</siteId>
                     <warningLevel>{$ctx:ebayWarningLevel}</warningLevel>
                     <messageId>{$ctx:ebayMessageId}</messageId>
                     <errorLanguage>{$ctx:ebayErrorLanguage}</errorLanguage>
                     <version>{$ctx:ebayVersion}</version>
                  </ebay.init-trading>
                  <ebay.getItem>
                     <itemId>{$ctx:itemId}</itemId>
                     <detailLevel>{$ctx:ebayDetailLevel}</detailLevel>
                  </ebay.getItem>
                  
                  <!--Extract the item picture URL and the item quantity sold amount from the message.-->
                  <property name="pictureUrl" expression="//ebl:Item/ebl:PictureDetails/ebl:PictureURL/text()"/>
                  <property name="itemQuantitySold" expression="//ebl:Item/ebl:SellingStatus/ebl:QuantitySold/text()"/>
                  
                  <filter xpath="get-property('itemQuantitySold') = 0">
                   <then>
                    <payloadFactory media-type="json">
                       <format>
          {
           "item":{
                     "Layout": "$1",
                     "Singlelines": [
                       {
                         "Content": "$1",
                         "Href": "$2"
                       }
                     ],
                     "Multilines": [
                       {
                         "Content": "$2"
                       }
                     ],
                     "Images": [
                       {
                         "Content": "$3",
                         "Alt": "$1",
                         "Href": "$2"
                       }
                     ]
                  }
              }
        </format>
                       <args>
                          <arg evaluator="xml" expression="get-property('itemTitle')"/>
                          <arg evaluator="xml" expression="get-property('itemUrl')"/>
                          <arg evaluator="xml" expression="get-property('pictureUrl')"/>
                       </args>
                    </payloadFactory>
                    
                    <property name="item" expression="json-eval($.item)"/>
                    <property name="itemContent" expression="fn:concat(get-property('operation','itemContent'), get-property('item'), ',')" scope="operation"/>
                    <property name="proceed" expression="get-property('operation','proceed')" scope="operation"/>
                   </then>
                  </filter>
                  <property name="itemIndex" expression="get-property('operation','itemIndex') + 1" scope="operation"/>
               </sequence>
            </target>
         </iterate>
         <!--FOR EACH ActiveItems : END-->
         
         <filter xpath="get-property('operation','itemIndex' ) = get-property('operation','itemCount' ) and get-property('operation','itemIndex' ) >0">
            <then>
               <property name="itemContent" expression="fn:substring(get-property('operation','itemContent'),1,fn:string-length(get-property('operation','itemContent'))-1)" scope="operation"/>
               <property name="itemIds" expression="fn:substring(get-property('operation','itemIds'),1,fn:string-length(get-property('operation','itemIds'))-1)" scope="operation"/>
               <property name="id" expression="fn:concat('{item_ids:[',get-property('operation','itemIds'),']}')"/>
               
               <payloadFactory media-type="json">
                  <format>
       {
        "templateContent": {
         "Repeaters": [
          {
           "Items": [$1]
          }
         ]
        }
       }
      </format>
                  <args>
                     <arg evaluator="xml" expression="get-property('operation','itemContent')"/>
                  </args>
               </payloadFactory>
               
               <property name="cmTemplateContent" expression="json-eval($.templateContent)"/>
               
               <filter source="boolean(get-property('operation','itemContent'))" regex="true">
                  <then>
                     
      <property name="messageType" value="application/json" scope="axis2"/>
                     
      <filter source="boolean(get-property('cmAccessToken'))" regex="false">
       <then>           
       <property name="status" value="Skipped" />
       <property name="message" value="Please provide the Campaign Monitor authentication token." />  
       </then>
       <else>
        <!-- Call the template cm-createCampaignFromTemplate to create a campaign for the active items.-->
        <call-template target="ebay-publishItemDetailsOnSocialMedia">
        (
         <with-param name="cmApiUrl" value="{$ctx:cmApiUrl}"/> |
         <with-param name="cmAccessToken" value="{$ctx:cmAccessToken}"/> |
         <with-param name="cmClientId" value="{$ctx:cmClientId}"/> |
         <with-param name="cmName" value="{$ctx:cmName}"/> |
         <with-param name="cmSubject" value="{$ctx:cmSubject}"/> |
         <with-param name="cmFromName" value="{$ctx:cmFromName}"/> |
         <with-param name="cmFromEmail" value="{$ctx:cmFromEmail}"/> |
         <with-param name="cmReplyTo" value="{$ctx:cmReplyTo}"/> |
         <with-param name="cmListIds" value="{$ctx:cmListIds}"/> |
         <with-param name="cmSegmentIds" value="{$ctx:cmSegmentIds}"/> |
         <with-param name="cmTemplateId" value="{$ctx:cmTemplateId}"/> |
         <with-param name="cmTemplateContent" value="{$ctx:cmTemplateContent}"/> |
        ) *
        </call-template>
        <call-template target="responseHandlerTemplate">
        <with-param name="activity" value="campaignMonitor_createCampaign" />
        <with-param name="id" value="{$ctx:idParam}" />
        <with-param name="status" value="{$ctx:status}" />
        <with-param name="message" value="{$ctx:message}" />
        </call-template>
        <loopback/>
       </else>
     </filter>
                  </then>
                  <else>
                     <property name="status" value="Skipped"/>
                     <property name="message" value="There is no active item(s) to create a campaign."/>
                  </else>
               </filter>
               <call-template target="responseHandlerTemplate">
      <with-param name="activity" value="campaignMonitor_createCampaignFromTemplate" />
                  <with-param name="id" value="{$ctx:uri.var.id}"/>
                  <with-param name="status" value="{$ctx:status}"/>
                  <with-param name="message" value="{$ctx:message}"/>
               </call-template>
               <loopback/>
            </then>
         </filter>
         
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2"/>
         <payloadFactory media-type="json">
            <format>
    {
     "Response":{
      "process":"ebay_retrieveAndCreateItem",
      "activityResponse":[$1]
     }
    }
   </format>
            <args>
               <arg evaluator="xml"
                    expression="get-property('operation', 'responseString')"/>
            </args>
         </payloadFactory>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>                                                                                                       
Sample Request for Monitoring Unsold Items
{
    "ebayApiUrl": "https://api.sandbox.ebay.com/wsapi",
    "ebayAppId": "Virtusa86-ece0-4c28-99d5-ef94509fdb2",
    "ebayVersion": "843",
    "ebayRouting": "default",
    "ebaySiteId": "203",
    "ebayAuthToken": "AgAAAA**AQAAAA**aAAAAA**1tU8VA**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wFk4GhDJiHpQWdj6x9nY+seQ**lxMDAA**AAMAAA**Skd/e56YbZ7jwPAPYW5CuVKkQZryxBK84u9eUB+G3tp3wMFMywAG+DtFWkx8VWGybVxrPDuWgLKU8rij09nA/2UT6/giy4vFClS0zNWWmuK0f6IZszAXhEZI5dF2rWwtbbpBJpZcJxjREs1+5vHqoc+V6WUwzhp2jOh/hNvmTwgnE/IZyjJwIVO720wnaoSDuq/kl2B5qzvPKdQGFF7lHWFtjI2Yed7W1N9p/T/8CdlYPer3Jb9IW4xHTlXemcsr5Gi9mYvQGrydU11Ie2tMQpIe3Gf332/I7lmeKDzNyuYxqGDdw7fbNddw848rd3UCnTzcHcxFXEZ6xvSOa7DIJvKfrwYky25k51gNjAA/R2sgy2yN7ghhaUCxNqZh1oen7d5LT9GUK6Kg7LIjaC5Qz9J4JiqzabphMVhblR9RwaMw9xF+ymRAacql4wxb4d3M+zlKuxai0pq26HImbYGAxOAEIC0XLgbeO15OKVovmV1M0o3XP5rszwD4HaqJsuQoOfqvPMcc4Gg5J/sR/KfQzd2yjVBhE4Qqj1rOFRnBJiMScTll6mJ/bSZ5CKte35dLSvCb6sC3VQ0WAETZyUlu6HOTHJJwdlrmpIyuY7xH8sSB7VHIBkXt/p5BZJL8CDFYibXK3IDwOf1gOpaCaDV0DLmV80cvAtDIrOLpqA3BD66kGs3fc+Y9RrBiG2m/yfo8L/GTPFpuyi8lLl1ukHafdU/sbZOuA4U7r4pKT/u6GDSL8K53bYkWk3/E2OFwdE/V",
    "ebayMessageId": "",
    "ebayErrorLanguage": "en_US",
    "ebayWarningLevel": "",
    "ebayDetailLevel": "ReturnAll",
    
    "cmApiUrl": "https://api.createsend.com",
    "cmAccessToken": "AX3ayb8/p3pPnvo18DBQMlsxOQ==",
    "cmClientId":"8bd3081b596269287bce14984c2f6a92",
    "cmName": "Active list Campaign Scenario Demo test 16",
    "cmSubject": "Active Items",
    "cmFromName": "From Name",
    "cmReplyTo": "replyto@mail.com",
    "cmFromEmail": "from@domail.com",
    "cmListIds": [
        "82700cd1504e0d68cf0737a7c2fb3a47"
    ],
    "cmSegmentIds": "",
    "cmTemplateId": "f8194aad0f17443832fecc1aeb3354a2"
}