Jump to content
  • 0

API Question


starlord

Question

Hello, 

I have been searching through the forums and reading this link https://docs.freemmorpgmaker.com/en-US/api/v1/endpoints/authentication.html#get-token for answers, but have not been successful.  Can someone please show me examples of the correct way to use api on http?  here is what I have done so far.

I have already enabled api on the server, and granted my account with api permission, and have my api port open however, when i use the following address on google chrome the following is the error message I am getting with trying to get a token following the above link.  Am I missing something?

http://ipaddress:5000/api/oauth/token/username:passwordinSHA256Hashformat

{"Message":"The requested resource does not support http method 'GET'."}

Thank you in advance Please Provide Examples

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

You don't normally use a browser to interact with an API. That stuff is meant to be used programmatically. (https://www.cleo.com/blog/blog-knowledge-base-what-is-rest-api

 

I believe the documentation also lists what http command to use to interact with said command. In this case you'll want POST. 

 

An example of how to interact with the API can probably be found in the CMS project that's around the board somewhere. But the API is not supposed to be something that humans interact and read directly. 

Link to comment
Share on other sites

  • 0

Hello starlord, here is an example code so you can communicate with the API. I used this calls to create a offline market system. It is very easy to understand, you will not have problems. Happy coding!

 

//GET TOKEN

$url = 'http://localhost:5400/api/oauth/token';

 

$password = '12345';

$password = hash( 'sha256', $password );

 

$data = array(

   'grant_type' => 'password',

   'username' => 'test',

   'password' => $password

);

$data = json_encode($data);

 

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

curl_close($ch);

 

$result = json_decode($result, JSON_OBJECT_AS_ARRAY);

 

//GET INVENTORY

$player = 'dummy';

 

$url = 'http://localhost:5400/api/v1/players/'.$player.'/items/inventory';

 

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('authorization: bearer '.$result['access_token'].''));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$inventory = curl_exec($ch);

curl_close($ch);

 

$inventory = json_decode($inventory, JSON_OBJECT_AS_ARRAY);

Link to comment
Share on other sites

  • 0
2 hours ago, Cheshire said:

You don't normally use a browser to interact with an API. That stuff is meant to be used programmatically. (https://www.cleo.com/blog/blog-knowledge-base-what-is-rest-api

 

I believe the documentation also lists what http command to use to interact with said command. In this case you'll want POST. 

 

An example of how to interact with the API can probably be found in the CMS project that's around the board somewhere. But the API is not supposed to be something that humans interact and read directly. 

Thank you for your reply, I will check this out.

Link to comment
Share on other sites

  • 0
2 hours ago, mrtaco99 said:

Hello starlord, here is an example code so you can communicate with the API. I used this calls to create a offline market system. It is very easy to understand, you will not have problems. Happy coding!

 

//GET TOKEN

$url = 'http://localhost:5400/api/oauth/token';

 

$password = '12345';

$password = hash( 'sha256', $password );

 

$data = array(

   'grant_type' => 'password',

   'username' => 'test',

   'password' => $password

);

$data = json_encode($data);

 

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

curl_close($ch);

 

$result = json_decode($result, JSON_OBJECT_AS_ARRAY);

 

//GET INVENTORY

$player = 'dummy';

 

$url = 'http://localhost:5400/api/v1/players/'.$player.'/items/inventory';

 

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('authorization: bearer '.$result['access_token'].''));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$inventory = curl_exec($ch);

curl_close($ch);

 

$inventory = json_decode($inventory, JSON_OBJECT_AS_ARRAY);

Thank you for your reply, I will check this out.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...