unione / unione-php
The UniOne SDK package what provide methods to interact with UniOne API.
Installs: 2 722
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 0
Open Issues: 3
Requires
- php: ^7.4 || ^8.0
- guzzlehttp/guzzle: ^6.5 || ^7
- webmozart/assert: ^1.9.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.15
- dev-master
- v1.2.0
- v1.1.0
- v1.0.0
- v0.0.1
- dev-KAN-8-Add-the-CC-and-BCC-headers-support
- dev-release-please--branches--master
- dev-PSUO-22-set-the-endpoint-as-required
- dev-PSUO-25-add-config-file-path-and-GuzzleHttp-load-fix
- dev-change_versiot_to__1_1_0
- dev-PSUO-22_add_unione_cli_script
- dev-PSUO-24_add_httpRequest_method_documentation
- dev-PSUO-22_Add_Webhooks_API
- dev-PSUO-21_allow_empty_fields_when_template_sends
- dev-PSUO-7_add_readme_md_file
- dev-PSUO-19_check_that_all_api_method_gets_array
- dev-PSUO-20_Made_endpoint_optional
- dev-PSUO-20_Make_endpoint_optional
- dev-PSUO-17_Add_platform_name_to_GET_param
- dev-PSUO-14_Implement_Template_API_handlers
- dev-Change_SDK_version
- dev-PSUO-18_Add_subscribe_method_in_Email_API
- dev-PSUO-12_API_response_processing
- dev-PSUO-11_Introduce_Api_Email_class
- dev-PSUO-13_Implement_debug_mode
- dev-PSUO-6-Create_email_class
- dev-PSUO-10-Configure_unit_tests
- dev-PSUO-9-Fix_release-please_action
- dev-PSUO-4-Expose_Guzzle_config
- dev-reviewdog-reporter
- dev-releases/1.0.0
- dev-release-please--branches--releases/1.0.0
- dev-releases/0.0.0
- dev-fix-style-and-add-timeout
This package is not auto-updated.
Last update: 2024-11-21 18:12:57 UTC
README
This SDK contains methods for easily interacting with the UniOne API: https://docs.unione.io/en/web-api-ref#web-api
Installation
Use Composer to install the package:
composer require unione/unione-php
Usage
Send email:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); // Example for EU instance. $client = new Unione\UnioneClient('YOUR-API-KEY', 'eu1.unione.io'); $recipients = [ [ "email" => 'john@example.com', "substitutions" => [ "to_name" => "John Smith" ], ], [ "email" => 'liza@example.com', "substitutions" => [ "to_name" => "Liza Frank" ], ] ]; $body = [ "html" => "<b>Test mail, {{to_name}}</b>", "plaintext" => "Hello, {{to_name}}", "amp" => "<!doctype html><html amp4email><head> <meta charset=\"utf-8\"><script async src=\"https://cdn.ampproject.org/v0.js\"></script> <style amp4email-boilerplate>body[visibility:hidden]</style></head><body> Hello, AMP4EMAIL world.</body></html>" ]; // You can use email object can be used to prepare the message array. // But the email send method accepts an array, that can be composed without // SDK utils. $mail = new Unione\Model\Email($recipients, $body); $mail->setFromEmail('user@example.com'); $mail->setSubject('test letter'); $response = $client->emails()->send($mail->toArray());
See API documentation for more details.
See template engine documentation for substitutions details.
Send subscribe email:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); $params = [ "from_email" => "john@example.com", "from_name" => "John Smith", "to_email" => "user@example.com" ]; $response = $client->emails()->subscribe($params);
API documentation.
Set template:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); $params = [ "template" => [ "name" => "First template", "body" => [ "html" => "<b>Hello, {{to_name}}</b>", "plaintext" => "Hello, {{to_name}}", "amp" => "<!doctype html><html amp4email><head> <meta charset=\"utf-8\"><script async src=\"https://cdn.ampproject.org/v0.js\"></script> <style amp4email-boilerplate>body[visibility:hidden]</style></head><body> Hello, AMP4EMAIL world.</body></html>" ], "subject" => "Test template mail", "from_email" => "test@example.com", "from_name" => "Example From", ] ]; $response = $client->templates()->set($params);
API documentation.
Get template:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); $response = $client->templates()->get('YOUR-TEMPLATE-ID');
API documentation.
Get templates list:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); $params = [ "limit" => 50, "offset" => 0 ]; $response = $client->templates()->list($params);
API documentation.
Delete template:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); $response = $client->templates()->delete('YOUR-TEMPLATE-ID');
API documentation.
Set webhook:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); $params = [ "url" => "https://yourhost.example.com/unione-webhook", "events" => [ "email_status" => [ "delivered", "opened", "clicked", "unsubscribed", "soft_bounced", "hard_bounced", "spam" ] ] ]; $response = $client->webhooks()->set($params);
API documentation.
The specified URL will receive a request from Unione. See more information about request data in API documentation.
This is how you can check the message integrity in your callback handler:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); // $body contains a callback request body. if ($client->webhooks()->verify($body) === TRUE) { // The webhook is confirmed, result can be processed. }
Get webhook:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); $response = $client->webhooks()->get('YOUR-WEBHOOK-URL');
API documentation.
Get list all or some webhooks:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); $response = $client->webhooks()->list();
API documentation.
Delete webhook:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); $response = $client->webhooks()->delete('YOUR-WEBHOOK-URL');
API documentation.
Additional information
Generic API method
For API methods, that are not implemented in SDK yet, you can use UnioneClient::httpRequest()
.
Here is an example for "set" suppression method:
$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME'); $response = $client->httpRequest('suppression/set.json', ["email" => "user@example.com", "cause" => "unsubscribed"]);
Set Guzzle HTTP client config
Unione client accepts an array with Guzzle configuration as a third argument. When creating a client, you can pass some additional options (i.e. connect_timeout) to apply this to all requests.
Here is a more advanced example of adding a history handler to save outcoming requests and responses.
$container = []; $history = Middleware::history($container); $handlerStack = HandlerStack::create(); $handlerStack->push($history); $config = ['handler' => $handlerStack]; $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME', $config);
See Guzzle documentation.