You need to sign in to do that
Don't have an account?
Avinash@salesforce
Integrate Salesforce with alexa webservice (Parsing the response)
Hi all.
I am integrating salesforce with an Alexa webservices. My scenario is to get the traffic history and save it in account object in salesforce.
I was able to get the XML Response which consists traffic history, but while parsing i am getting null response.
Below is my class.
I am using the Alexa Web Information Service traffic history API.
Need Help in parsing the response...!
My Class::
req.setEndpoint(endpoint);
req.setMethod('GET');
String responseBody;
Http http = new Http();
HttpResponse res = http.send(req);
String GlobalRank;
System.debug('STATUS:'+res.getStatus());
System.debug('STATUS_CODE:'+res.getStatusCode());
System.debug('BODY: '+res.getBody());
DOM.Document xmlDOC = new DOM.Document();
xmlDOC.load(res.getBody());
DOM.XMLNode rootElement = xmlDOC.getRootElement();
for(DOM.XMLNode xmlNodeObj:xmlDOC.getRootElement().getChildElements()){
Line 47 ========>> System.Debug('$$$ Child Elements'+xmlNodeObj);
for(DOM.XMLNode xmlNodeObjChild:xmlNodeObj.getChildren())
{
System.Debug('$$$ Childrens'+xmlNodeObjChild.getChildren());
system.debug('%%%%%%%%--'+xmlNodeObjChild.getName());
if(xmlNodeObjChild.getName()=='Range')
System.Debug(xmlNodeObjChild.getText());
if(xmlNodeObjChild.getName()=='Site')
System.Debug(xmlNodeObjChild.getText());
if(xmlNodeObjChild.getName()=='Start')
System.Debug(xmlNodeObjChild.getText());
}
}
// return GlobalRank.trim()<>''? Integer.valueOf(GlobalRank.trim()):null;
return null;
}
private static void calculateTimeStamp(){
Datetime now = Datetime.now();
timestamp = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'.'+now.formatGMT('SSS')+'Z';
System.Debug('Formatted date : '+timestamp);
}
private static void generateAWSSignature(String verb ,String action, String request){
String canonical = verb+'\n'+
'awis.amazonaws.com\n'+
'/\n'+
request;
system.Debug('String to Sign:\n'+canonical+'\n');
Blob bsig = Crypto.generateMac('HmacSHA1', Blob.valueOf(canonical), Blob.valueOf(secretAccessKey));
String signature = EncodingUtil.base64Encode(bsig);
AWSSignature = signature;
}
}
Need Help in parsing the response from alexa.!
I am integrating salesforce with an Alexa webservices. My scenario is to get the traffic history and save it in account object in salesforce.
I was able to get the XML Response which consists traffic history, but while parsing i am getting null response.
Below is my class.
I am using the Alexa Web Information Service traffic history API.
Need Help in parsing the response...!
My Class::
req.setEndpoint(endpoint);
req.setMethod('GET');
String responseBody;
Http http = new Http();
HttpResponse res = http.send(req);
String GlobalRank;
System.debug('STATUS:'+res.getStatus());
System.debug('STATUS_CODE:'+res.getStatusCode());
System.debug('BODY: '+res.getBody());
DOM.Document xmlDOC = new DOM.Document();
xmlDOC.load(res.getBody());
DOM.XMLNode rootElement = xmlDOC.getRootElement();
for(DOM.XMLNode xmlNodeObj:xmlDOC.getRootElement().getChildElements()){
Line 47 ========>> System.Debug('$$$ Child Elements'+xmlNodeObj);
for(DOM.XMLNode xmlNodeObjChild:xmlNodeObj.getChildren())
{
System.Debug('$$$ Childrens'+xmlNodeObjChild.getChildren());
system.debug('%%%%%%%%--'+xmlNodeObjChild.getName());
if(xmlNodeObjChild.getName()=='Range')
System.Debug(xmlNodeObjChild.getText());
if(xmlNodeObjChild.getName()=='Site')
System.Debug(xmlNodeObjChild.getText());
if(xmlNodeObjChild.getName()=='Start')
System.Debug(xmlNodeObjChild.getText());
}
}
// return GlobalRank.trim()<>''? Integer.valueOf(GlobalRank.trim()):null;
return null;
}
private static void calculateTimeStamp(){
Datetime now = Datetime.now();
timestamp = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'.'+now.formatGMT('SSS')+'Z';
System.Debug('Formatted date : '+timestamp);
}
private static void generateAWSSignature(String verb ,String action, String request){
String canonical = verb+'\n'+
'awis.amazonaws.com\n'+
'/\n'+
request;
system.Debug('String to Sign:\n'+canonical+'\n');
Blob bsig = Crypto.generateMac('HmacSHA1', Blob.valueOf(canonical), Blob.valueOf(secretAccessKey));
String signature = EncodingUtil.base64Encode(bsig);
AWSSignature = signature;
}
}
Need Help in parsing the response from alexa.!
[1] http://blog.deadlypenguin.com/blog/2015/11/30/json-deserialization-in-salesforce/
But the response it is returning is in XML format. How do i use JSON (Or) Is there any way that alexa returns itsresponse in JSON.
Thaanks,
Avinash
https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference