Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
maxLevel3
printablefalse

Overview

The flow for course initiation is illustrated in the following diagram. The ESB connectors for Eventbrite, MailChimp, and Google Calendar will be used to connect to each service. Eventbrite is an online ticketing service that allows event organizers to plan, set up ticket sales, and promote and publish events. MailChimp is an online email marketing solution used to create campaigns, manage contacts, send emails, and track results. Google Calendar can be used as a communication medium through which the students can be notified/reminded about appointments and notifications.

Course creation and marketing

In this use case, we will create a course in Canvas as an offline process. We can retrieve this course from Canvas, create it as a paid event with the required ticket details in the Eventbrite API, and then publish it through the Eventbrite API. For the published events, we can create a campaign in the MailChimp API and send it for marketing purposes. As a prerequisite, MailChimp should have a list of existing subscribers. 

  1. Retrieve the course from Canvas using the getCourse operation.

  2. In Eventbrite, create a paid event using the createEvent operation, create the ticket details associated with the event using the createTicketClass operation, and publish the event using the publishEvent operation.

  3. In MailChimp, create a campaign using the createDraftCampaign operation, and then send the campaign using the sendCampaign operation.

    Info

    Once the e-mail has been sent from MailChimp, users can access the event in Eventbrite through the e-mail sent from MailChimp, and they can pay online and purchase tickets for the event in Eventbrite. This is an offline process.

MailChimp operations
Canvas operations
Eventbrite operations
Samples
Code Block
languagexml
titleSample template for creating and sending the campaign
	<?xml version="1.0" ?>
<!-- This template is responsible for creating a campaign and sending in MailChimp 
     according to the given access token of MailChimp with other parameters. -->
