Sending attachment file via http post request

Viewed 420

I'm trying to send attachment file from youtrack to another system (in this example to trello) without the use of image url but its content

I cannot send it as image url in youtrack because my system is closed and accessible to only those that have vpn.

Problem is with reading inputStream from content of attachement in workflow. I symply have no idea how to do it and youtrack documentation havent touched it (as far as my research goes)

Code: (with truncated not important parts)

//...

exports.rule = entities.Issue.onChange({
  //...
  action: function(ctx) {
    //...
    var link = '/1/cards/' + issue['trelloIssueId'] + '/attachments';

    issue.comments.added.forEach(function(comment) {
      comment.attachments.forEach(function(attachment) {        
        var response = connection.postSync(link, {
          name: attachment.name,
          file: attachment.content,
          mimeType: attachment.mimeType
        });

        //...
      });
    });
  },
  requirements: {}
});

from this I got error:

TypeError: invokeMember (forEach) on jetbrains.youtrack.workflow.sandbox.InputStreamWrapper@677a561f failed due to: Unknown identifier: forEach

How do I have to prepare content to ba abble to send it with postSync method?

1 Answers

It looks like you tried to iterate over issue.comments.added while the loop should be executed over issue.comments as there is no added key for an issue's comments Set as per the following documentation page suggest: https://www.jetbrains.com/help/youtrack/devportal/v1-Issue.html

Please let me know if that works.

Related