Skip to content
Kim Kar edited this page Jan 27, 2021 · 13 revisions

Initialization

const XIVAPI = require('@xivapi/js')

const xiv = new XIVAPI()

It's just that easy!

Global Parameters

An optional object that can be provided during initialization. These parameters are passed on pretty much all requests if set, but you can override them (except for staging) on requests that take a param object.

For example, if you define language: 'ja' in the global parameters, using xiv.search("Ifrit") will return results in Japanese but doing xiv.search("Ifrit", {language: 'fr'}) will give results in French, ignoring the global setting.

Name Type Default Description
private_key string undefined The API key for your account. You can get this from your XIVAPI account page.
staging bool false Use the XIVAPI staging server (https://staging.xivapi.com), like the rebel you are.
language string 'en' Language to fetch results in, out of these.
snake_case bool false Returns all result fields in lower_snake_case rather than UpperCase.
verbose boolean false Logs information on all requests made to the console.
const xiv = new XIVAPI({
  private_key: 'someKey',
  language: 'ja',
  snake_case: true
})

General Structures

Pagination

For calls that support pages (like search, etc) the returned object contains a Pagination element that looks like this:

{
  ...
  Pagination: {
    Page: 1,             //current page
    PageNext: 2,         //next page, if applicable
    PagePrevious: null,  //previous page, if applicable
    PageTotal: 12,       //total number of pages
    Results: 100,        //number of results in this page
    ResultsPerPage: 100, //number of results per page
    ResultsTotal: 1168   //total number of results
  }
}

You can use this and the page request parameter to effectively navigate through content.

Usage

All API methods return Promises, so you can handle their output in one of two ways:

then/catch methods:

xiv.search("Shroud Cherry Sapling").then((response) => {
  // do something with the response
}).catch((error) => {
  // do something with the error
})

using await with try/catch blocks in an async function:

try {
  let response = await xiv.search("Shroud Cherry Sapling")
  // do something with the response
} catch(error) {
  // do something with the error
}
Clone this wiki locally