<template name="createCampaignAndSend" xmlns="http://ws.apache.org/ns/synapse">
	<!-- MailChimp related template parameters -->
	<parameter name="mailchimp.apiUrl" description="Base endpoint URL of MailChimp API."/>
    <parameter name="mailchimp.apiKey" description="API Authentication Key to access the MailChimp API."/>
	<parameter name="mailchimp.options" description="A struct of the standard options for this campaign."/>
    <parameter name="mailchimp.content" description="The content for this campaign."/>
	<parameter name="mailchimp.listId" description="Id of the Subscriber list."/>
	<parameter name="mailchimp.subject" description="Subject of the campaign."/>
	<parameter name="mailchimp.fromEmail" description="Campaign sender's email."/>
	<parameter name="mailchimp.fromName" description="Sender's name."/>
	<parameter name="mailchimp.toName" description="Receiver's Name."/>
	<parameter name="mailchimp.templateId" description="Id of the campaign template."/>
	<parameter name="mailchimp.eventName" description="Name of the event."/>
	<parameter name="mailchimp.startTime" description="Event start time."/>
	<parameter name="mailchimp.startTimeZone" description="Event start time zone."/>
	<parameter name="mailchimp.endTime" description="Event end time."/>
	<parameter name="mailchimp.endTimeZone" description="Event end time zone."/>
	<parameter name="mailchimp.eventDescription" description="Event description."/>
	<parameter name="mailchimp.eventUrl" description="Url of the event."/>
	<parameter name="campaign.idObject" description="Id as Key value pair(s) for response handler (Ex. id1:value1,id2:value2)."/>
    <sequence>
		<!-- MailChimp related template properties -->
		<property name="mailchimp.apiUrl" expression="$func:mailchimp.apiUrl"/>
		<property name="mailchimp.apiKey" expression="$func:mailchimp.apiKey"/>
		<property name="mailchimp.content" expression="$func:mailchimp.content"/>
		<property name="mailchimp.listId" expression="$func:mailchimp.listId"/>
		<property name="mailchimp.subject" expression="$func:mailchimp.subject"/>
		<property name="mailchimp.fromEmail" expression="$func:mailchimp.fromEmail"/>
		<property name="mailchimp.fromName" expression="$func:mailchimp.fromName"/>
		<property name="mailchimp.toName" expression="$func:mailchimp.toName"/>
		<property name="mailchimp.templateId" expression="$func:mailchimp.templateId"/>
		
		<property name="mailchimp.eventName" expression="$func:mailchimp.eventName"/>
		<property name="mailchimp.startTime" expression="$func:mailchimp.startTime"/>
		<property name="mailchimp.startTimeZone" expression="$func:mailchimp.startTimeZone"/>
		<property name="mailchimp.endTime" expression="$func:mailchimp.endTime"/>
		<property name="mailchimp.endTimeZone" expression="$func:mailchimp.endTimeZone"/>
		<property name="mailchimp.eventDescription" expression="$func:mailchimp.eventDescription"/>
		<property name="mailchimp.eventUrl" expression="$func:mailchimp.eventUrl"/>
		
		<property name="campaign.idObject" expression="$func:campaign.idObject"/>
		
			<!--Building the MailChimp options parameter.-->
			<payloadFactory media-type="json">
			<format>
					{
						"options":{
									"list_id": "$1",
									"subject": "$2",
									"from_email": "$3",
									"from_name": "$4",
									"to_name": "$5",
									"template_id": $6
						}
					}
			</format>
				<args>
					<arg  expression="get-property('mailchimp.listId')"/>
					<arg  expression="get-property('mailchimp.subject')"/>
					<arg  expression="get-property('mailchimp.fromEmail')"/>
					<arg  expression="get-property('mailchimp.fromName')"/>
					<arg  expression="get-property('mailchimp.toName')"/>
					<arg  expression="get-property('mailchimp.templateId')"/>
				</args>
			</payloadFactory>
			
			<property name="mailchimp.options" expression="json-eval($.options)"/>
			
			<!--Building the MailChimp content parameter.-->
			<payloadFactory media-type="json">
					<format>
							{
								"content":{
									"sections": {
										"eventTitle": "$1",
										"startTime":"$2",
										"startTimeZone":"$3",
										"endTime":"$4",
										"endTimeZone":"$5",
										"eventDescription":"$6",
										"eventUrl":"To reserve your ticket please visit: $7"
									}
								}
							}
					</format>
						<args>
							<arg expression="get-property('mailchimp.eventName')"/>
							<arg expression="get-property('mailchimp.startTime')"/>
							<arg expression="get-property('mailchimp.startTimeZone')"/>
							<arg expression="get-property('mailchimp.endTime')"/>
							<arg expression="get-property('mailchimp.endTimeZone')"/>
							<arg expression="get-property('mailchimp.eventDescription')"/>
							<arg expression="get-property('mailchimp.eventUrl')"/>
						</args>
					</payloadFactory>
					
					<property name="mailchimp.content" expression="json-eval($.content)"/>
		
		<!-- If the MailChimp API key is available, proceed with the MailChimp call. -->
		<filter source="boolean(get-property('mailchimp.apiKey'))" regex="true">
            <then> 
				<!-- Calling the MailChimp connector createDraftCampaign method. -->
				<mailchimp.init>
					<apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
					<apiKey>{$ctx:mailchimp.apiKey}</apiKey>
					<format>json</format>
				</mailchimp.init>
				<mailchimp.createDraftCampaign>
					<options>{$ctx:mailchimp.options}</options>
					<content>{$ctx:mailchimp.content}</content>
					<type>regular</type>
				</mailchimp.createDraftCampaign>
				
				<!-- Getting the created campaign ID. -->
				<property name="campaignId" expression="json-eval($.id)" />
				
				<filter source="boolean(get-property('campaignId'))" regex="false">
					<then>		
						<property name="status" value="Error" />
						<property name="message" expression="json-eval($.)" />
					</then>
					<else>
						<property name="status" value="Success" />
						<property name="message" expression="fn:concat('Campaign was successfully created with campaign id ',get-property('campaignId'),'.')" />
					</else>
				</filter>
				<call-template target="responseHandlerTemplate">
							<with-param name="activity" value="mailchimp_createCampaign" />
							<with-param name="id" value="{$ctx:campaign.idObject}" />
							<with-param name="status" value="{$ctx:status}" />
							<with-param name="message" value="{$ctx:message}" />
				</call-template>
				
				<!-- Send the campaign, only if the campaign is created. -->
				<filter source="boolean(get-property('campaignId'))" regex="true">
					<then>
						<mailchimp.init>
							<apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
							<apiKey>{$ctx:mailchimp.apiKey}</apiKey>
							<format>json</format>
						</mailchimp.init>
						<mailchimp.sendCampaign>
							<campaignId>{$ctx:campaignId}</campaignId>
						</mailchimp.sendCampaign>
						
						<property name="isCampaignSendComplete" expression="json-eval($.complete)" />
						
						<filter xpath="boolean(get-property('isCampaignSendComplete')) and get-property('isCampaignSendComplete')='true' " >
							<then>
								<property name="status" value="Success" />
								<property name="message" value="Email for the campaign has been sent." />
							</then>
							<else>
								<property name="status" value="Error" />
								<property name="message" expression="json-eval($.)" />
							</else>
						</filter>
						
						<call-template target="responseHandlerTemplate">
							<with-param name="activity" value="mailchimp_sendCampaign" />
							<with-param name="id" value="{$ctx:campaign.idObject}" />
							<with-param name="status" value="{$ctx:status}" />
							<with-param name="message" value="{$ctx:message}" />
						</call-template>
					</then>
				</filter>
            </then>
		</filter>
		
    </sequence>
