How to authenticate and get CA Agile Central data using Google Apps Script

Document ID : KB000057523
Last Modified Date : 14/02/2018
Show Technical Document Details

Issue

Per Google Apps Script documentation Apps Scrip can connect to public APIs.
Is there an example of Apps Script connecting to CA Agile Central WS API?

Resolution

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

1. Basic authentication:
?
function myFunction() {
  var username = "user@company.com"
  var password = "secret"
  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/12352608129'
??? + '&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, _abc123 in the example below:
?
function myFunction() {
  var headers={
    "contentType": "application/json",
    "headers":{"zsessionid":"_abc123"} 
  }
  
  var url = 'https://rally1.rallydev.com/slm/webservice/v2.0/defect?'
??? + 'workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/12352608129'
??? + '&pagesize=200'
??? + '&fetch=FormattedID'
??? + '&query=((State = Submitted)OR(State = Open))';
var response = UrlFetchApp.fetch(url,headers);
Logger.log(response);
}

User-added image

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/39358928290/children?workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/17465508792&fetch=FormattedID
User-added image
Here is the equivalent query in Google Apps Script
?
function myFunction() {
  var headers={
    "contentType": "application/json",
    "headers":{"zsessionid":"_abc123"}
  }
  
  var url = 'https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/initiative/39358928290/children?'
    + 'workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/17465508792'
    + '&pagesize=200'
    + '&fetch=FormattedID';
var response = UrlFetchApp.fetch(url,headers);
Logger.log(response);
}

?