Issue Attachments - Update Visibility via the REST API
Hi,
Is there a way to update the visibility of an attachment via the REST API?
Reading through this: https://www.jetbrains.com/help/youtrack/devportal/resource-api-issues-issueID-attachments.html we can only add new attachments, but, maybe I'm missing something.
Thanks!
Please sign in to leave a comment.
Nevermind.
I've found this https://www.jetbrains.com/help/youtrack/devportal/operations-api-issues-issueID-attachments.html...
I'll read some more.
Thanks!
We are happy to hear that our documentation helped you to find a solution. Have a nice day!
One question though: if I only want to update the visibility of an attachment, how would I go about it?
The way I'm doing it now is this:
1) fetch the IssueAttachment object with these fields: $type,id,name,url,visibility(id,permittedUsers(id),permittedGroups(id))
2) change the visibility to be what I need (a LimitedVisibility instance)
3) POST the new IssueAttachment object to /api/issues/{issueID}/attachments/{attachmentID}
The end result of those operations is that the visibility indeed changes to what I need it to be, but the attachment content is gone. It cannot be accessed in any way.
The question is: what am I doing wrong? Should I be getting the full IssueAttachment object (including the base64 content and everything else), change it and then post the updated object?
Thanks!
I'm Lena from the YouTrack Team.
Could you please specify the full POST request with a body?
Hi Lena Vostrikova,
I am using the code generated by OpenAPI for Java, which hides the post from me.
But, I think I've figured it out.
The serialized object that OpenAPI was sending was including all fields, even though most of them were null. And the YouTrack processor was just overwriting the existing values with null.
I made sure null valued fields were not present in the serialized object, only the ones I actually assigned values to (visibility in my case).
I think that fixed it.
As a suggestion: aside from the OpenAPI specs that your team provides, can you provide sample libraries that conform to those specs for the major languages? :)
Thanks!
I'm happy to hear that you found a source of the issue. As for the libraries, I recommend you take a look at the [Open API Generator](https://openapi-generator.tech/) - it helps you generate code to interact with any server which exposes an OpenAPI document.
Please let me know if you have additional questions.