Created
July 11, 2024 08:15
-
-
Save presswizards/92f280d4c42a0cf07c59383dc315b11c to your computer and use it in GitHub Desktop.
ServerAvatar API Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Set the API endpoint | |
$api_endpoint = 'https://api.serveravatar.com/v1/'; | |
// Set the API key | |
$api_key = 'YOUR_API_KEY_HERE'; | |
// Set the server ID | |
$server_id = 'YOUR_SERVER_ID_HERE'; | |
// Set the application name | |
$app_name = 'wordpress'; | |
// Set the domain name | |
$domain_name = 'example.com'; | |
// Set the username and password for the WordPress admin user | |
$username = 'admin'; | |
$password = 'password'; | |
// Set the email address for the WordPress admin user | |
$email = '[email protected]'; | |
// Set the API request parameters | |
$params = array( | |
'api_key' => $api_key, | |
'server_id' => $server_id, | |
'app_name' => $app_name, | |
'domain_name' => $domain_name, | |
'username' => $username, | |
'password' => $password, | |
'email' => $email, | |
); | |
// Send the API request | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $api_endpoint . 'create/app/'); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
// Check the API response | |
if ($response === false) { | |
echo 'Error: ' . curl_error($ch); | |
} else { | |
$response = json_decode($response, true); | |
if ($response['success'] === false) { | |
echo 'Error: ' . $response['message']; | |
} else { | |
echo 'WordPress application created successfully'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment