jsonapi icon indicating copy to clipboard operation
jsonapi copied to clipboard

Make calls to jsonapi using Javascript

Open ersgonzalo opened this issue 9 years ago • 3 comments

Hey Mates,

I'm a bit unsure of how to make calls to the JSON Api on my server using Javascript. I want to make more information available on my server's website and take it from the server itself without having to use external services. If this information is documented in the Wiki forgive me for my ignorance but I can't seem to find any at the moment. From what I can gather, process for making a call to a Minecraft server seems to be as so:

  • Install the JSONAPI Plugin to your server (along with the other dependencies as needed)
  • Look into configuration files and save the username and password in the users.yml file for later use
  • If you want to use a salt, include a salt in the config.yml file
  • Look into the Javascript SDK from tools and load it as one of the scripts for the index.html
  • In my own script.js file, insert this:
    var j = new jsonapi({ hostname: "serverIP/domainName", port: 20059, username: "usernameFromUsers.yml", password: "passwordFromUsers.yml", salt: "saltFromConfig.yml" });
  • And then make calls, like so: j.call('getPlayers', console.log);

However, I seem to get errors with my server and nothing is returned from my get requests. Could I get some help with this?

ersgonzalo avatar Nov 27 '15 03:11 ersgonzalo

What are the errors?

krisdb2009 avatar Nov 27 '15 03:11 krisdb2009

I get two errors:

  • If I use port '25565' Uncaught ReferenceError: Invalid left-hand side in assignment
  • If I use port '20059' I get 'Not Found' as a response from the server
    I can see messages on the server if I use port 25565 but not 20059

ersgonzalo avatar Nov 27 '15 05:11 ersgonzalo

Better use Websockets :) but you will have to use CryptoJS / Other SHA256 crypting system

var socket = new WebSocket("ws://****YOURIP****:20061/");

Kworz avatar Nov 28 '15 15:11 Kworz