atlassian_apis 0.8.0 icon indicating copy to clipboard operation
atlassian_apis: ^0.8.0 copied to clipboard

A client to access the Atlassian REST APIs (Jira Cloud platform, Service Desk, Confluence)

A client for the Atlassian REST APIs in Dart #

This is a Dart client for the APIs of:

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();
}

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);
}

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()
  }));
}

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();
}
9
likes
140
pub points
69%
popularity

Publisher

verified publisher iconxaha.dev

A client to access the Atlassian REST APIs (Jira Cloud platform, Service Desk, Confluence)

Homepage

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

http, path

More

Packages that depend on atlassian_apis