Client library for accessing YouTrack REST API for Google Apps Script
This is the Google Apps Scripts version of youtrack-rest-client
- Open the Script Editor
- Select File -> New -> Script file
- Input the file name as you want, for example: youtrack.gs
- Clear the default code in new gs file
- Copy the raw contents of the dist/youtrack-1.3.2.js file in this repo and paste it in the Script Editor pane on the youtrack.gs file.
With your permanent token (see Manage-Permanent-Token):
const config = {
baseUrl: "http://example.myjetbrains.com/youtrack",
token: "perm:your-token"
};
const client = new ytGAS.Youtrack(config);
// get the current user
client.users.current()
.then((user) => {
Logger.log(user);
}).catch(err => {
Logger.log(err);
});
// get all users
client.users.all()
.then((users) => {
Logger.log(users);
}).catch(err => {
Logger.log(err);
});
}
// get a user by id
client.users.byId('1-1')
.then((user) => {
Logger.log(user);
}).catch(err => {
Logger.log(err);
});
// get all projects
client.projects.all()
.then((projects) => {
Logger.log(projects);
}).catch(err => {
Logger.log(err);
});
// get a project by its id
client.projects.byId('0-0')
.then((project) => {
Logger.log(project);
}).catch(err => {
Logger.log(err);
});
// search/list issues
client.issues.search('project: SYT')
.then((issues) => {
Logger.log(issues);
}).catch(err => {
Logger.log(err);
});
// get issue by id
client.issues.byId('SYT-4')
.then((issue) => {
Logger.log(issue);
}).catch(err => {
Logger.log(err);
});
// delete an issue
client.issues.delete('SYT-4')
.then(() => {
Logger.log('issue deleted');
}).catch(err => {
Logger.log(err);
});
// create a new issue
client.issues.create({
summary: 'lorem ipsum',
description: 'created using rest api',
project: {
id: '0-0'
}
}).then(issue => {
Logger.log(issue);
}).catch(err => {
Logger.log(err);
});
// update an issue
client.issues.update({
id: 'SYT-4',
summary: "updated summary"
}).then(issue => {
Logger.log(issue);
}).catch(err => {
Logger.log(err);
});
// execute command for issue(s) (internal id is used)
client.issues.executeCommand({
query: 'for me',
issues: [
{
id: '2-5'
}
]
}).then(response => {
Logger.log(response);
}).catch(err => {
Logger.log(err);
});
// execute command for issue(s) and add a comment
client.issues.executeCommand({
query: 'for me',
comment: 'gonna solve this real quick',
issues: [
{
id: '2-5'
}
]
}).then(response => {
Logger.log(response);
}).catch(err => {
Logger.log(err);
});
// get the configured workitem types for the project
client.projects.getWorkItemTypes('0-0')
.then((workItemTypes) => {
Logger.log(workItemTypes);
}).catch(err => {
Logger.log(err);
});
// list the workitems of a project
client.workItems.all('SYT-3')
.then((workItems) => {
Logger.log(workItems);
}).catch(err => {
Logger.log(err);
});
// add new workitem to project
client.workItems.create('SYT-3', {
duration: {
presentation: '30m'
},
text: 'fixed bug',
type: {
name: 'Development',
id: '88-0'
}
}).then(workItem => {
Logger.log(workItem);
}).catch(err => {
Logger.log(err);
});
// update workitem
client.workItems.update('SYT-3', {
id: '136-0',
duration: {
presentation: '45m'
}
}).then(workItem => {
Logger.log(workItem);
}).catch(err => {
Logger.log(err);
});
// delete work item
client.workItems.delete('SYT-3', '136-0')
.then(() => {
Logger.log('workitem deleted.');
}).catch(err => {
Logger.log(err);
});
// list comments of an issue
client.comments.all('SYT-3').then((comments) => {
Logger.log(comments);
}).catch(err => {
Logger.log(err);
});
// add comment to issue
client.comments.create('SYT-3', {
text: 'issue comment'
}).then(comment => {
Logger.log(comment);
}).catch(err => {
Logger.log(err);
});
// update comment
client.comments.update('SYT-3', {
id: '4-3',
text: 'updated issue comment'
}).then(comment => {
Logger.log(comment);
}).catch(err => {
Logger.log(err);
});
// delete a comment
client.comments.delete('SYT-3', '4-1')
.then(() => {
Logger.log('comment deleted.');
}).catch(err => {
Logger.log(err);
});
// get all tags
client.tags.all()
.then((tags) => {
Logger.log({ tags });
}).catch(err => {
Logger.log(err);
});
// get tag by id
client.tags.byId('6-0')
.then((tag) => {
Logger.log(tag);
}).catch(err => {
Logger.log(err);
});
// get issue links of issue
client.issues.byId('SYT-3')
.then((issue) => {
Logger.log({ links: issue.links });
}).catch(err => {
Logger.log(err);
});
// update issue link(s)
client.issues.update({
id: 'SYT-3',
links: [
{
issues: [
{
id: '2-7'
}
],
id: '104-3s',
}
]
}).then((issue) => {
Logger.log({ links: issue.links });
}).catch(err => {
Logger.log(err);
});
// get all agile boards
client.agiles.all()
.then((agiles) => {
Logger.log(agiles);
}).catch(err => {
Logger.log(err);
});
// get specific agile board by id
client.agiles.byId('115-0')
.then((agile) => {
Logger.log(agile);
}).catch(err => {
Logger.log(err);
});
// create new agile board
client.agiles.create({
name: '19-15',
projects: [{ id: '0-0' }]
}).then((agile) => {
Logger.log(agile);
}).catch(err => {
Logger.log(err);
});
// delete an agile board
client.agiles.delete('115-2')
.then(() => {
Logger.log('agile deleted.');
}).catch(err => {
Logger.log(err);
});
// update an agile board
client.agiles.update({
id: '115-2', projects: [{ id: '0-0' }]
}).then((agile) => {
Logger.log(agile);
}).catch(err => {
Logger.log(err);
});
const agileId = '104-0';
// get all sprints of an agile board
client.sprints.all(agileId)
.then(sprints => {
Logger.log(sprints);
}).catch(err => {
Logger.log(err);
});
// get agile sprint by id
client.sprints.byId(agileId, '116-1')
.then(sprint => {
Logger.log(sprint);
}).catch(err => {
Logger.log(err);
});
// create new sprint
client.sprints.create(agileId, { name: 'my sprint' })
.then(sprint => {
Logger.log(sprint);
}).catch(err => {
Logger.log(err);
});
// update a sprint
client.sprints.update(agileId, { id: '116-1', name: 'my sprint 3' })
.then(sprint => {
Logger.log(sprint);
}).catch(err => {
Logger.log(err);
});
// delete a sprint
client.sprints.delete(agileId, '116-1')
.then(() => {
Logger.log('sprint deleted.');
}).catch(err => {
Logger.log(err);
});
If you encounter any missing features or bugs, you're welcome to open an Issue! PRs are welcome too ;-)
- Fork it (https://github.com/siquylee/youtrack-gs/fork)
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request