Rally Software

Expand all | Collapse all

I'm trying to create UserStories programmatically. I generated my APIKey and appending it to post URL.But I'm facing some issues. Here, essentially, is the code:

  • 1.  I'm trying to create UserStories programmatically. I generated my APIKey and appending it to post URL.But I'm facing some issues. Here, essentially, is the code:

    Posted Mar 02, 2018 03:56 PM
    import requests, json   
    rally_auth
    = ('**uid', '***pwd')   
    rally_auth_url
    = 'https://rally1.rallydev.com/slm/webservice/v2.0/security/authorize'   
    rally_defect
    = 'https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement'   
    workspace_ref
    = 'https://rally1.rallydev.com/slm/webservice/v2.0/workspace/123***'   
    fe_project_ref
    = 'https://rally1.rallydev.com/slm/webservice/v2.0/project/134***'                               
    user_ref
    = 'https://rally1.rallydev.com/slm/webservice/v2.0/user/106***'   
    l2_ref
    = 'https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/l2roadmapitem/166***'    
    headers
    = {"Accept": "application/json", "Content-Type": "application/json", "ZSESSIONID" : "_iv********"}    
    s
    = requests.Session()   
    token
    = '_iv**********'   
    url
    = rally_defect + '/create?key=' + token     
    payload
    = {'Workspace' : workspace_ref,     
               'Name': 'Tesing',     
               'Description': 'Testing',     
               'Project': fe_project_ref,     
               'StoryType': "New Feature",       
               'PortfolioItem' : l2_ref,     
               'Owner' : user_ref,     
               'ScheduleState':'Defined',
    }   
    r
    = s.put(url, data=json.dumps(payload), headers=headers)    
    print r.text     
    print r.status_code

     

    {"CreateResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": ["Cannot parse input stream due to I/O error as JSON document: Parse error: expected '}' but saw ',' [ chars read = \u003E\u003E\u003E{\"Project\": \"https://rally1.rallydev.com/slm/webservice/v2.0/project/13453299863\",\u003C\u003C\u003C ]"], "Warnings": []}}

     

     



  • 2.  Re: I'm trying to create UserStories programmatically. I generated my APIKey and appending it to post URL.But I'm facing some issues. Here, essentially, is the code:
    Best Answer

    Posted Mar 05, 2018 06:16 AM

    nani9999,

     

    You will need to provide the Artifact type in your JSON. Below is an update to your code that should work for you. I am also assuming 'StoryType' is a Custom String Field. You will need to update the name to 'c_StoryType' to add a value to a Custom Field.

     

    I also removed some of the extra lines. Since you are using an API Key and setting it as the ZSessionID in the Headers, you will not need the Security Token to create the Artifact.


    import requests, json

    rally_defect = 'https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement'
    workspace_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/workspace/123***'
    fe_project_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/project/134***'
    user_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/user/106***'
    l2_ref = 'https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/l2roadmapitem/166***'

    headers = {"Accept": "application/json", "Content-Type": "application/json", "ZSESSIONID" : "_iv********"}

    s = requests.Session()
    url = rally_defect + '/create'

    payload = {
    "HierarchicalRequirement" : {
    "Workspace" : workspace_ref,
    "Name" : "Tesing",
    "Description" : "Testing",
    "Project" : fe_project_ref,
    "c_StoryType" : "New Feature",
    "PortfolioItem" : l2_ref,
    "Owner" : user_ref,
    "ScheduleState" : "Defined"
    }
    }

    r = s.put(url, data=json.dumps(payload), headers=headers)

    print r.text

     

    print r.status_code



  • 3.  Re: I'm trying to create UserStories programmatically. I generated my APIKey and appending it to post URL.But I'm facing some issues. Here, essentially, is the code:

    Posted Mar 06, 2018 05:25 AM

    nani9999,

     

    I know you accepted my answer on Stackoverflow, but if you would please mark this one correct as well when you have a chance.  Thank you!

     

    Michael