Perl API

The United Notifications Perl API allows you to send notifications to your designated channels using the Mojolicious framework. Below is a comprehensive guide to help you integrate this functionality into your Perl applications.

Code Example

Here's an example of how to send a notification using the Mojo::UserAgent module in Perl:

use Mojo::UserAgent;

# Send the POST request
my $response = Mojo::UserAgent->new->post(
    'https://api.united-notifications.com' => 
    form => {
        client_key => 'f31c320dcd',
        channel    => '[channel-token]',
        type       => 'info',
        title      => 'This is a info-notification',
        body       => 'This is the body.',
        critical   => 0
    }
)->result;

# Output the result or error
print $response->body;

Ensure you have the Mojolicious module installed on your system. You can install it via CPAN with the command:

cpan Mojolicious
Parameters

The Perl API accepts the following parameters in the POST request:

  • client_key: Your unique API key used for authentication.
  • channel: The channel token identifying the recipient(s) of the notification.
  • type: The type of notification. Options include:
    • info: General information notifications.
    • warning: Alerts requiring attention.
    • error: Notifications about critical issues.
  • title: A brief title summarizing the notification content.
  • body: The main content of the notification message.
  • critical: A boolean value (0 for false or 1 for true) indicating the notification's urgency.
API Endpoint

All requests are sent to the following endpoint:

https://api.united-notifications.com

Use the HTTP POST method with form-encoded parameters for sending data.

Response

The response from the API contains information about the success or failure of your request. Typically, it includes:

  • status: Indicates whether the request was successful (success) or encountered an error (error).
  • message: Additional details about the operation or error.
  • data: (Optional) Contains any relevant metadata about the notification.

You can output the response using the print function as shown in the example above.

Security Considerations

To ensure secure communication:

  • All requests should use HTTPS for encrypted transmission.
  • Protect your client_key and avoid exposing it in public repositories.
  • Use secure storage for sensitive credentials.
  • Validate responses to confirm successful notification delivery.
Troubleshooting

If you encounter issues while using the API, consider the following:

  • Verify that the Mojo::UserAgent module is installed and properly configured.
  • Ensure the endpoint URL (https://api.united-notifications.com) is reachable from your environment.
  • Double-check the client_key and channel values for accuracy.
  • Inspect the API response for error messages to identify the root cause.
  • Check your internet connection and firewall rules to ensure outgoing POST requests are not blocked.
Usage Tips

To make your implementation more robust:

  • Wrap your API calls in error-handling routines to gracefully manage failures.
  • Log responses and errors to help with debugging and analytics.
  • Use asynchronous or non-blocking calls when sending large volumes of notifications.

By following this guide, you can efficiently integrate the United Notifications service into your Perl application to deliver real-time notifications to your users.

Did you find this page helpful?
These might also be helpful