# d2

> Javascript library for DHIS2

Latest version **31.10.2** (published 2021-11-18) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install d2
pnpm add d2
yarn add d2
bun add d2
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 31.10.2 |
| Published | 2021-11-18 |
| First published | 2015-05-09 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=5.1.1 |
| Dependencies | 1 |
| Unpacked size | 6.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Mark Polak |
| Maintainers | varl, amcgee, ismay, dhis2-bot, martinkrulltott, birk, mpolak, nicolayr, travis4dhis2 |
| Keywords | dhis2, api, library |

## Links

- npm: https://www.npmjs.com/package/d2
- Repository: https://github.com/dhis2/d2
- Issues: https://github.com/dhis2/d2/issues
- npm.io page: https://npm.io/package/d2

## Dependencies (1)

- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) ^2.2.1

## Recent versions

- 31.10.2 (latest) — 2021-11-18
- 30.2.3 (legacy) — 2023-12-11
- 30.2.2 (dhis2-2.30) — 2021-04-08
- 24.1.11 (dhis-2.24) — 2016-07-26
- 24.0.13 (dhis-2.23) — 2016-07-25
- 30.2.1 — 2021-04-07
- 30.2.0 — 2021-04-07
- 31.10.0 — 2021-04-07
- 31.9.3 — 2021-03-24
- 31.9.2 — 2021-03-22
- 31.9.1 — 2021-03-09
- 31.9.0 — 2020-12-11
- 31.8.2 — 2020-08-21
- 31.8.1 — 2019-05-13
- 31.8.0 — 2019-04-30
- … 167 more at https://npm.io/package/d2/versions

## README

# d2

[![build status](https://travis-ci.com/dhis2/d2.svg?branch=master)](https://travis-ci.com/dhis2/d2)
[![greenkeeper badge](https://badges.greenkeeper.io/dhis2/d2.svg)](https://greenkeeper.io/)
[![npm version](https://badge.fury.io/js/d2.svg)](https://badge.fury.io/js/d2)

The full api documentation is available [here](https://d2-ci.github.io/d2/). To get started we suggest you read the [overview](https://d2-ci.github.io/d2/tutorial-overview.html). If you already know what you're looking for we suggest the reference material on what is available on the instance of [d2](https://d2-ci.github.io/d2/module-d2.init-d2.html).

For more information on how the models work the [model module documentation](https://d2-ci.github.io/d2/module-model.html) is helpful reference material. For other questions see the [FAQ](https://d2-ci.github.io/d2/tutorial-FAQ.html).


## Quickstart guide

### Install

Start with adding d2 to your project:

`yarn add d2` or `npm install d2`

After installing you will be able to import the library into your project by using the files in the `lib` folder:

```js
// Using ES2015 imports
import d2 from 'd2';

// Using CommonJS imports
var d2 = require('d2');
```

### Initialise the library
To be able to use d2 you will first need to initialise the library. This is required to let the library know where it should load its data from (e.g. the schemas, currentUser, authorities). The schemas are the definitions of the data model as used in DHIS2.

To do this you can provide d2 with a `baseUrl` (if you don't provide any the default of `../api` will be used):

```js
import { init } from 'd2';

init({ baseUrl: 'http://apps.dhis2.org/dev/api' })
  .then(d2 => {
    //Your d2 is initialised and ready to use.
  });
```

### Get first page of users and print their names

```js
d2.models.user.list()
  .then(userCollection => {
    userCollection.forEach(user => console.log(user.name)));
  });
```

That's it! See the documentation referenced above for further information.


## Report an issue

The issue tracker can be found in [DHIS2 JIRA](https://jira.dhis2.org)
under the [LIBS](https://jira.dhis2.org/projects/LIBS) project.

Deep links:

-   [Bug](https://jira.dhis2.org/secure/CreateIssueDetails!init.jspa?pid=10700&issuetype=10006&components=11011)
-   [Feature](https://jira.dhis2.org/secure/CreateIssueDetails!init.jspa?pid=10700&issuetype=10300&components=11011)
-   [Task](https://jira.dhis2.org/secure/CreateIssueDetails!init.jspa?pid=10700&issuetype=10003&components=11011)

---
_Source: https://npm.io/package/d2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
