How to authenticate and get Rally data using Google Apps Script
search cancel

How to authenticate and get Rally data using Google Apps Script

book

Article ID: 57523

calendar_today

Updated On:

Products

Rally On-Premise Rally SaaS

Issue/Introduction

Per Google Apps Script documentation Apps Scrip can connect to public APIs.

Is there an example of Apps Script connecting to Rally WSAPI?

 

Resolution

NOTE: Troubleshooting 3rd party APIs and writing and debugging custom code is outside of Rally support's scope. The example below comes as is.

1. Basic authentication:

function myFunction() {
  var username = "<USERNAME>"
  var password = "<PASSWORD>"
  var headers={
    "contentType": "application/json",
    "headers": {
      "Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)
    }
  }
  
 var url = 'https://rally1.rallydev.com/slm/webservice/v2.0/defect?'
??? + 'workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/<WORKSPACE_OID>'
??? + '&pagesize=200'
??? + '&fetch=FormattedID'
??? + '&query=((State = Submitted)OR(State = Open))';
var response = UrlFetchApp.fetch(url,headers);
Logger.log(response);
}




2. API Key:

ApiKey is supported in production (rally1.rallydev.com). It is currently not supported on Sandbox (sandbox.rallydev.com) and in On-Premises. A zsessionid header is set to an ApiKey.

function myFunction() {
  var headers={
    "contentType": "application/json",
    "headers":{"zsessionid":"<API Key - include the underscore before the key>"} 
  }
  
  var url = 'https://rally1.rallydev.com/slm/webservice/v2.0/defect?'
??? + 'workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/<WORKSPACE_OID>'
??? + '&pagesize=200'
??? + '&fetch=FormattedID'
??? + '&query=((State = Submitted)OR(State = Open))';
var response = UrlFetchApp.fetch(url,headers);
Logger.log(response);
}

 

Troubleshooting tips:

Test your query directly in WS API and in the browser before using it with Google Apps Script.
For example, here is a direct endpoint that returns children of PortfolioItem/Initiative:

https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/initiative/<INITIATIVE_OID/children?workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/<WORKSPACE_OID>&fetch=FormattedID

Here is the equivalent query in Google Apps Script

function myFunction() {
  var headers={
    "contentType": "application/json",
    "headers":{"zsessionid":"<API Key - include the underscore before the key>"}
  }
  
  var url = 'https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/initiative/<INITIATIVE_OID>/children?'
    + 'workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/<WORKSPACE_OID>'
    + '&pagesize=200'
    + '&fetch=FormattedID';
var response = UrlFetchApp.fetch(url,headers);
Logger.log(response);
}