Last updated:
0 purchases
atlassian apis
A client for the Atlassian REST APIs in Dart #
This is a Dart client for the APIs of:
Jira Cloud
Jira Software
Jira Service management
Confluence
Cloud Admin
All the client are generated from the OpenAPI definition files provided by Atlassian
See Atlassian documentation of the APIs
Usage #
Authentication #
import 'dart:io';
import 'package:atlassian_apis/jira_platform.dart';
void main() async {
// This example uses API Token authentication.
// Alternatively, you can use OAuth.
var user = Platform.environment['ATLASSIAN_USER']!;
var apiToken = Platform.environment['ATLASSIAN_API_TOKEN']!;
// Create an authenticated http client.
var client = ApiClient.basicAuthentication(
Uri.https('<your-account>.atlassian.net', ''),
user: user,
apiToken: apiToken);
// Create the API wrapper from the http client
var jira = JiraPlatformApi(client);
// Communicate with the APIs..
await jira.projects.searchProjects();
// Close the client to quickly terminate the process
client.close();
}
copied to clipboard
Jira #
import 'dart:convert';
import 'package:atlassian_apis/jira_platform.dart';
void main() async {
// Create Jira API from an authenticated client
var jira = JiraPlatformApi(apiClient);
// Create a comment
var info = await jira.issueComments
.addComment(issueIdOrKey: 'BR-123', body: Comment(body: 'A comment'));
printJson(info);
}
copied to clipboard
Service desk #
import 'dart:convert';
import 'dart:io';
import 'package:atlassian_apis/service_management.dart';
import 'package:path/path.dart' as path;
void main() async {
// Create the API for Service Desk
var serviceManagement = ServiceManagementApi(apiClient);
// Fetch some data
var desks = await serviceManagement.servicedesk.getServiceDesks();
printJson(desks);
// Create a new customer
var newCustomer = await serviceManagement.customer
.createCustomer(body: CustomerCreateDTO(email: '..', displayName: '...'));
printJson(newCustomer);
// Upload a file
var file = File('some_file.png');
var attachment = await serviceManagement.servicedesk.attachTemporaryFile(
serviceDeskId: '1',
file: MultipartFile('file', file.openRead(), file.lengthSync(),
filename: path.basename(file.path)));
// Create a new customer request with attachment
await serviceManagement.request.createCustomerRequest(
body: RequestCreateDTO(requestFieldValues: {
'summary': 'The issue summary',
'attachment': attachment.temporaryAttachments
.map((e) => e.temporaryAttachmentId)
.toList()
}));
}
copied to clipboard
Confluence #
import 'dart:convert';
import 'dart:io';
import 'package:atlassian_apis/confluence.dart';
import 'package:http/http.dart';
void main() async {
// Create Confluence API from an authenticated client
var confluence = ConfluenceApi(apiClient);
// Get a page
var page =
await confluence.content.getContentById(id: '1234', expand: ['version']);
// Update a page
await confluence.content.updateContent(
id: page.id!,
body: ContentUpdate(
version: ContentUpdateVersion(number: page.version!.number + 1),
title: page.title!,
type: 'page',
body: ContentUpdateBody(
storage: ContentBodyCreateStorage(
value: 'new content',
representation: ContentBodyCreateStorageRepresentation.storage,
),
),
),
);
// Get page attachments
var attachments = await confluence.contentChildrenAndDescendants
.getContentChildrenByType(id: '1234', type: 'attachment');
var existingAttachments = attachments.results.toList();
// Delete attachments
await confluence.content.deleteContent(id: existingAttachments.first.id!);
// Create new attachments
var file = File('my_file.pdf');
await confluence.contentAttachments.createOrUpdateAttachments(
id: '1234',
body: MultipartFile('file', file.openRead(), file.lengthSync(),
filename: 'file.pdf'));
// Close the http client
confluence.close();
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.