Summary Creation of attachment via WS API from scratch consists of two steps: creation of the attachmentcontent object and creation of the actual attachment on a CA Agile Central artifact.
Issue How to upload attachments using Web Services API?
Resolution Creation of attachment via WS API from scratch consists of two steps: creation of the attachmentcontent object and creation of the actual attachment on a CA Agile Central artifact.
Later in the article see links to java code samples that attach existing zip and image files to CA Agile Central artifacts.
The example below applies to objects in WS API that inherit from Artifact object, e.g. user story(HierarchicalReqirement in WS API), defect, test case, as well as to TestCaseResult object , which is outside of Artiact object's hierarchy in WS API. (TestCaseResult directly inherits from WorkspaceDomainObject. See Object Model for more details.)
The only difference is that attachment payload for a test case result has to use TestCaseResult, and not Artifact object.
A browser REST client is used to post both objects, and a valid API Key is used for authentication, set in zsessionid header.
Before we proceed with the examples we need to encode? attachment content. Using this encoder/decoder,? we encoded "hello world" to UTF-8
This code will be used in a payload when creating attachmentcontent object.
1. Create attachmentconent:
Here is the result's JSON:
Here is the ref of the newly created attachmentcontent object:
NOTE: As with any WS API request, a request to create attachmentcontent may be implicitly scoped to a workspace different from the one for which it is intended. In case the creation of the attachmentconent fails with "Not authorized to create Attachmentcontent" error try setting workspace on the request explicitly as shown in this example:
where workspace ObjectID is 12345. There are different ways ot find out ObjectID of a workspace. One of them is to switch to that workspace in the UI and follow suggestions from this article: How to find ObjectIDs of current workspace and project without admin rights
If the attachmentconent has been successfully created will use it in the payload of the attachment object created in the next step.
2. Create attachment:
Identify an artifact on which you want to create an attachment.
In this example it is a user story with ObjectID of 29750715443.
ObjectID of a CA Agile Central artifact can be accessed from the last part of the URL of its details page.
NOTE: when creating an attachment on a test case result modify payload syntax to use TestCaseResult object instead of Artifact e.g.:
Here is the result's JSON:
Verify that the attachment was uploaded. For further verification, download the attachment and check its content:
For real-life examples see java code samples here and here.