Attach file to an issue or issue's comment from workflow

Hello,
In our company we use two YouTrack servers: "internal" and "external" ones. When adding an attachment to an issue in the "external" YouTrack, it is necessary to automatically copy this attachment to the "internal" one to the same issue. Now we are copying the task itself, its description, but not the attached files. How can we copy attachments?

I know, that it's not possible now to attach file to an issue in workflow using base64. But I want to know if these methods can work to attach a file to an issue:

  1. Get binary data from fileUrl and use it in payload of postSync (I tried this method but it works only with text files, but not .exe, .png, etc. Maybe I did some mistakes);
  2. Add a comment to issue in "internal" YouTrack and attach file to this comment.
  3. Use fileUrl. If I'm not mistaken, these links are valid for three days. So this option doesn't seem to work either.

If any of theese method can work, please tell me how to do it right. Or maybe there are other ways to do it.
I'd really appreciate some help as I've been struggling with this for two weeks now.
Thank you.

1
5 comments

Hello!

If I understand you correctly, you need to implement the following work scenario:

  1. An issue receives an attachment in YouTrack A;
  2. A workflow is triggered;
  3. The workflow sends a POST request to YouTrack B;
  4. Through this request, that same attachment is added to the issue in YouTrack B.

The above can be made possible using the postSync method in the workflow. This method is used to send requests outside YouTrack. Attachment.content can serve as the payload in postSync.

You may also check this example of how one can attach files to an issue using REST API.

Let us know if you have more questions here.

0

Yes, the scenario is correct. But there are two difficulties in your proposed solution:

  1. using REST API allows you to send the file only in binary form (not base64);
  2. attachment.content does not provide binary file data. As I understand it, this method returns some wrapper class. I did not find information on how to work with it.

If I misunderstand something, please provide a code snippet to implement this scenario.

 

0
Upon further investigation, we found that currently only multipart content can be sent via postSync, and hence this is not something that can be used for your purpose. Apologies for misleading you in this regard. However, this should become possible in one of the next releases—even though we don’t have a public issue for it, this is something we had to implement for another feature currently in development.
 
For now, a workaround that we can suggest here involves going the other way instead.
 
External YouTrack:
  1. An attachment is added to an issue, triggering an on-change workflow;
  2. Via the workflow, a tag is added to that issue;
  3. This tag is only visible to one user, who holds the permanent token that will be used by your internal YouTrack.
Internal YouTrack:
  1. An on-schedule workflow periodically checks if any issues in your external YouTrack have that tag;
  2. If an issue does have that tag, the base64Content of that issue’s attachment is requested using the getSync function;
  3. An attachment is created in your internal YouTrack, corresponding to the same attachment in your external YouTrack, by using the base64Content requested in p. 2.
I hope this makes some sense despite the complexity of the solution.
0

Thanks for the advice.
But in this task, we need to instantly copy applications.
We came to the following sulution: to allocate a separate server (with python), to which we pass the fileURL. The server gets the binary data from given url and sends it via REST API to the internal YouTrack.

0

Thanks for getting back to us. I am glad you found a solution that suits your case.

Let us know if you have any other questions—we'll be happy to help.

0

Please sign in to leave a comment.