EcoNuker API
  • Welcome
  • Ratelimits
  • Auth Tokens
  • Items
  • Servers
  • Bot Information
  • Testing
  • Quickstart
    • Examples - Python
    • Examples - JS
Powered by GitBook
On this page
  • JavaScript Example
  • JavaScript Async Example
  1. Quickstart

Examples - JS

Examples of using the EcoNuker API.

PreviousExamples - Python

Last updated 2 years ago

Notice: is unavailable until June 1, 2023. For now, use

JavaScript Example

const baseurl = "https://beta.econuker.xyz/api"; // "https://api.econuker.xyz"
const authtoken = null; // "your auth token here"

const headers = authtoken ? {
  "authorization": authtoken
} : {};

fetch(baseurl + "/servers", { headers })
  .then(response => {
    if (response.ok) {
      return response.json();
    } else {
      throw new Error("Request failed with status: " + response.status);
    }
  })
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error(error);
  });

JavaScript Async Example

Installation

npm install node-fetch

Code

const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));

const baseurl = "https://beta.econuker.xyz/api"; // "https://api.econuker.xyz"
const authtoken = null; // "your auth token here"

const headers = authtoken ? {
  "authorization": authtoken
} : {};

async function asyncFunction() {
  const response = await fetch(baseurl + "/servers", { headers });
  if (response.ok) {
    const data = await response.json();
    return data;
  } else {
    throw new Error("Request failed with status: " + response.status);
  }
}

asyncFunction()
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error(error);
  });
econuker.xyz/api
beta.econuker.xyz/api