Abstract SDK

Abstract SDK

  • Getting Started
  • API
  • Community

›Introduction

Introduction

  • Getting Started

API

  • Authentication
  • Reference

Utilities

  • Sketch
Edit

Getting Started

Important Note: This SDK is a beta – we are expecting to make major revisions to the methods and responses that are available before a wider public launch.

The SDK was designed to allow interacting with both the Abstract API and the desktop CLI from a unified interface in any environment that supports JavaScript. The SDK should work well inside desktop design tools such as Sketch, on servers, or CI environments.

Installation

yarn add abstract-sdk

or

npm install abstract-sdk

Configuring

In order to use the SDK you'll need to instantiate an instance and give it an authentication token, we recommend storing the token in your environment as ABSTRACT_TOKEN and it will be automatically loaded – don't commit it with your code!

import * as Abstract from "abstract-sdk";

const abstract = Abstract.Client();

You can also specify a token to use, for example:

import * as Abstract from "abstract-sdk";

const abstract = Abstract.Client({
  accessToken: process.env.ABSTRACT_API_TOKEN
});

Transports

If you want to ensure that the SDK only ever loads data from the API or the CLI then you can achieve this by specifying a transport. This is useful when running in an environment without the Mac application installed or alternatively when you want to ensure you're only dealing with local data:

import * as Abstract from "abstract-sdk";

const abstract = Abstract.Client({
  transport: Abstract.TRANSPORTS.CLI
});

Making a Request

Lets get started by loading a list of accessible projects from the API. All of the methods in the SDK return a promise – you may use traditional promise syntax or async / await if your JS runtime supports ES6.

const projects = await abstract.projects.list();
projects.map(project => {
  console.log(`${project.name}: ${project.id}`);
});

Hopefully you just got a list of projects that are accessible to your token, nice! From here you can use the API reference to dig deeper – try loading branches, commits, comments, artboard data, and more.

Authentication →
  • Installation
  • Configuring
    • Transports
  • Making a Request
Copyright © 2018 Elastic Projects