+ Start a Discussion
pavan bommana 5pavan bommana 5 

Not able to create a userstory in rally through basic authentication in rest api

I am able to create a userstory with this api in POSTMAN but it is showing error in apex class.
public class rallyIntegrate {
    public string variable;
    public string securityToken;
    public void getSourcetoken(){
       HTTP h = new HTTP();
        HTTPRequest r = new HTTPRequest();        
        r.setEndpoint('https://rally1.rallydev.com/slm/webservice/v2.0/security/authorize');
        Blob headerValue = Blob.valueOf(UserName+ ':' +Password );
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        r.setHeader('Authorization', authorizationHeader);
        r.setMethod('GET');
        HTTPResponse resp = h.send(r);
        system.debug('34====='+resp.getStatus());
        system.debug('35====='+resp.getStatusCode());
        system.debug('35====='+resp.getBody());
        variable = resp.getBody();
        system.debug('===+++'+variable.substringAfter('OperationResult').substringBetween('SecurityToken": "','"}}')); 
         securityToken = variable.substringAfter('OperationResult').substringBetween('SecurityToken": "','"}}');
    }
    public void getSourceBody(){
        string body = '{"HierarchicalRequirement":{"Name":"Rally full Test","Description":"Created my second user story"}}';
        HTTP htt = new HTTP();
        HTTPRequest req = new HTTPRequest(); 
        req.setEndpoint('https://rally1.rallydev.com/slm/webservice/v2.0/defect/create?key='+securityToken);
        req.setHeader('Content-Type', 'application/json');
        req.setMethod('POST');
        req.setBody(body);
        HTTPResponse res = htt.send(req);
        system.debug('response++  '+res.getBody());
    }
}

ERROR : Full authentication is required to access this resource.
Can anyone help me in this please.
SwethaSwetha (Salesforce Developers) 
HI Pavan,
Can you check if you are running behind a proxy? Have you ensured that the Salesforce IP ranges mentioned in https://help.salesforce.com/articleView?id=000321501&type=1&mode=1 are whitelisted at your Third party?

Related: https://github.com/jenkinsci/rally-plugin/issues/15
https://github.com/RallyTools/rally-node/issues/30

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you