1

Integrating Salesforce to Azuredevops, Creating Issue/Task/Bug to Azuredevops from the Salesforce custom page by using POST method RestApi. Doing the same from postman service by using same url ,accesstoken etc and i am able to create task in the Azuredevops.

But issue is when i try the same from salesforce I am getting the response back as

"System.HttpResponse[Status=Found, StatusCode=302]" and <html><head><title>Object moved</title></head><body> <h2>Object moved to <a href="https://*******.*****.visualstudio.com/_signin*********************

I am using Namedcredential in the salesforce, and written code like below,

Httprequest request = new HttpRequest();
Http http = new Http();        
request.setMethod('POST');
request.setEndpoint('callout:Namedcred' + '/*****/******/_apis/wit/workitems/$issue?api-version=6.0' );
request.setHeader('Content-Type', 'application/json-patch+json');            
request.setHeader('Authorization',  '{!$Credential.Password}');
request.setBody(requestBody);
HttpResponse response = http.send(request);

I tried the same from the postman service and everything working good and also getting 200 OK status

  • Hello, i hope that couple of spaces are only added by mistake ? :) are you using a https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-items/create?view=azure-devops-rest-7.0&tabs=HTTP ?? I have similar problem with authentication and i use a PAT as a BASE64 and that helps – Cezu Jan 28 '23 at 16:50
  • @Cezu Yes those spaces were added by mistake while posting here ,I corrected that now. url using is , https://dev.azure.com/*****/******/_apis/wit/workitems/$issue?api-version=6.0 PYI: *******/******/is my official azuredevops project name – Ranganath C N Jan 30 '23 at 05:45
  • I think there is a problem with authentication are you using a PAT ? https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows and try to convert your password using : ```String myBase64String = EncodingUtil.base64Encode(Blob.valueof(myString));``` – Cezu Jan 31 '23 at 07:32
  • @Cezu Yes i am Using PAT.After the conversion i am getting unauthorised error. – Ranganath C N Feb 02 '23 at 16:30

0 Answers0