Rally Software

 View Only
  • 1.  How to add an Attachment to a User Story using Rally Rest API

    Posted Oct 18, 2019 12:39 PM
     is it possible to send an attachment (.doc or a .xls) file along with other details  while creating an user story using rest API?

      I'm using the below JSON script and I'm getting a error "cannot find referenced object

    '{"HierarchicalRequirement": { "Name": "Test SRM Connector", 
      "Description": "Please ignore this user story...",
     "_refObjectName": "Regi Varghese",
     "c_WorkType" : "Maintenance",
     {"Attachment":{"Content":"aGVsbG8gd29ybGQ=","ContentType":"octet-stream","Name":"a.txt","Size":"20"}} } }');

    request.setMethod('PUT');

    Getting the below error:

    USER_DEBUG [63]|DEBUG|{"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{\"HierarchicalRequirement\": { \"Name\": \"Test SRM Connector\",\"Description\": \"Please ignore this user story...\",\"_refObjectName\": \"

    Any help is appreciated.

    Thanks

    ------------------------------
    Regi
    ------------------------------


  • 2.  RE: How to add an Attachment to a User Story using Rally Rest API

    Broadcom Employee
    Posted Oct 18, 2019 03:35 PM
    Hi Regi.

    Yes, it's possible to create a user story with an attachment using Rally's API. However, it can't all be done in a single http call.

    In your code there are a few issues:
    - On the HierarchicalRequirement you're referencing a field named: "Attachment". The actual field's name is: "Attachments" (plural).
    - You're trying to create the attachment together with creating the user story.

    The reason you can't create the attachment with the user story is because Attachment is a separate endpoint, which also happens to reference an AttachmentContent object as well (that holds the actual contents). The process shall be: (1) create the AttachmentContent (2) create the Attachment and refer the newly created content (3) create the user story and refer the newly created attachment.

    Here is a working example:

    Step 1: Creating an AttachmentContent:
    {"AttachmentContent":{"Content":"HERE YOU SHALL FILL IN YOUR BASE-64-BINARY FILE CONTENT"}}

    You will receive an ObjectID for the newly created AttachmentContent, we're going to use it in step 2.

    Step 2: Creating an Attachment:

    {"Attachment":
       {
          "Description":"User Story with Attachment",
          "User":"/user/<Fill in your user OID>",
          "ContentType":"text/plain",
          "Content": {
             "_ref":"/attachmentcontent/<Fill in your AttachmentContent OID received in step1>"
         },
         "Artifact":"/artifact/<Fill in your artifact OID>",
         "Name":"TestFile.docx"
      }
    }

    You shall again receive an ObjectID of the newly created Attachment object. You will use it in step 3.

    Step 3: Create a user story and include the attachment:

    {
       "hierarchicalrequirement":
       {
          "Name": "My User Story",
          "Description: "Test User Story with Attachment",
          "Project":"/project/<Fill in your project OID>",
          "Attachments": [
             { "_ref": "/attachment/<Fill in the Attachment OID from step 2>" }
         ]
       }
    }


    I hope this helps. Let us know if questions.

    Sagi


  • 3.  RE: How to add an Attachment to a User Story using Rally Rest API
    Best Answer

    Broadcom Employee
    Posted Oct 22, 2019 08:46 PM
    Hi Regi,

    I received an email from you, but for some reason I can't reply. I'm getting an 'undelivered' message. Below is your email that I had received.
    I believe you are using the ObjectUUID instead of the ObjectID. So, when you look at the error message that shows: "7e5e07ca-bb9f-4725-82b6-5528266f3f34" , this value is of an ObjectUUID. However, you need to use the ObjectID instead.

    Can you try that and let us know if it worked.

    Thanks,
    Sagi

    Your email
    Hi Sagi

    Thanks for your detailed explanation. 

    While following your steps,  In step 2 , I am getting the following error.

    I got the OID from the first step - and I am trying to reference that in Step2.

    USER_DEBUG [92]|DEBUG|{"CreateResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": ["Could not read: Could not read referenced object /attachmentcontent/7e5e07ca-bb9f-4725-82b6-5528266f3f34"], "Warnings": []}}

    The code I tried is

    description = 'This is my story'; description = 'This is my story';     

    //String UsContent = '"_ref":"/attachmentcontent/'+ Jstring + '"' ;      
    System.debug('UsContent' + UsContent);       
    endpoint = 'https://rally1.rallydev.com/slm/webservice/v2.0/attachment/create';   
     HttpRequest request1 = new HttpRequest();     
      request.setEndPoint(endpoint);     
      request.setBody('{"Attachment":{"Description": "{description}","ContentType":"text/plain","User":"/user/195975401488","Content":{"_ref":"/attachmentcontent/7e5e07ca-bb9f-4725-82b6-5528266f3f34"}, "Name":"TestFile.docx"}}'); 
     request.setMethod('PUT');   
      HttpResponse response1= httpProtocol.send(request);     
      System.debug(response1.getStatus());       
      System.debug(response1.getBody());


  • 4.  RE: How to add an Attachment to a User Story using Rally Rest API

    Broadcom Employee
    Posted Oct 23, 2019 09:28 PM
    Thank you Regi.  
    I'm glad it worked out for you. :)

    Your email
    Thanks Sagi, It worked. 

    OID did the magic.

    Thanks for your support.


    ------------------------------
    RV


  • 5.  RE: How to add an Attachment to a User Story using Rally Rest API

    Posted Feb 16, 2023 07:24 PM

    This message says we can create a work item and simultaneously add items to one of its collections, in this case its Attachments collection. I am finding it possible to create a Defect and simultaneously assign values to its non-collection properties, but, using the pattern shown, i.e. where the collection name is the key and an array of objects with _ref as keys and references as values is the value, I am not getting anything assigned to the collection property when the Defect is created. In my case the collection property is a multi-valued custom property with allowed values, so the references are references to those allowed values. I get no error message. I simply do not get values added to the property. Any idea why this might be?

    Probably not helpful, but, in case it is, here is how I am constructing the body:

          Defect: {
            Name: `${tpusData.testCase.Name} - Duplicate IDs`,
            Project: tpusData.tpus.Project._ref,
            Owner: tpusData.tpus.Owner._ref,
            ScheduleState: 'Defined',
            TestCase: tpusData.testCase._ref,
            Severity: 'Major Problem',
            Priority: 'High Attention',
            c_A11yWCAGSuccessCriteriaMultiValue: [
              {_ref: '/allowedattributevalue/675314579201'}
            ],
            c_A11yWeightedPoints: tpusData.testCase.c_A11yWeightedPointsInteger,
            Description: `<pre>${JSON.stringify(report.score, null, 2)}</pre>`
          }
    

    The non-collection properties get properly populated, but not the collection property.




  • 6.  RE: How to add an Attachment to a User Story using Rally Rest API

    Broadcom Employee
    Posted Feb 16, 2023 07:43 PM

    Hi Jonathan.

    I have just tested this JSON below and it's working. This created a defect and assigned two values to a multi-valued field.

    I'm guessing in your code example that field that's not working is: c_11yWCAGSuccessCriteriaMultiValue. Assuming I'm correct here a few suggestions to examine:

    • Confirm the value (/allowedattributevalue/675314579201) exists.
    • Confirm this multi-valued field is visible in the project where your object was created.
    • Give it a try directly from Postman. The intent here is to confirm there isn't a specific issue with the language you're using.

    If this isn't helping, then I would recommend either open a support case or provide a bit more info on which field isn't working, what error you're getting if any.

    Below is the screenshot I had mentioned above.

    Thanks,

    Sagi




  • 7.  RE: How to add an Attachment to a User Story using Rally Rest API

    Posted Feb 20, 2023 11:42 AM

    Thank you for your reply, Sagi. The error was entirely mine. I misnamed the property. When I corrected the property name, the property was correctly populated. I apologize.