Commencer un nouveau sujet

PHP | How to update all email templates for the companies of an account

You can extract all templates from a list of locations, and do a search&replace for each email template:


<?php 
$token = "";
$apikey = "";

// Fetching list of companies/locations for the account
$data = file_get_contents("https://app.agendize.com/api/2.1/scheduling/companies?apiKey=$apikey&token=$token");
$results = json_decode($data);

// Table header for output
echo "Company name\tCompany ID\tEmail template name\tEmail template ID\n";

foreach ($results->items as $result) {
    // Fetching list of email templates for the current company/location
    $data2 = file_get_contents("https://app.agendize.com/api/2.1/scheduling/companies/$result->id/settings/messages/emails?apiKey=$apikey&token=$token");

    $ct = json_decode($data2);
    foreach ($ct->items as $key => $value) {
        // Table row for output
        echo $result->name . "\t" . $result->id . "\t" . $value->name . "\t" . $value->id . "\n";
        $ch = curl_init("https://app.agendize.com/api/2.1/scheduling/companies/$result->id/settings/messages/emails/$value->id?apiKey=$apikey&token=$token");
        
        //replace default color with new color
        $updatedTemplate = str_replace('#30AF93', '#194867', $value->html);
        
        //setup request to send json via PUT
        $data3 = array(
            'name' => $value->name,
            'html' => $updatedTemplate
        );
        $payload = json_encode($data3);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    
        //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);
    }
}
?>


Connexion ou Inscription pour poster un commentaire