how to read changeset for perticular user story and update the build column using REST API- java? - rally

currently i'm looking for solution to read and update the user story changesets using Rally java REST Api.
how do i do it?

Sharan,
This previous post may be a good starting point:
Rally update Changeset data from Java using Java Toolkit for Rally REST API
EDIT:
Sharan,
I did some fiddling around and found that I could not update the Builds on Changeset, but I could add a Changeset to a Build.
You'll need to know the _ref URL for the Build and Changeset you want to use, but then it is pretty straight forward. I used Apache HTTP Client to do the operations below. The header, 'zsessionid' is your API Key for Authentication.
DefaultHttpClient httpClient = new DefaultHttpClient();
String jsonString = "{\"Build\":{\"Changesets\": {\"Changeset\":\"https://rally1.rallydev.com/slm/webservice/v2.0/changeset/123456\"}}}";
HttpPost postRequest = new HttpPost("https://rally1.rallydev.com/slm/webservice/v2.0/build/123456");
postRequest.setHeader("zsessionid", "_ApIK3y");
postRequest.setHeader("content-type", "application/json");
postRequest.setEntity(new StringEntity(jsonString));
HttpResponse response = httpClient.execute(postRequest);
System.out.println(EntityUtils.toString(response.getEntity()));
Hope that helps.

Related

Token management in Karate parallel execution

Scenario : All the endpoints in my API test need authentication and hence authorization header needs to be passed. I have Authentication.feature file where I read refresh token from a file, generate new access token, write the new refresh token back to the file. After running each scenario, I need to update the refresh token back to the file and it will be consumed by next feature. Authentication.feature file is called from karate-config.js file and authentication header is set as shown below
var response = karate.call('classpath:Test/features/Authentication.feature',config).response;
var token = response.access_token
karate.configure('headers',{Authorization: 'Bearer '+token});
Everything till now is working fine, but when I use junit5 parallel runner, it causes issues with the authentication token. Not the latest refresh token is written to the file. I tried by making the file read/write part synchronized, but it does not solve the problem. Also I tried #parallel=false annotation in Authentication.feature, still no luck. How can I make my test run parallel at the same time it correctly update the file with latest refresh token
The recommended way to do this is to use karate.callSingle() - please read about it if you haven't already: https://github.com/karatelabs/karate#hooks
Note that this code example below is JS in karate-config.js:
var result = karate.callSingle('classpath:some/package/my.feature');
Also see this answer for some other ideas: https://stackoverflow.com/a/53516885/143475

Dynamically setting request headers for REST request using Postman Interceptor

Is it possible to dynamically (automatically) set request headers for REST request using Postman Interceptor? We are currently setting multiple headers for each new request in a collection manually, we'd like to automate this if possible. How to achieve and please provide an example? thanks in advance.
p.s. I am not talking about writing a pre-request script unless we can write a global script that will be automatically used when we create each new request. The solution needs to be fully automated so we don't need to manually write the header key/value pairs for each new request. The key names will be the same each request and the values will be the same as well (environment variables).
using v4.10.7 of Postman for Mac.

Send data to a REST API every time a new account is added to Salesforce

Sorry for the total newbie question here regarding triggers, but here is my scenerio:
What are some of the options available to send data to a 3rd party REST API every time a new account is added to Salesforce?
I have been initially looking at code examples for triggers on account after insert. In addition to this, is there a way using the SFDC streaming API? Any ideas on What API usage is best practice + code examples would be much appreciated.
Thanks in advance!
To be able to make callout from a trigger you need to make the callout asynchronous (using #future annotation) .
For example :
trigger AfterInsertAccount on Account (after insert){
futCls.asynchCallout(); //call a method with #future annotation
}
Class Code :
global futCls {
#future
Public static void asynchCallout(callout=true){
HttpRequest req = new HttpRequest();
req.setEndpoint('your 3rd party service URL goes here');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
}
}
For more information refer to SFDC documentation.

How to send a request to an external API

I am new to Symfony2 and I'm trying to send a
new Request()
to and external API. This is what I have but I don't know if it is correct use of the built in request/response library.
$request = new Request('https://myservice.com/apimethod?foo=bar', 'GET');
Can anyone tell me if this will return a response provided the API I'm trying to call exists?! If not, what am I doing wrong?
In Symfony2, the Request class represents an HTTP request made to your site. Basically, if you go to www.yoursite.com/someaction Symfony instantiates aSymfony\Component\HttpFoundation\Request object. This object contains methods that you can use to examine the HTTP request (such as seeing if it contains GET or POST variables.)
This is a good explanation of Symfony and HTTP fundamentals. I also recommend looking at the source code for Request to see exactly what it can do.
In order to achieve what you're trying to do in your example, you'd need to use cURL. I personally use a wrapper class on top of cURL that you can find here.
Hope this helps.
https://github.com/CircleOfNice/CiRestClientBundle
It's the easiest way to send a request to an external API. It provides all http methods as functions and is easy to use.
$restClient = $this->container->get('ci.restclient');
$restClient->get('http://www.someUrl.com');
$restClient->post('http://www.someUrl.com', 'somePayload');
$restClient->put('http://www.someUrl.com', 'somePayload');
$restClient->delete('http://www.someUrl.com');
$restClient->patch('http://www.someUrl.com', 'somePayload');
$restClient->head('http://www.someUrl.com');
$restClient->options('http://www.someUrl.com', 'somePayload');
$restClient->trace('http://www.someUrl.com');
$restClient->connect('http://www.someUrl.com');
If you want to use rest clients just to CRUD entities then I think you should have a look at
https://github.com/CircleOfNice/DoctrineRestDriver
which helps you to get rid of manually sending requests and mapping responses because Doctrine is doing the job for you.
// Sends a GET request to http://$driverUrl/#TableAnnotation/1 and returns a valid MyEntity Entity
$entity = $em->find("Some\Namespace\MyEntity", 1);
Someone else answered a question like this: https://stackoverflow.com/a/10715549/2306587
You don't have to rely on cURL to make an external request. There is a Symfony-Bundle who can handle that: http://knpbundles.com/sonata-project/SonataGoutteBundle
Use Guzzle from here.
Exemple:
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
echo $res->getStatusCode();

CCNet API, docs?

I want to query my CCNet server to find out the status of the builds. I've heard rumor that there's a (ReST?) API of sorts, but I can't seem to find any documentation for it.
Is there any documentation for it, or do I need to download the CCNet source code and start reading?
EDIT: I found the endpoint /XmlStatusReport.aspx, which gives an XML overview of all projects. The same filename in any folder gives exactly the same response, though, so I'm afraid that might be the only API there is.
As an alternative to the XML you already mentioned yourself, you could use remoting as the CCTray app does. If you reference ThoughtWorks.CruiseControl.Remote.dll form the CruiseControl.NET\server folder you can instantiate CruiseServerRemotingClient and use it to retrieve information from the server.
The following snippet prints out the list of projects on the server and their build statuses:
CruiseServerRemotingClient client = new CruiseServerRemotingClient("tcp://ccnetserver:21234/CruiseManager.rem");
ProjectStatus[] statusList = client.GetProjectStatus();
foreach (ProjectStatus status in statusList)
{
Console.WriteLine("{0}: {1}", status.Name, status.BuildStatus);
}
You could also retrieve the log for the latest build in XML format as follows:
string buildName = client.GetLatestBuildName("Jasenje");
Console.WriteLine(client.GetLog("Jasenje", buildName));
I haven't managed to find any real documentation for the API but at least there are XML comments with brief descriptions of methods and parameters.