Salesforce To Citrix Integration
A Little Background About This
Post:
In my recent projects , I met some of my salesforce users using
Citrix applications such as
1.
Go To Webinar,
2.
Go To Meeting,
3.
Go To Assist
They are using AppExchange
products for salesforce – Citrix integration but still ended up doing manual copy
–paste work from Citrix applications to salesforce like polls, surveys
questions answers etc .
I got an opportunity to automate above work and this post
explains same piece of work .
Happy To See:
I had look into Citrix GoToWebinar API and was happy to see
that.
1.
It provide beautiful Rest API.
2.
It uses OAuth for authorization and authentication.
Tool Needed For
Demonstration :
1.
Salesforce Developer Org .
2.
Citrix Developer Account
3.
GoToWebinar Trial Account
Enough Talk’s Let’s Start:
Let’s break this into discrete tasks with
their outcomes and we will complete each task one by one.
Task 1 : Register a citrix developer account and create one app .
Outcome 1 : Receive Consumer key and Consumer Secret.
Task 2 : Authorize
Salesforce user on behalf of goToWebinar user .
Outcome 2 : Receive Authorization Code.
Task 3 : Request Access token using Above Authorization Code .
Outcome 3: Receive Access token
Taks 4 : Make API calls to citrix application using above access token.
Outcome 4 : Well ! both systems are integrated now .
Task 1 : Register a citrix
developer account and create one app.
1.
Create a visualforce page named ‘goToWebinar’ in your salesforce org..
3.
Register with your details.
4.
Click ‘Add a New App’.
5.
Set Application URL to your ‘goToWebinar’ visualforce
page URL.
4.
If you get ‘there was an error trying to create the
App. Please try again later’ error while creating app ,please go to https://developer.citrixonline.com/forum
and post your issue , citrix support will help you.
Outcome 1 : Receive Consumer
key and Consumer Secret.
Now we have Consumer key and
consumer secret which we will use in next task.
Task 2 : Authorize Salesforce user on
behalf of GoToWebinar user .
Paste
below code in your visualforce page. Click Authorize link, We will authorize
salesforce user with citrix systems on behalf of citrix User.
<apex:pageBlock >
<apex:pageBlockSection title="Authorize GoToWebinar" >
<apex:outputLink value="https://api.citrixonline.com/oauth/authorize? client_id=YOUR_CONSUMER_KEY">Authorize</apex:outputLink>
</apex:pageBlockSection>
</apex:pageBlock >
<apex:pageBlockSection title="Authorize GoToWebinar" >
<apex:outputLink value="https://api.citrixonline.com/oauth/authorize? client_id=YOUR_CONSUMER_KEY">Authorize</apex:outputLink>
</apex:pageBlockSection>
</apex:pageBlock >
Outcome 2 : Receive Authorization Code.
It will redirect to the callback url which is your
visualforce page only with authorization code as below.
Check your Browser URL will look like below URL carrying
authorization code.
https://ashishdev.ap1.visual.force.com/apex/goToWebinar?scope=&code=aeacc93a
Task 3 : Request Access token using Above Authorization Code .
In this step we will use Previous step Authorization Code to
get acess token,
We will make one apex http callout like below.
string aouthCode = apexpages.currentpage().getparameters().get('code');
stringacessTokenUrl='https://api.citrixonline.com/oauth/access_tokengrant_type=authorization_code&code='+aouthCode+'&client_id=YOUR_CONSUMER_KEY';
Http h = new Http();
// Instantiate a new HTTP request, specify the method (GET) as
well as the endpoint
HttpRequest req = new HttpRequest();
req.setEndpoint(acessTokenUrl);
req.setMethod('GET');
// Send the request, and return a response
HttpResponse res =
h.send(req);String body = res.getBody();
Outcome 3: Receive Access token
Debug your response json ,we have access token now.
Taks 4: Make API calls to citrix application using above access token.
We now have access token ,we can make GotoWebinar api calls
using above access token.
Here is sample callout to get all your historical webinars.
Here is sample callout to get all your historical webinars.
string webinarUrl='https://api.citrixonline.com/G2W/rest/organizers/'+organizerKey+'/historicalWebinars';
Http h1 = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req1 = new HttpRequest();
req1.setEndpoint(webinarUrl);
req1.setMethod('GET');
req1.setHeader('Content-Type','application/xml');
req1.setHeader('Authorization',jsonWrapObj.access_token);
// Send the request, and return a response
HttpResponse res1 = h1.send(req1);
String body1 = res1.getBody();
Http h1 = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req1 = new HttpRequest();
req1.setEndpoint(webinarUrl);
req1.setMethod('GET');
req1.setHeader('Content-Type','application/xml');
req1.setHeader('Authorization',jsonWrapObj.access_token);
// Send the request, and return a response
HttpResponse res1 = h1.send(req1);
String body1 = res1.getBody();
Outcome 4 : Debug
your response json .Well ! both systems are integrated now .
Full Working Code :
Full Working Code :
Here is full working code to get all historical webinars .
1 . Create below Apex class in your org.
public class JsonParser{
public String subject{get;set;}
public String description{get;set;}
public String timeZone{get;set;}
public list<times> times{get;set;}
public class times{
public String endTime{get;set;}
public String startTime{get;set;}
}
}
public String subject{get;set;}
public String description{get;set;}
public String timeZone{get;set;}
public list<times> times{get;set;}
public class times{
public String endTime{get;set;}
public String startTime{get;set;}
}
}
public with sharing class GoToWebinarController {
//MyMeetings
public List<JsonParser> meetingWrapperList{get;set;}
// aouth Details
public String aouthCode{get;set;}
public String acessTokenCode{get;set;}
public String organizerKey{get;set;}
String authorizationUrl ='https://api.citrixonline.com/oauth/authorize?client_id=dfG9oHrA2MVqQicN6aQSmk4BPJuPkb0N';
public GoToWebinarController(){
aouthCode = apexpages.currentpage().getparameters().get('code');
}
public PageReference goToWebinarHistoricalWebinars() {
String acessTokenUrl = 'https://api.citrixonline.com/oauth/access_token?grant_type=authorization_code&code='+aouthCode+'&client_id=dfG9oHrA2MVqQicN6aQSmk4BPJuPkb0N';
Http h = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req = new HttpRequest();
req.setEndpoint(acessTokenUrl);
req.setMethod('GET');
// Send the request, and return a response
HttpResponse res = h.send(req);
String body = res.getBody();
JSONWrapper jsonWrapObj = (JSONWrapper)JSON.deserialize(body, JSONWrapper.class);
acessTokenCode =jsonWrapObj.access_token;
organizerKey =jsonWrapObj.organizer_key;
system.debug(body);
string webinarUrl ='https://api.citrixonline.com/G2W/rest/organizers/'+organizerKey+'/historicalWebinars';
Http h1 = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req1 = new HttpRequest();
req1.setEndpoint(webinarUrl);
req1.setMethod('GET');
req1.setHeader('Content-Type','application/xml');
req1.setHeader('Authorization',jsonWrapObj.access_token);
// Send the request, and return a response
HttpResponse res1 = h1.send(req1);
String body1 = res1.getBody();
system.debug('--------------res1.getBody()--------------'+res1.getBody());
myMeetings = body1;
meetingWrapperList =(List<JsonParser>)JSON.deserialize(myMeetings, List<JsonParser>.class);
system.debug(meetingWrapperList);
return null;
}
public class JSONWrapper{
public Integer expires_in;
public String access_token;
public string organizer_key;
}
}
//MyMeetings
public List<JsonParser> meetingWrapperList{get;set;}
// aouth Details
public String aouthCode{get;set;}
public String acessTokenCode{get;set;}
public String organizerKey{get;set;}
String authorizationUrl ='https://api.citrixonline.com/oauth/authorize?client_id=dfG9oHrA2MVqQicN6aQSmk4BPJuPkb0N';
public GoToWebinarController(){
aouthCode = apexpages.currentpage().getparameters().get('code');
}
public PageReference goToWebinarHistoricalWebinars() {
String acessTokenUrl = 'https://api.citrixonline.com/oauth/access_token?grant_type=authorization_code&code='+aouthCode+'&client_id=dfG9oHrA2MVqQicN6aQSmk4BPJuPkb0N';
Http h = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req = new HttpRequest();
req.setEndpoint(acessTokenUrl);
req.setMethod('GET');
// Send the request, and return a response
HttpResponse res = h.send(req);
String body = res.getBody();
JSONWrapper jsonWrapObj = (JSONWrapper)JSON.deserialize(body, JSONWrapper.class);
acessTokenCode =jsonWrapObj.access_token;
organizerKey =jsonWrapObj.organizer_key;
system.debug(body);
string webinarUrl ='https://api.citrixonline.com/G2W/rest/organizers/'+organizerKey+'/historicalWebinars';
Http h1 = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req1 = new HttpRequest();
req1.setEndpoint(webinarUrl);
req1.setMethod('GET');
req1.setHeader('Content-Type','application/xml');
req1.setHeader('Authorization',jsonWrapObj.access_token);
// Send the request, and return a response
HttpResponse res1 = h1.send(req1);
String body1 = res1.getBody();
system.debug('--------------res1.getBody()--------------'+res1.getBody());
myMeetings = body1;
meetingWrapperList =(List<JsonParser>)JSON.deserialize(myMeetings, List<JsonParser>.class);
system.debug(meetingWrapperList);
return null;
}
public class JSONWrapper{
public Integer expires_in;
public String access_token;
public string organizer_key;
}
}
2. Create Below visualforce page.
<apex:page controller="GoToWebinarController" doctype="html-5.0">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Authorize GoToWebinar" >
<apex:outputLink value="https://api.citrixonline.com/oauth/authorize?client_id=dfG9oHrA2MVqQicN6aQSmk4BPJuPkb0N">Authorize</apex:outputLink>
</apex:pageBlockSection>
<apex:pageBlockSection title="aOuth Code" rendered="true">
{!aouthCode}
</apex:pageBlockSection>
<apex:pageBlockSection title="Access Token Code" rendered="true">
{! acessTokenCode}<br/>
{!organizerKey}
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="My Previous Webinars">
<apex:commandButton value="Display My Previous Webinars" action="{!goToWebinarHistoricalWebinars}"/>
<apex:pageBlockSection columns="1">
<apex:pageBlockTable value="{!meetingWrapperList}" var="myWebinar">
<apex:column >
<apex:facet name="header">Name</apex:facet>
{!myWebinar.subject}
</apex:column>
<apex:column >
<apex:facet name="header">Description</apex:facet>
{!myWebinar.description}
</apex:column>
<apex:column >
<apex:facet name="header">Start Time</apex:facet>
{!myWebinar.times[0].startTime}
</apex:column>
<apex:column >
<apex:facet name="header">End Time</apex:facet>
{!myWebinar.times[0].endTime}
</apex:column>
<apex:column >
<apex:facet name="header">Timezone</apex:facet>
{!myWebinar.timezone}
</apex:column>
<!--
<apex:column >
<apex:facet name="header">Registration URL</apex:facet>
<apex:outputLink value="{!myWebinar.registrationUrl}">Register</apex:outputLink>
</apex:column>
-->
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Authorize GoToWebinar" >
<apex:outputLink value="https://api.citrixonline.com/oauth/authorize?client_id=dfG9oHrA2MVqQicN6aQSmk4BPJuPkb0N">Authorize</apex:outputLink>
</apex:pageBlockSection>
<apex:pageBlockSection title="aOuth Code" rendered="true">
{!aouthCode}
</apex:pageBlockSection>
<apex:pageBlockSection title="Access Token Code" rendered="true">
{! acessTokenCode}<br/>
{!organizerKey}
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="My Previous Webinars">
<apex:commandButton value="Display My Previous Webinars" action="{!goToWebinarHistoricalWebinars}"/>
<apex:pageBlockSection columns="1">
<apex:pageBlockTable value="{!meetingWrapperList}" var="myWebinar">
<apex:column >
<apex:facet name="header">Name</apex:facet>
{!myWebinar.subject}
</apex:column>
<apex:column >
<apex:facet name="header">Description</apex:facet>
{!myWebinar.description}
</apex:column>
<apex:column >
<apex:facet name="header">Start Time</apex:facet>
{!myWebinar.times[0].startTime}
</apex:column>
<apex:column >
<apex:facet name="header">End Time</apex:facet>
{!myWebinar.times[0].endTime}
</apex:column>
<apex:column >
<apex:facet name="header">Timezone</apex:facet>
{!myWebinar.timezone}
</apex:column>
<!--
<apex:column >
<apex:facet name="header">Registration URL</apex:facet>
<apex:outputLink value="{!myWebinar.registrationUrl}">Register</apex:outputLink>
</apex:column>
-->
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
For More Citrix API References .Please refer below links.
This comment has been removed by the author.
ReplyDeleteThe website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface. jogos friv gratis
ReplyDeleteJogos online
jogos 4 school