Create an SCMRepository and Changeset with Rest API
search cancel

Create an SCMRepository and Changeset with Rest API


Article ID: 10740


Updated On:


Rally On-Premise Rally SaaS


How to create an SCMRepository and Changeset with Rest API (WS API).


Component: ACSAAS


Normally a changeset is created in Rally via integration with version control systems. It cannot be created in the UI. It can however be created directly in Web Services API, without using version control integration.


In WS API, the Changeset object has a couple of required fields, one of them an SCMRepository.


SCMRepository is also an object in WS API. It does not have to represent an actual version control repository, e.g, SVN repository.


In this example a browser REST client is used to create an SCMRepository and a Changeset on a defect.


1. Create API Key and use API Key for zsessionid header. 


Get security token (for OnPremises and Sandbox only)


Method: GetURL:


The response will include the token that will be used in the next step:
{"OperationResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": [], "Warnings": [], "SecurityToken": "<SECURITY_TOKEN>"}}


2. Create an SCMRepository object:


Method: Post


(If OnPremises or Sandbox, append the key to the request as in:<SECURITY_TOKEN>


Payload (request body):


"Description":"created with wsapi",


Notice that SCMRepository object has attribute Projects which is a collection of projects, hence this syntax:




After SCMRepository is created find out its reference. A query on SCMReposotory objects in WS API will return existing repositories. Here is an example of a return:


_rallyAPIMajor: "2",
_rallyAPIMinor: "0",
_ref: "<OBJECT_OID>",
_refObjectUUID: "<OBJECT_UUID>",
_refObjectName: "repo1",
_type: "SCMRepository"


We need to use this part: /scmrepository/<OBJECT_OID>


3. Create a Changset:


Changest object in WS API has required fiels: CommitTimeStamp, Revision, SCMRepository. Artifacts attribute, which is a collection of artifacts with which changeset is associated is not a required field.


Method: Post


Payload (request body):




A changeset is created:

Here is an example of creating a changeset with a curl command (API key is used for authentication):
curl --header "zsessionid:<API Key - include the underscore before the key>" -H "Content-Type: application/json" -d"{\"Changeset\":{\"Revision\":\"1\",\"SCMRepository\":\"/scmrepository/<OBJECT_OID>\",\"CommitTimestamp\":\"2014-12-17\",\"Message\":\"test\",\"Artifacts\":{\"Artifact\":\"/defect/<DEFECT_OID>\"}}}"