PHP | How to update backoffice colors & logo for all active clients in your reseller console

Posted about 1 year ago by Julien Pauthier

Post a topic
Julien Pauthier
Julien Pauthier Admin

This scripts can be useful to re-apply default colors, your brand logo as well as profile's features & limitations:


<?php 
$apiKey = "";
$ssoToken = "";
$logoUrl = "https://yourdomainname/yourlogourl.png";

$dataColor = file_get_contents("https://api.agendize.com/api/2.0/resellers/settings/whiteLabel?apiKey=$apiKey&token=$ssoToken");

//fetch colors from the reseller settings
$reselleColor = json_decode($dataColor);
$colorHeader = "";
$colorMenu = "";
if ($reselleColor != null) {
    $colorHeader = $reselleColor->headerBackgroundColor;
    $colorMenu = $reselleColor->menuBackgroundColor;
    echo "Menu: " . $colorMenu . "\tHeader: " . $colorHeader . "\n";
} else {
    die();
}

//fetch list of all clients from the reseller console
$data = file_get_contents("https://api.agendize.com/api/2.0/resellers/accounts?apiKey=$apiKey&token=$ssoToken");
$clients = json_decode($data);

foreach ($clients->items as $client) {
    if ($client->status == "enabled") {
        echo $client->id. "\t" . $client->email . "\t";
        if (isset($client->profile)) {
            echo $client->profile->id . "\n";

            //create a new cURL resource
            $ch = curl_init("https://api.agendize.com/api/2.0/resellers/accounts/$client->id?apiKey=$apiKey&token=$ssoToken");

            //setup request to send json via POST
            $data = array(
                'whiteLabel' => array(
                    "headerBackgroundColor" => $colorHeader,
                    "menuBackgroundColor" => $colorMenu,
                    "logoURL" => $logoUrl
                ),
                'profile' => array(
                    "id" => $client->profile->id
                )
            );
            $payload = json_encode($data);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            //set the content type to application/json
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

            //execute the POST request
            $result = curl_exec($ch);

            //close cURL resource
            curl_close($ch);
            //create a new cURL resource
            $ch = curl_init("https://api.agendize.com/api/2.0/resellers/accounts/$client->id?apiKey=$apiKey&token=$ssoToken");

            //setup request to send json via POST
            $data = array(
                'whiteLabel' => array(
                    "headerBackgroundColor" => $colorHeader,
                    "menuBackgroundColor" => $colorMenu,
                    "logoURL" => $logoUrl
                ),
                'profile' => array(
                    "id" => $client->profile->id
                )
            );
            $payload = json_encode($data);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            //set the content type to application/json
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

            //execute the POST request
            $result = curl_exec($ch);

            //close cURL resource
            curl_close($ch);
        } else {
            echo "No profile ID\n";
        }
    }
}
?>


0 Votes


0 Comments

Login or Sign up to post a comment