What are the best practices for handling API authentication tokens in PHP when interacting with external services like chatwoot?

When interacting with external services like Chatwoot in PHP, it is important to securely handle API authentication tokens to prevent unauthorized access. One best practice is to store the tokens in a secure location, such as environment variables or a configuration file, and never hardcode them in your code. Additionally, consider using HTTPS for all API requests to encrypt the data being transmitted.

// Store your API authentication token securely in an environment variable
$api_token = getenv('CHATWOOT_API_TOKEN');

// Make API request using the stored token
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://your-chatwoot-instance.com/api/v1/conversations');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: Bearer ' . $api_token
));
$response = curl_exec($ch);
curl_close($ch);

// Handle the API response as needed