Skip to content

wikitree/wikitree-js

Repository files navigation

npm Node.js CI

wikitree-js

JavaScript library to access the WikiTree API for Node.js and Web environments.

Setup

Add wikitree-js package to your project:

npm install wikitree-js

Import package:

import {getAncestors} from 'wikitree-js';

Usage

getPerson

API documentation

Example 1

Async/await:

const response = await getPerson('Skłodowska-2');

Promise:

const responsePromise = getPerson('Skłodowska-2')

responsePromise.then(response => {
  // ...
});

Live demo:

Example 2

Async/await:

const response = await getPerson(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
  }
);

Promise:

const responsePromise = getPerson(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
  }
);

responsePromise.then(response => {
  // ...
});

Live demo:

getAncestors

API documentation

Example 1

Async/await:

const response = await getAncestors('Skłodowska-2');

Promise:

const responsePromise = getAncestors('Skłodowska-2')

responsePromise.then(response => {
  // ...
});

Live demo:

Example 2

Async/await:

const response = await getAncestors(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
    depth: 2,
  }
);

Promise:

const responsePromise = getAncestors(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
    depth: 2,
  }
);

responsePromise.then(response => {
  // ...
});

Live demo:

getDescendants

API documentation

Example 1

Async/await:

const response = await getDescendants('Skłodowska-2');

Promise:

const responsePromise = getDescendants('Skłodowska-2')

responsePromise.then(response => {
  // ...
});

Live demo:

Example 2

Async/await:

const response = await getDescendants(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
    depth: 2,
  }
);

Promise:

const responsePromise = getDescendants(
  'Skłodowska-2',
  {
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
    depth: 1,
  }
);

responsePromise.then(response => {
  // ...
});

Live demo:

getRelatives

API documentation

Example

Async/await:

const response = await getRelatives(
  ['Skłodowska-2'],
  {
    getChildren: true,
    getParents: true,
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth'],
  }
);

Promise:

const responsePromise = getRelatives(
  ['Skłodowska-2'],
  {
    getChildren: true,
    getParents: true,
    fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth'],
  })

responsePromise.then(response => {
  // ...
});

Live demo:

login (Node.Js)

This login method works only in Node.Js. To log in in a Web application use

Example

const auth = await login('user@example.com', 'P@s$w0Rd');
const response = await getRelatives(['Private-123'], {}, { auth });

Live demo: Replit

login (Web)

API documentation

The Web login only works for apps hosted on https://apps.wikitree.com/. See WikiTree Apps page for details on how to host your app there.

The login flow works as follows:

  1. Redirect the user to the WikiTree login page giving it a URL to redirect back:
navigateToLoginPage('https://apps.wikitree.com/my-app');
  1. Once the user logs in, they will be redirected back to your app with an authcode URL parameter, e.g.
https://apps.wikitree.com/my-app?authcode=abc123abc
  1. The app needs to take this authcode and call clientLogin with it.
clientLogin(authcode);
  1. All subsequent requests to WikiTree will be authenticated.

Use getLoggedInUserName() to get the currently logged in user's profile name.

About

WikiTree JavaScript library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published