</template>

...

Code Block
languagexml
titleSample request for retrieving the Canvas course details and creating them as events in Eventbrite
{
"canvasApiUrl":"https://canvas.instructure.com",
"canvasAccessToken":"7~5pA2tUv3iq22u5BqMI8T3FyId333J2atYt4e1KMNAptdFsfBqCEVrREg0I0hPTcv",
"canvasCourses":{"data":[
				{
					"courseId":"893240",
					"accountId":"81259",
					"price":"1000",
					"currency":"JPY",
					"timeZone":"Asia/Colombo",
					"venueId":"9176393",
					"ticketQty":"50"
				},
				{
					"courseId":"902512",
					"accountId":"81259",
					"price":"",
					"currency":"JPY",
					"timeZone":"Asia/Colombo",
					"venueId":"9176393",
					"ticketQty":"50"
				}
			]
			},
"eventbriteApiUrl":"https://www.eventbriteapi.com",
"eventbriteAccessToken":"4SMVCVGYVT2K3FYPMMLP",
"mailchimpApiUrl": "https://us9.api.mailchimp.com",
"mailchimpApiKey": "2ad58ea9a2e332a6fe0a4ef6ea6dca10-us9",
"mailchimpListId": "0239fb6051",
"mailchimpSubjectPrefix": "University of Oracle",
"mailchimpFromEmail": "palamayuranrox@gmail.com",
"mailchimpFromName": "Marketing Department - Oracle University",
"mailchimpToName": "Dear Subscriber",
"mailchimpTemplateId": 171393
}

Course management

You can retrieve attendees from Eventbrite and add them as users to the course in Canvas, or you can add them to the MailChimp subscribers list, if they are not in the list already. The users added to Canvas will receive an e-mail invitation, which they can use to register themselves to the course. You can retreive the enrolled users from Canvas and create a calendar that you can share with them in Google Calendar. To perform this step, students must have a given Gmail ID.

  1. Retrieve attendees from Eventbrite using the /wiki/spaces/CONNECTORS/pages/48465408 operation.
  2. Add the attendees to the MailChimp subscribers list using the /wiki/spaces/CONNECTORS/pages/48465308 operation. 
  3. Using the addUser operation, add the attendees as users, and then enroll the user using the enrollUser operation in Canvas. Retrieve the users belonging to a course using the listCourseUsers operation. 
  4. If the calendar ID is not provided, and if the user provided sufficient details to create a calendar, use the createCalendar operation of the Google Calendar connector to create a new calendar. In order to provide permissions for users, use the createAcl operation of the Google Calendar connector.
