#I try to get the api working in javascript but i keep getting ecconrefused errors

12 messages · Page 1 of 1 (latest)

charred gull
#

This is how my code looks like:

const axios = require('axios');
require('dotenv').config();

const api_key = process.env.PTERO_API_KEY;
const base_url = process.env.PTERO_BASE_URL;

module.exports = function requestPterodactylAPI(endpoint, method, headers = {}, params = {}, data = {}) {
  return axios({
    method: method,
    url: `${base_url}/api/${endpoint}`,
    headers: {
      ...headers,
      'Accept': 'application/json',
      'Authorization': `Bearer ${api_key}`
    },
    withCredentials: true,
    params: params,
    data: data,
    validateStatus: function (status) {
      return status >= 200 && status < 300; // default
    },
    jar: true,
    withCredentials: true
  })
    .then(response => {
      return response.data;
    })
    .catch(error => {
      console.log(error);
      throw error;
    });
};

``` it might be that i use the wrong api URL but i have no idea what URL that has to be.
queen cedar
#

What do you have in Base URL?

charred gull
#

O i made a typo in my .env file. I now get a bad request error but not a econnrefused error so its improvement

floral hawkBOT
#

The env file can be found at /var/www/pterodactyl/.env. Files starting with a . in Linux are hidden so it may not show up in file browsers by default. You can open it directly with nano /var/www/pterodactyl/.env

charred gull
#

Thats something else bot :D

#

I am not sure exactly what i request wrong

#

Now forbidden thonk

#
const requestPterodactylAPI = require("./ptero.js");

requestPterodactylAPI("client", "get", {}, {}, {})
  .then((data) => {
    console.log(data);
  })
  .catch((error) => {
    console.log(error);
  });
``` this is what i use to actually make the request to the other file
charred gull
#

Does using cloudflare for my panel proxy mode cause issues?

queen cedar
#

can you access the API endpoint when logged in with their account?

charred gull
#

what you mean?

atomic fable
#

Hi