Skip to content

bribes/Unofficial-NameMC-API-Docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

THIS AND THE API IS DICONTINUED

if you want an alternative try using https://faav.gapple.pw/ or https://api.snaz.in/docs#namemc (SNAZ IS CURRENTLY NOT WORKING)



Contents

About

I created this API for people who need to use NameMC's database in a automated way.


Limitations

This API scrapes the NameMC website in order to provide accurate responses. If the NameMC layout changes or goes offline, this API will provide inaccurate information or will not function at all. Please keep this in mind while using this API.


Routes


Official NameMC API


Usage Examples

JavaScript:

XHR:

See it in action

<html>
<head>
	<script>
	var getJSON = function(url, callback) {
	   var xhr = new XMLHttpRequest();
	   xhr.open('GET', url, true);
	   xhr.responseType = 'json';
	   xhr.onload = function() {
	     var status = xhr.status;
	     if (status === 200) {
	       callback(null, xhr.response);
	     } else {
	       callback(status, xhr.response);
	     }
	   };
	   xhr.send();
	};

	getJSON('https://www.faav.tk/v1/namemc/capecount?username=Marc',
	function(err, data) {
	 if (err !== null) {
	   document.getElementById('marc').innerHTML = err;
	 } else {
	   document.getElementById('marc').innerHTML = 'Marc has '+data.formatted+' capes.';
	 }
	});
	</script>
</head>
	<body>
	<p id="marc">Marc has 0 capes.</p>
	</body>
</html>

Fetch (My Favorite):

See it in action

<html>
<head>

	<script>
	   fetch('https://www.faav.tk/v1/namemc/capecount?username=Marc').then(res => res.json()).then((data) => {
	       document.getElementById('marc').innerHTML = 'Marc has '+data.formatted+' capes.';
	   })
	</script>
	<title></title>
</head>
<body>
	<p id="marc">Marc has 0 capes.</p>
</body>
</html>

jQuery:

See it in action

<html>
<head>

	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
	</script>
	<script>
	    $.getJSON('https://www.faav.tk/v1/namemc/capecount?username=Marc', function(data) {
	           document.getElementById('marc').innerHTML = 'Marc has '+data.formatted+' capes.';
	       });
	</script>
	<title></title>
</head>
<body>
	<p id="marc">Marc has 0 capes.</p>
</body>
</html>

PHP:

See it in action

<?php
$namemc_api = json_decode(file_get_contents("https://www.faav.tk/v1/namemc/capecount?username=Marc"), false);
$marcs_capes = $namemc_api -> formatted;
 echo '<p>Marc has '.$marcs_capes." capes.</p>";
?>

Java:

OkHttp & Gson:

public static void main(String[] args) {
	final OkHttpClient okHttpClient = new OkHttpClient();
	final Gson gson = new Gson();

	final Request request = new Request.Builder()
		.url("https://www.faav.tk/v1/namemc/capecount?username=Marc")
		.get()
		.build();

	try (final Response response = okHttpClient.newCall(request).execute()) {
		if (response.isSuccessful()) {
			final JsonObject jsonObject = gson.fromJson(response.body().charStream(), JsonObject.class);
			System.out.printf("Marc has %s capes", jsonObject.get("formatted").getAsString());
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
}

Contributions

Thank you JerreBor (Jero) for the Java usage example and the better Read Me file, and thank you lucky swede for the documentation template.


Disclaimer

This API is not affiliated nor indorsed by NameMC, Minecraft, Mojang, and/or Microsoft.