function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
batrulzbatrulz 

Accessing "Rally" Rest service from Apex

I am new to using Rest services .I am trying to access Rally rest service (https://rally1.rallydev.com/slm/doc/webservice/) , i tried using :

HttpRequest req = new HttpRequest();
     req.setEndpoint('https://rally1.rallydev.com/slm/webservice/v2.0/task.js');
     req.setMethod('GET');
    
     // Specify the required user name and password to access the endpoint
     // As well as the header and header information

     String username = 'myname';
     String password = 'mypwd';
 
     Blob headerValue = Blob.valueOf(username + ':' + password);
     String authorizationHeader = 'BASIC ' +
     EncodingUtil.base64Encode(headerValue);
     req.setHeader('Authorization', authorizationHeader);
  
     // Create a new http object to send the request object
     // A response object is generated as a result of the request 
 
     Http http = new Http();
     HTTPResponse res = http.send(req);
     System.debug(res.getBody());


But it didnt work , i go a 401 response code back.
How do i get the security token and use it in my queries ? Has anyone integrated with Rally using Apex ?
Best Answer chosen by batrulz
AsitM9AsitM9
Change 
String authorizationHeader = 'BASIC ' +  

to

String authorizationHeader = 'Basic ' + 

It will work.

All Answers

justin_sfdcjustin_sfdc
The error 401 means that the username and password is incorrect;

http://www.salesforce.com/us/developer/docs/api_rest/index_Left.htm#CSHID=errorcodes.htm|StartTopic=Content%2Ferrorcodes.htm|SkinName=webhelp

Please check that you have correct username and password.
Try that going to the endpoint using your browser and put your username and pwd in it.
batrulzbatrulz
the username and password are correct; i have tried putting the url directly into the browser and then entering my username , password and it works
AsitM9AsitM9
Change 
String authorizationHeader = 'BASIC ' +  

to

String authorizationHeader = 'Basic ' + 

It will work.
This was selected as the best answer