Google Calendar operations
MailChimp operations
Canvas operations
Eventbrite operations
Samples
Code Block
languagexml
titleSample proxy for retrieving attendees' email addresses from Eventbrite on a specific event
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="canvas_addSubscribersToMailChimpAndAddingUsersToCanvas"
       transports="https"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
    <target>
      	<inSequence onError="faultHandlerSeq">
	  
	 	<!-- Eventbrite parameters -->
	  	<property name="eventbrite.apiUrl" expression="json-eval($.eventbriteApiUrl)" />
	  	<property name="eventbrite.accessToken" expression="json-eval($.eventbriteAccessToken)" />
	  	<property name="eventbrite.eventId" expression="json-eval($.eventbriteEventId)" />
	  	<!-- MailChimp parameters -->
	  	<property name="mailchimp.apiUrl" expression="json-eval($.mailChimpApiUrl)" />
	  	<property name="mailchimp.apiKey" expression="json-eval($.mailChimpApiKey)" />
      	<property name="mailchimp.updateExisting" expression="json-eval($.mailChimpUpdateExisting)"/>
	  	<property name="mailchimp.listId" expression="json-eval($.mailChimpListId)"/>
	  	<!-- Canvas parameters -->
	  	<property name="canvas.apiUrl" expression="json-eval($.canvasApiUrl)" />
	  	<property name="canvas.accessToken" expression="json-eval($.canvasAccessToken)" />
	  	<property name="canvas.accountId" expression="json-eval($.canvasAccountId)"/>
      	<property name="canvas.courseId" expression="json-eval($.canvasCourseId)"/>
		
	  	<property name="emailBuilder" value="[" scope="operation"/>
	  	<property name="emailList" value="" scope="operation"/>
	  
	  	<!-- Retrieve event attendees from Eventbrite. -->
	   	<eventbrite.init>
            <apiUrl>{$ctx:eventbrite.apiUrl}</apiUrl>
            <accessToken>{$ctx:eventbrite.accessToken}</accessToken>
        </eventbrite.init>
        <eventbrite.eventAttendees>
            <EventID>{$ctx:eventbrite.eventId}</EventID>
        </eventbrite.eventAttendees>
        <sequence key="eventbrite-removeResponseHeaders" />
	   	<property name="noOfAttendees" expression="count(//attendees)" scope="operation" />
        <property name="attendeesIndex" expression="0" scope="operation" />
        <filter xpath="get-property('operation','noOfAttendees') = get-property('operation','attendeesIndex')">
        	<then>
				<property name="id" expression="fn:concat('eventbrite_eventId:', get-property('eventbrite.eventId'))" />
                <property name="status" value="Failed" />
                <property name="message" value="No attendees were found for the event." />
                <!--Call the responseHandler template.-->
		        <call-template target="responseHandlerTemplate">
		        	<with-param name="activity" value="canvas_addUserToAccountAndEnroll" />
		            <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 Attendee: BEGIN-->
		        <iterate continueParent="true" id="attendees" expression="//attendees" sequential="true">
		            <target>
		                <sequence>
		                	<!--Store the attendee's email address in the MailChimp subscriber list.-->
		                    <property name="attendeeEmail" expression="//attendees/profile/email/text()" />
		                    <property name="fullName" expression="//attendees/profile/name/text()" />
		                    <property name="firstName" expression="//attendees/profile/first_name/text()" />
		                    <property name="lastName" expression="//attendees/profile/last_name/text()" />
		                    <property name="timeZone" expression="//attendees/event/start/timezone/text()" />
		                    <!--Concatanate the emails to build an array in a way Mailchimp expects.-->
							<property name="emailJSON" expression="fn:concat('{ &quot;email&quot;: { &quot;email&quot;: &quot;',get-property('attendeeEmail'),'&quot; },&quot;email_type&quot;: &quot;html&quot;}')" /> 
							<property name="emailBuilder" expression="fn:concat(get-property('operation','emailBuilder'), get-property('emailJSON') , ', ')" scope="operation"/>
						   	<!--Add users to Canvas and enroll them for the course.-->
		                    <call-template target="addUsersAndRegistrants">
					   				<with-param name="canvas.apiUrl" value="{$ctx:canvas.apiUrl}" />
					   				<with-param name="canvas.accessToken" value="{$ctx:canvas.accessToken}" />
					   				<with-param name="canvas.accountId" value="{$ctx:canvas.accountId}" />
					   				<with-param name="canvas.courseId" value="{$ctx:canvas.courseId}" />
					   				<with-param name="fullName" value="{$ctx:fullName}" />
					   				<with-param name="email" value="{$ctx:attendeeEmail}" />
					   				<with-param name="firstName" value="{$ctx:firstName}" />
							   		<with-param name="lastName" value="{$ctx:lastName}" />
							   		<with-param name="timeZone" value="{$ctx:timeZone}" />
					 		</call-template>
						   	
						   	<!--Increment the attendee count.-->
                            <property name="attendeesIndex" expression="get-property('operation', 'attendeesIndex') + 1" scope="operation" />
						</sequence>
					</target>    					
		        </iterate>
		        <!--FOR EACH Attendee: END-->
				
                <filter xpath="get-property('operation', 'noOfAttendees') = get-property('operation', 'attendeesIndex')">
                    <then>	
				        <property name="mailchimp.batch" expression="fn:concat(fn:substring(get-property('operation', 'emailBuilder'), 0, fn:string-length(get-property('operation', 'emailBuilder')) - 1), ']')"/>
						
						<!-- Add the attendee's email address to the subscriber list in MailChimp. -->
						<mailchimp.init>
				            <apiUrl>{$ctx:mailchimp.apiUrl}</apiUrl>
				            <apiKey>{$ctx:mailchimp.apiKey}</apiKey>
				            <format>json</format>
				        </mailchimp.init>
						<mailchimp.addSubscribersToList>
						    <listId>{$ctx:mailchimp.listId}</listId>
						    <batch>{$ctx:mailchimp.batch}</batch>
						    <doubleOptin>false</doubleOptin>
						    <updateExisting>{$ctx:mailchimp.updateExisting}</updateExisting>
						    <replaceInterests>false</replaceInterests>
						</mailchimp.addSubscribersToList>
						<property name="noOfAttendeesAdded" expression="json-eval($.add_count)" />
						<filter source="boolean(get-property('noOfAttendeesAdded'))" regex="true">
							<then>
								<!--Store the attendee details in the MailChimp subscriber list-.->
								<property name="id" expression="fn:concat('mailchimp_listId', get-property('mailchimp.listId'))" />
						        <property name="status" value="Added" />
						        <property name="message" expression="fn:concat('No. of email addresses added to subscription list: ', get-property('noOfAttendeesAdded'))" />
							</then>
							<else>
								<!-- In a failure, while adding the attendee details in the MailChimp subscriber list.-->
								<property name="id" expression="fn:concat('mailchimp_listId', get-property('mailchimp.listId'))" />
						        <property name="status" value="Failure" />
						        <property name="message" expression="json-eval($)" />
							</else>
						</filter>
				        <!--Call the responseHandler template.-->
				        <call-template target="responseHandlerTemplate">
				            <with-param name="activity" value="mailchimp_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>
                </filter>        
				
			</else>	
		</filter>
      </inSequence>
      <outSequence>
         <payloadFactory media-type="json">
                <format>{
					"Response":{
						"activity":"canvas-addSubscribersToMailChimpAndAddingUsersToCanvas",
						"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>                       
Code Block
languagexml
titleSample request for retrieving attendees' email addresses from Eventbrite on a specific event
{
	"eventbriteApiUrl" : "https://www.eventbriteapi.com",
	"eventbriteAccessToken" : "O5CHYSIJQPS7QNQKBYU6",
	"eventbriteEventId" : "14747958541",
	"mailChimpApiUrl" : "https://us9.api.mailchimp.com",
	"mailChimpApiKey" : "33b1f0d89fe028aa2039029d0164344a-us9",
	"mailChimpUpdateExisting" : "false",
	"mailChimpListId" : "cac586e1b4",
	"canvasApiUrl" : "https://orion-city.acme.instructure.com",
	"canvasAccessToken" : "51451~fwK08jirhrTKFiuyua8H3rpFVQtZJu7D7rf3mi7pecuHxMglbY24XOxQ42UWTvam",
	"canvasAccountId" : "1",
	"canvasCourseId" : "122"
}
Code Block
languagexml
titleSample proxy for retrieving all the enrolled users of a course and sharing a Google Calendar with them
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="canvas_createAndShareGoogleCalendarWithCourseUsers" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <!--Canvas Properties-->		 
         <property name="canvas.apiUrl" expression="json-eval($.canvasApiUrl)" />
         <property name="canvas.accessToken" expression="json-eval($.canvasAccessToken)" />
         <property name="canvas.courseId" expression="json-eval($.canvasCourseId)" />
		 
         <!--GoogleCalendar Properties-->
         <property name="googlecalendar.apiUrl" expression="json-eval($.googlecalendarApiUrl)" />
         <property name="googlecalendar.accessToken" expression="json-eval($.googlecalendarAccessToken)" />
         <property name="googlecalendar.calendarId" expression="json-eval($.googlecalendarCalendarId)" />
         <property name="googlecalendar.summary" expression="json-eval($.googlecalendarSummary)" />
         <property name="googlecalendar.description" expression="json-eval($.googlecalendarDescription)" />
         <property name="googlecalendar.location" expression="json-eval($.googlecalendarLocation)" />
         <property name="googlecalendar.timeZone" expression="json-eval($.googlecalendarTimeZone)" />
         <property name="responseString" value="" scope="operation" />
		 
         <!--Only if the user HAS NOT provided the calendarID, create one and use its calendarID. -->
         <filter source="boolean(get-property('googlecalendar.calendarId'))" regex="false">
            <then>
               <googlecalendar.init>
                  <apiUrl>{$ctx:googlecalendar.apiUrl}</apiUrl>
                  <accessToken>{$ctx:googlecalendar.accessToken}</accessToken>
               </googlecalendar.init>
               <googlecalendar.createCalendar>
                  <summary>{$ctx:googlecalendar.summary}</summary>
                  <description>{$ctx:googlecalendar.description}</description>
                  <location>{$ctx:googlecalendar.location}</location>
                  <timeZone>{$ctx:googlecalendar.timeZone}</timeZone>
               </googlecalendar.createCalendar>
			   
               <sequence key="removeResponseHeaders" />
			   
               <!--Extract the ID from the response and set it here.-->
               <property name="googlecalendar.calendarId" expression="json-eval($.id)" />
			   
               <!--On success, display the custom message with calendar details. -->
               <filter source="boolean(get-property('googlecalendar.calendarId'))" regex="false">
                  <then>
                     <property name="apiErrorResponse" expression="json-eval($.error.errors[0].message)" />
                     <property name="message" expression="fn:concat('Failed to create the calendar: ', get-property('apiErrorResponse'))" />
                     <property name="id" value="{}" />
					 
					<!--Call the responseHandler template.-->
                     <call-template target="responseHandlerTemplate">
                        <with-param name="id" value="{$ctx:id}" />
                        <with-param name="activity" value="googlecalendar_createCalendarForCanvas" />
                        <with-param name="status" value="Error" />
                        <with-param name="message" value="{$ctx:message}" />
                     </call-template>
                     <loopback />
                  </then>
                  <else>
                     <property name="googlecalendar.calendarId" expression="json-eval($.id)" />
                     <property name="id" expression="fn:concat('Calendar ID:', get-property('googlecalendar.calendarId'))" />
                     <property name="message" value="Calendar is created successfully." />
                   
				   <!--Call the responseHandler template.-->
                     <call-template target="responseHandlerTemplate">
                        <with-param name="id" value="{$ctx:id}" />
                        <with-param name="activity" value="googlecalendar_createCalendarForCanvas" />
                        <with-param name="status" value="Success" />
                        <with-param name="message" value="{$ctx:message}" />
                     </call-template>
                  </else>
               </filter>
            </then>
         </filter>
         <filter source="boolean(get-property('googlecalendar.calendarId'))" regex="true">
            <then>
               <!--Retrieve all the users who are enrolled with the given course. -->
               <canvas.init>
                  <apiUrl>{$ctx:canvas.apiUrl}</apiUrl>
                  <accessToken>{$ctx:canvas.accessToken}</accessToken>
               </canvas.init>
               <canvas.listCourseUsers>
                  <courseId>{$ctx:canvas.courseId}</courseId>
                  <include>email,enrollments</include>
               </canvas.listCourseUsers>
			   
               <sequence key="removeResponseHeaders" />
			   
               <property name="noOfUsers" expression="count(//jsonArray/jsonElement)" scope="operation" />
               <property name="userIndex" expression="0" scope="operation" />
			   
               <!-- If there are no users registered to the course, display a custom error message.-->
               <filter xpath="get-property('operation', 'noOfUsers') = get-property('operation', 'userIndex')">
                  <then>
                     <property name="messageType" value="application/json" scope="axis2" />
                     <property name="message" value="No registered users can be found for the given course." />
                     <call-template target="responseHandlerTemplate">
                        <with-param name="activity" value="canvas_shareGoogleCalendarWithCanvesUsers" />
                        <with-param name="id" value="{$ctx:canvas.courseId}" />
                        <with-param name="status" value="Skipped" />
                        <with-param name="message" value="{$ctx:message}" />
                     </call-template>
                     <loopback />
                  </then>
                  <else>
                     <!--FOR EACH User: BEGIN-->
                     <iterate continueParent="false" id="users" expression="//jsonArray/jsonElement" sequential="true">
                        <target>
                           <sequence>
                              <!--Store the user details-->
                              <property name="userId" expression="//jsonElement/id/text()" />
                              <property name="userEmail" expression="//jsonElement/email/text()" />
                              <property name="userName" expression="//jsonElement/name/text()" />
                              <property name="userRole" expression="//jsonElement/enrollments[1]/role/text()" />
                              <property name="messageType" value="application/json" scope="axis2" />
                              <property name="roleScope" expression="fn:concat('{ &quot;type&quot;: &quot;user&quot;, &quot;value&quot;: &quot;',get-property('userEmail'),'&quot; }')" />
                             
							 <!--If the user's emailId is not set, provide the custom error message since the googleCalendar cannot be shared with such users.-->
                              <filter source="boolean(get-property('userEmail'))" regex="false">
                                 <then>
                                    <property name="messageType" value="application/json" scope="axis2" />
                                    <property name="message" value="Failed to share the calendar since the user's email ID does not exist." />
                                    <call-template target="responseHandlerTemplate">
                                       <with-param name="activity" value="canvas_shareGoogleCalendarWithCanvesUsers" />
                                       <with-param name="id" value="{$ctx:userId}" />
                                       <with-param name="status" value="Error" />
                                       <with-param name="message" value="{$ctx:message}" />
                                    </call-template>
                                 </then>
                                 <else>
                                    <filter source="get-property('userRole')" regex="TeacherEnrollment">
                                       <then>
                                          <!-- If the user is a teacher, provide the 'owner' role of the calendar.-->
                                          <property name="userRole" value="owner" />
                                       </then>
                                       <else>
                                          <!-- If the user is not a teacher, provide the 'reader' role of the calendar.-->
                                          <property name="userRole" value="reader" />
                                       </else>
                                    </filter>
									
                                    <!-- Share the Google calendar with the users. -->
                                    <googlecalendar.init>
                                       <apiUrl>{$ctx:googlecalendar.apiUrl}</apiUrl>
                                       <accessToken>{$ctx:googlecalendar.accessToken}</accessToken>
                                    </googlecalendar.init>
									
                                    <googlecalendar.createAcl>
                                       <calendarId>{$ctx:googlecalendar.calendarId}</calendarId>
                                       <role>{$ctx:userRole}</role>
                                       <scope>{$ctx:roleScope}</scope>
                                    </googlecalendar.createAcl>
									
                                    <property name="responseId" expression="json-eval($.id)" />
									
                                    <!--On success, display the custom message with the user details. -->
                                    <filter source="boolean(get-property('responseId'))" regex="true">
                                       <then>
                                          <property name="id" expression="fn:concat('canves_userId:', get-property('userId'))" />
                                          <property name="status" value="Success" />
                                          <property name="message" value="Calendar has been successfully shared" />
                                       </then>
                                       <else>
                                          <property name="apiErrorResponse" expression="json-eval($.error.errors[0].message)" />
                                          <property name="id" expression="fn:concat('canves_userId:', get-property('userId'))" />
                                          <property name="status" value="Error" />
                                          <property name="message" expression="fn:concat('Failed to share the calendar: ', get-property('apiErrorResponse'))" />
                                       </else>
                                    </filter>
									
                                    <!--Call the responseHandler template-->
                                    <call-template target="responseHandlerTemplate">
                                       <with-param name="id" value="{$ctx:id}" />
                                       <with-param name="activity" value="canvas_shareGoogleCalendarWithCanvesUsers" />
                                       <with-param name="status" value="{$ctx:status}" />
                                       <with-param name="message" value="{$ctx:message}" />
                                    </call-template>
									
                                    <property name="statusCode" expression="$axis2:HTTP_SC" />
									
                                    <!--If the calendar is missing or if an authorization error occurs at the Google Calendar API, do not proceed but loopback. -->
                                    <filter source="get-property('statusCode')" regex="40[1,4]">
                                       <then>
                                          <loopback />
                                       </then>
                                    </filter>
                                 </else>
                              </filter>
							  
                              <!--Increment the user count.-->
                              <property name="userIndex" expression="get-property('operation', 'userIndex') + 1" scope="operation" />
							  
                           </sequence>
                        </target>
                     </iterate>
                  </else>
               </filter>
			   
               <!--FOR EACH User: END-->
               <filter xpath="get-property('operation', 'noOfUsers') = get-property('operation', 'userIndex')">
                  <then>
                     <loopback />
                  </then>
               </filter>
			   
            </then>
         </filter>
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2" />
         <payloadFactory media-type="json">
            <format>{
						"Response":{
							"process":"canvas_createAndShareGoogleCalendarWithCourseUsers",
							"activityResponse": [$1]
						}
					}</format>
            <args>
               <arg expression="get-property('operation', 'responseString')" />
            </args>
         </payloadFactory>
         <send />
      </outSequence>
   </target>
   <description />
</proxy>                       
Code Block
languagexml
titleSample request for retrieving all the enrolled users of a course and sharing a Google Calendar with them
{
	"canvasApiUrl":"https://canvas.instructure.com",
	"canvasAccessToken":"7~5pA2tUv3iq22u5BqMI8T3FyId333J2atYt4e1KMNAptdFsfBqCEVrREg0I0hPTcv",
	"canvasCourseId":"902480",
	"googlecalendarApiUrl":"https://www.googleapis.com",
	"googlecalendarAccessToken":"ya29.zABfAfjrz5t38djHzFa4jG-7HQqDSnZbGQPGu1Zo1IXKuAhvsYOumBMmk9U1-sjg06wbNwJojQhRYA",
	"googlecalendarCalendarId":"boi0hvadfvqtbabqtk35c9cjck@group.calendar.google.com",
	"googlecalendarSummary":"CanvesTestCalendar",
	"googlecalendarDescription":"test calendar for canves",
	"googlecalendarLocation":"Colombo-Western Provice",
	"googlecalendarTimeZone":"GMT"
}