Examples
Here are some basic code examples on how to make API calls through our API for pack developers.
PHP
<?php /* * This example is written in PHP and provides a base to access our API. This example uses this method * http://wiki.atlauncher.com/api:admin:pack#put_admin_pack_pack_name_settings_allowedplayers - to alter * the allowed players for a private pack. This is a PUT request meaning that all the allowed players will * be replaced with what is provided in the $dataToSend array. */ $apiKey = ""; // Insert API Key Here $packSafeName = ""; // Packs safe name removing all non alphanumeric characters so "My Pack-23" would be "MyPack23" $apiBaseURL = "https://api.atlauncher.com/v1"; // The API request to make, in this instance it's dealing with allowed players of a private pack $apiRequestURL = $apiBaseURL . "/admin/pack/" . $packSafeName . "/settings/allowedplayers/"; // The username to add to the allowed players list $username= "Username"; $response = null; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiRequestURL); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([$username])); curl_setopt($ch, CURLOPT_HTTPHEADER, ["API-KEY: " . $apiKey, "Content-Type: application/json"]); $ret = curl_exec($ch); curl_close($ch); if($ret == null) { exit("Didn't get response from the API!"); } $response = json_decode($ret); if($response == null || json_last_error_msg() != JSON_ERROR_NONE) { exit("Error reading response from the API!"); } if(!$response->error) { exit("API call succeeded with response: " . print_r($response, true)); } else { if($response->code == 429) { // API limit has been reached for this hour, add code to stop future requests otherwise you // will get a 24 hour IP ban! exit("API limit reached with response: " . print_r($response, true)); } else { exit("API call failed with response: " . print_r($response, true)); } } ?>