If you have any question left, please drop a note with the discussion link of this page.

Javascript Getting Started Example

From Wiki.zanox.com

Jump to: navigation, search

Thanks to Steffen for this example:

// Userrequest = zanox service method
var resourceURL = 'http://api.zanox.com/json/' + UserRequest ;         
// Resource = other zanox ressource parameter
resourceURL    += ( Resource != null && Resource !=  ? '/' + Resource :  ); 
// page = pages to be delivered by the web service (here as a fixed parameter 1!)
resourceURL    += '?page=' + Page; 
resourceURL    += ( Items == null || Items ==  ?  : '&items=' + Items );
// SearchTerm = search term (URL encoding!)
resourceURL    += ( SearchTerm == null || SearchTerm ==  ?  : '&q=' + SearchTerm.encoding(/ /g, "+")) ; 
          
var Jetzt       = new Date();
// in GMT format; see also: encoding test tool
var gmtDate     = Jetzt.GMTString();
var stringToSign = "GET/" + UserRequest + ( Resource !=  ? '/'+Resource :  )+ gmtDate;
// key = shared zanox key; see also: http://www.actionscript-praxis.de/forum/viewtopic.php?t=401&view=previous (german)
var sha1 =  b64_hmac_sha1( Key , stringToSign  ) ;  
// ajax call tool of your choice; see also: http://www.sitewardslandia.com/97-ajax-loesungen-2007 (german)
var myClient = new AjaxClient();    

myClient.setRequestHeader( 'Authorization', ZanoxApplicationID + ':' + sha1 + '=' );            
myClient.setRequestHeader( 'Date', gmtDate  );
myClient.open( 'GET', resourceURL );
myClient.send();
// the variable Json contains the result of the zanox request in a JSON format
Json = myClient.getText();
Personal tools