How to create and update an artifact in Rally using a curl command with a security token
search cancel

How to create and update an artifact in Rally using a curl command with a security token

book

Article ID: 277404

calendar_today

Updated On:

Products

Rally SaaS

Issue/Introduction

How to create and update an artifact in Rally using a curl command with a security token

Resolution

If a user updates, creates, or deletes Rally artifacts Using our Rest API outside of a browser (ex: when using curl) the session has to be maintained manually. Without a session cookie, each curl request (in our case getting the token and the post request to update an artifact) will constitute separate HTTP sessions.

 

Step 1:

Tell curl to store a session cookie in order to persist the HTTP session in the terminal.  Then cd to the working directory

curl -u "<RallyUsername>:<PASSWORD>" https://rally1.rallydev.com/slm/webservice/v2.0/security/authorize -c rally1cookie.txt   (The Rally Username is in email format)

 

****Note the output in the terminal from the curl above, which includes the security token you will append to your post request in the next step:

{"OperationResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": [], "Warnings": [], "SecurityToken": "<SECURITY_TOKEN>"}}

 

****A file rally1cookie.txt will be created in the working directory. Here is a content example:

# Netscape HTTP Cookie File

# https://curl.se/docs/http-cookies.html

# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_rally1.rallydev.com   FALSE   /       FALSE   1703276148      __cflb  abctest

rally1.rallydev.com     FALSE   /       TRUE    0       SERVERID        xyztest

#HttpOnly_rally1.rallydev.com   FALSE   /       TRUE    <ServerID>      _username       <RallyUsername>

#HttpOnly_.rally1.rallydev.com  TRUE    /       TRUE    0       SUBSCRIPTIONID  <SubscriptionNumber>

#HttpOnly_.rally1.rallydev.com  TRUE    /       TRUE    0       SUBBUCKETID     <SubscriptionNumber>

#HttpOnly_.rally1.rallydev.com  TRUE    /       TRUE    <ServerID>      ZSESSIONID      <ZsessionID>

#HttpOnly_rally1.rallydev.com   FALSE   /       TRUE    0       JSESSIONID      <JsessionID>

 

Step 2:

Here is the curl command to create a defect:

curl -i -X POST  -H "Content-Type: application/json"  -d '{

"Defect": {

  "Workspace": {

   "_ref": "/workspace/<Workspace_ObjectID>"

  },

    "Project": {

   "_ref": "/project/<Project_ObjectID>"

  },

  "Name": "Test for Security Token",

  "ScheduleState": "Defined",

  "State": "Submitted"

}

}' 'https://rally1.rallydev.com/slm/webservice/v2.0/defect/create?key=<SecurityToken>' -b rally1cookie.txt

 

The output in the terminal will include a full JSON. Success!

 

Here is a curl command to update a defect

curl -v -u "<User>@<Company.com>:<PASSWORD>" -H "Content-Type: application/json" -d"{\"Defect\":{\"Resolution\":\"Not a Defect\",\"State\":\"Fixed\"}}" https://rally1.rallydev.com/slm/webservice/v2.0/Defect/<Defect_OID>?key=<SECURITY_TOKEN> -b rally1cookie.txt