Developer Portal for YouTrack and Hub Help

Post Binary Content from YouTrack

When you need to post files from YouTrack to a third-party application, the target application might require you to make POST requests with the Content-Type header value set to multipart/form-data.

To make such a request from a YouTrack workflow rule, pass an object for the payload parameter of the Connection.postSync method and set its type value to 'multipart/form-data'.

In the parts parameter of the payload, YouTrack expects to find an array consisting of the attachment parts. You can send as many parts as necessary.

For each element of the parts array, there are the following fields available:







The name of the part.



The size of the attached file in bytes.



The name of the attachment file.


InputStream | String

The content of the file.

When the contentType is not set explicitly, YouTrack expects the content as an InputStream in binary form.



The content type of the file.

For each individual part, you can set the contentType value separately. Depending on the contentType value, YouTrack expects different types of the content. For example, if you set contentType: 'application/json', the content value must be in JSON format.

Here is an example of a workflow rule that makes a POST request and passes an attachment with the multipart/form-data type.

const entities = require('@jetbrains/youtrack-scripting-api/entities'); const http = require('@jetbrains/youtrack-scripting-api/http'); exports.rule = entities.Issue.action({ title: 'Reattach the first attachment', // The base URL is taken from the first line of the issue description. // Auth details are taken from the second of the issue description, the user ID - from the third line. command: 'reattach', guard: (ctx) => { return true; }, action: (ctx) => { const issue = ctx.issue; const baseURL = issue.description.split('\n')[0].trim() const auth = issue.description.split('\n')[1].trim() const rootUserId = issue.description.split('\n')[2].trim() const connection = new http.Connection(baseURL); const attachment = issue.attachments.first(); connection.addHeader('authorization', auth); connection.postSync('issues/' + + '/attachments', [], { type: 'multipart/form-data', parts: [ { name: 'my-part-name', size: attachment.size, fileName: 'filename', content: attachment.content } ] }); }, requirements: {} });
Last modified: 11 June 2024