### Download Email Opens using Java HTTPURLConnection Source: https://dev.emaillabs.io/index Illustrates how to retrieve email open statistics in Java using HttpURLConnection. This example shows setting up authentication headers (Basic Auth with Base64 encoding), constructing URL parameters dynamically from a HashMap, and making a GET request. It includes error handling for exceptions during the process. ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.sql.Timestamp; import java.io.OutputStreamWriter; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Base64; public class DownloadOpens { public static void main(String[] args) { try { // setup variables String appKey = "appkey"; String secretKey = "secretkey"; String userpass = appKey + ":" + secretKey; String basicAuth = "Basic " + Base64.getEncoder().encodeToString(userpass.getBytes("UTF-8")); String dateFrom = new String("" + (new Date().getTime() / 1000)); // set params HashMap params = new HashMap(); params.put("offset", "0"); params.put("limit", "10"); params.put("filter", "tags::TAG_1"); // build url StringBuilder urlParams = new StringBuilder(); boolean first = true; for (Map.Entry entry : params.entrySet()) { if (first) { urlParams.append("?"); first = false; } else { urlParams.append("&"); } urlParams.append(URLEncoder.encode(entry.getKey(), "UTF-8")); urlParams.append("="); urlParams.append(URLEncoder.encode(entry.getValue(), "UTF-8")); } // setup connection URL url = new URL("https://api.emaillabs.net.pl/api/opens" + urlParams.toString()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", basicAuth); // read output BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); System.out.print(in.readLine()); } catch (Exception e) { System.out.print(e.getMessage()); } } } ``` -------------------------------- ### Download Message Openings using Java HTTPURLConnection Source: https://dev.emaillabs.io/index This Java code example demonstrates how to fetch message opening statistics. It utilizes Java's built-in `HttpURLConnection` to make a GET request to the API endpoint. The snippet includes setting up basic authentication, constructing URL parameters, and reading the response stream. Error handling is included for exceptions during the process. ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.sql.Timestamp; import java.io.OutputStreamWriter; import java.util.Date; import java.util.HashMap; import java.util.Map; public class DownloadOpens { public static void main(String[] args) { try { // setup variables String appKey = "appkey"; String secretKey = "secretkey"; String userpass = appKey + ":" + secretKey; String basicAuth = "Basic " + Base64.getEncoder().encodeToString(userpass.getBytes("UTF-8")); String dateFrom = new String("" + (new Date().getTime() / 1000)); // set params HashMap params = new HashMap(); params.put("offset", "0"); params.put("limit", "10"); params.put("filter", "tags::TAG_1"); // build url StringBuilder urlParams = new StringBuilder(); boolean first = true; for (Map.Entry entry : params.entrySet()) { if (first) { urlParams.append("?"); first = false; } else { urlParams.append("&"); } urlParams.append(URLEncoder.encode(entry.getKey(), "UTF-8")); urlParams.append("="); urlParams.append(URLEncoder.encode(entry.getValue(), "UTF-8")); } // setup connection URL url = new URL("https://api.emaillabs.net.pl/api/opens" + urlParams.toString()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", basicAuth); // read output BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); System.out.print(in.readLine()); } catch (Exception e) { System.out.print(e.getMessage()); } } } ``` -------------------------------- ### Download Event Logs by ID (Python) Source: https://dev.emaillabs.io/index This Python example uses the `requests` library to fetch event logs by ID. It constructs the necessary basic authentication header and makes a GET request to the EmailLabs API. ```python import base64 import requests auth_header = base64.b64encode("appkey:secretkey") url = 'https://api.emaillabs.net.pl/api/get_event_api/xksoem2291aks91ksmais9xk' r = requests.get(url, headers={"Authorization": "Basic %s" % auth_header}) print(r.text) ``` -------------------------------- ### Download Email Events (OK) using Java Source: https://dev.emaillabs.io/index This Java code fetches 'OK' email events from the EmailLabs API. It constructs an HTTP GET request, including basic authentication headers and URL parameters for filtering. The example uses `HttpURLConnection` and `URLEncoder` to build the request and `Base64` for authentication. The output is read from the connection's input stream. ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.sql.Timestamp; import java.io.OutputStreamWriter; import java.util.Date; import java.util.HashMap; import java.util.Map; public class DownloadOnStatus { public static void main(String[] args) { try { // setup variables String appKey = "appkey"; String secretKey = "secretkey"; String userpass = appKey + ":" + secretKey; String basicAuth = "Basic " + Base64.getEncoder().encodeToString(userpass.getBytes("UTF-8")); String dateFrom = new String("" + (new Date().getTime() / 1000)); // set params HashMap params = new HashMap(); params.put("offset", "0"); params.put("limit", "10"); params.put("from_time", dateFrom); // build url StringBuilder urlParams = new StringBuilder(); boolean first = true; for (Map.Entry entry : params.entrySet()) { if (first) { urlParams.append("?"); first = false; } else { urlParams.append("&"); } urlParams.append(URLEncoder.encode(entry.getKey(), "UTF-8")); urlParams.append("="); urlParams.append(URLEncoder.encode(entry.getValue(), "UTF-8")); } // setup connection URL url = new URL("https://api.emaillabs.net.pl/api/smtp_events/ok" + urlParams.toString()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", basicAuth); // read output BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); System.out.print(in.readLine()); } catch (Exception e) { System.out.print(e.getMessage()); } } } ``` -------------------------------- ### PHP: Filter and Sort Parameters Example Source: https://dev.emaillabs.io/index Example demonstrating how to set filter and sort parameters for an API request in PHP. The filter allows for selecting specific records based on criteria like OS or IP, and also supports date range filtering. The sort parameter enables ordering of results. ```php $data = array( 'filter' => '"os::Windows|ip::1.1.1.1"' //'filter' => '"created_at.from::2014-01-01 00:00:00|created_at.to::2014-01-02 00:00:00"', 'sort' => '-created_at' ); ``` -------------------------------- ### Get Blacklist Reasons - Java Source: https://dev.emaillabs.io/index This Java code snippet demonstrates how to retrieve blacklist reasons using Java's HttpURLConnection. It sets up basic authentication with the provided AppKey and SecretKey, makes a GET request to the API, and prints the JSON response to the console. ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.sql.Timestamp; import java.io.OutputStreamWriter; import java.util.Date; import java.util.HashMap; import java.util.Map; public class BlacklistReasons { public static void main(String[] args) { try { // setup variables String appKey = "appkey"; String secretKey = "secretkey"; String userpass = appKey + ":" + secretKey; String basicAuth = "Basic " + Base64.getEncoder().encodeToString(userpass.getBytes("UTF-8")); // setup connection URL url = new URL("https://api.emaillabs.net.pl/api/blacklist_reasons"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", basicAuth); // read output BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); System.out.print(in.readLine()); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### GET /api/blacklist_reasons Source: https://dev.emaillabs.io/index Downloads a list of reasons for rejections on to the blacklist. This endpoint does not accept additional parameters. ```APIDOC ## GET /api/blacklist_reasons ### Description Downloads a list of reasons for rejections of email addresses onto the blacklist. This function does not accept additional parameters. Queries should be directed to the address below via a GET method. ### Method GET ### Endpoint `https://api.emaillabs.net.pl/api/blacklist_reasons` ### Parameters This endpoint does not accept any parameters. ### Request Example ``` GET https://api.emaillabs.net.pl/api/blacklist_reasons ``` ### Response #### Success Response (200) - **reasons** (array) - A list of rejection reasons. - **reason** (string) - The reason for rejection. #### Response Example ```json { "reasons": [ "hardbounce", "spam complaint" ] } ``` ### Error Handling - **401 Unauthorized**: Invalid or missing ApiKey or SecretKey. ``` -------------------------------- ### Success Response Example (JSON) Source: https://dev.emaillabs.io/index This example demonstrates the structure of a successful API response. It includes a status code, a status message, and a 'data' object. The 'data' object is a nested structure where keys represent date, hour, tag, and finally the status and count of emails. ```json { "code":200, "status":"success", "message":"OK", "data":[ "2015-12-01":{ "13":{ "tag1":{ "injected":6, "ok":6 } } }, "..." ] } ``` -------------------------------- ### Blacklist Success Response Example Source: https://dev.emaillabs.io/index This is an example of a successful response (HTTP 200) when querying an email address from the blacklist. It provides details such as the email address, source of blacklisting, reason, comment, and timestamps. ```json {     "code":200,     "status":"success",     "message":null,     "data":{      "account":"2.test.smtp",         "email":"search@address.pl",         "source":"smtp",         "reason":"hardbounce",         "comment":"Host or domain name not found. Name service error for name=niemadomeny.pl[...]",         "created_at":"2014-10-15 14:39:03",         "updated_at":null,         "id":"543e6b22c89e4204a2eeab92"     } } ``` -------------------------------- ### GET /api/blacklist_reasons Source: https://dev.emaillabs.io/index This endpoint allows you to download a list of reasons for rejections of email addresses that are added to the blacklist. It does not accept any additional parameters and should be accessed via a GET request. ```APIDOC ## GET /api/blacklist_reasons ### Description This function allows you to download a list of reasons for rejections of e-mail addresses on to the black list. This function does not accept additional parameters. Queries should be directed to the address below via a GET method. ### Method GET ### Endpoint https://api.emaillabs.net.pl/api/blacklist_reasons ### Parameters #### Query Parameters None ### Request Example None (GET request to the endpoint) ### Response #### Success Response (200) - **code** (Number) - HTTP 1.1 Standard code. - **status** (String) - Text version of status. - **message** (String) - Message status. - **data** (Object) - Data in JSON format. #### Response Example ```json { "code":200, "status":"success", "message":null, "data":[ "hardbounce", "unsubscribe", "spam_complaint", "other" ] } ``` #### Error Response (4xx) - **KeyError** (401) - Not set or incorrect ApiKey or SecretKey. If You want to check keys, log in to your panel. ``` -------------------------------- ### GET /api/opens - Download Message Openings Source: https://dev.emaillabs.io/index Retrieves message opening statistics. You can filter, sort, and paginate the results. The request must be sent using the GET method. ```APIDOC ## GET /api/opens ### Description This endpoint allows you to download user email opening statistics. It accepts various optional parameters for filtering, pagination, and sorting. ### Method GET ### Endpoint `https://api.emaillabs.net.pl/api/opens` ### Parameters #### Query Parameters - **offset** (integer) - Optional - Specifies the starting point for retrieving results (for pagination). - **limit** (integer) - Optional - Specifies the maximum number of results to return per page. - **sort** (string) - Optional - Specifies the order in which to sort the results. Use a hyphen prefix for descending order (e.g., `-created_at`). - **filter** (string) - Optional - Allows filtering results based on specific criteria such as `to::email@example.com`, `msgid::message_id`, or date ranges like `created_at.from::YYYY-MM-DD HH:MM|created_at.to::YYYY-MM-DD HH:MM`. ### Request Example (PHP cURL) ```php '"to::test@niedomena.pl"', // email filter // 'filter' => '"msgid::1404397451.53b5678b5ec06@swift.generated"', // message id filter // 'filter' => '"created_at.from::2014-01-01 00:00|created_at.to::2014-09-01 00:00"', // date filter 'offset' => 0, 'limit' => 5, 'sort' => '-created_at', ); //Transmission of search criteria for URL $url = sprintf("%s?%s", $url, http_build_query($data)); //Setting the authentication type curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Transmission of login data curl_setopt($curl, CURLOPT_USERPWD , "$appkey:$secret"); //Transfer URL with action curl_setopt($curl, CURLOPT_URL, $url); //Settings for the return from the server curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //Downloading results $result = curl_exec($curl); //Displaying in JSON format echo $result; ?> ``` ### Request Example (Python requests) ```python import base64 import requests import urllib auth_header = base64.b64encode(b"appkey:secretkey").decode('utf-8') url = 'https://api.emaillabs.net.pl/api/opens' data = { "offset": 0, 'limit': 10, 'sort': '-created_at' } r = requests.get(url+"?"+urllib.urlencode(data), headers={"Authorization": "Basic %s" % auth_header}) print(r.text) ``` ### Request Example (Java) ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.Base64; import java.util.HashMap; import java.util.Map; public class DownloadOpens { public static void main(String[] args) { try { // setup variables String appKey = "appkey"; String secretKey = "secretkey"; String userpass = appKey + ":" + secretKey; String basicAuth = "Basic " + Base64.getEncoder().encodeToString(userpass.getBytes("UTF-8")); // set params HashMap params = new HashMap(); params.put("offset", "0"); params.put("limit", "10"); params.put("filter", "tags::TAG_1"); // build url StringBuilder urlParams = new StringBuilder(); boolean first = true; for (Map.Entry entry : params.entrySet()) { if (first) { urlParams.append("?"); first = false; } else { urlParams.append("&"); } urlParams.append(URLEncoder.encode(entry.getKey(), "UTF-8")); urlParams.append("="); urlParams.append(URLEncoder.encode(entry.getValue(), "UTF-8")); } // setup connection URL url = new URL("https://api.emaillabs.net.pl/api/opens" + urlParams.toString()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", basicAuth); // read output BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder response = new StringBuilder(); String inputLine; while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.print(response.toString()); } catch (Exception e) { System.out.print(e.getMessage()); } } } ``` ### Response #### Success Response (200) - **data** (array) - Contains an array of opening records. - **date** (string) - Timestamp of the opening. - **email** (string) - Recipient's email address. - **id** (string) - Unique identifier for the opening event. - **tags** (array) - Array of tags associated with the email. #### Error Response (401) - **KeyError** (string) - Not set or incorrect ApiKey or SecretKey. Log in to your panel to check your keys. #### Error Response (404) - **NotFoundError** (string) - Not found any result matching the query. ``` -------------------------------- ### GET /api/vps Source: https://dev.emaillabs.io/index Downloads all VPSes assigned to the panel. VPS IDs can be used to create new SMTP accounts. ```APIDOC ## GET /api/vps ### Description This function lets you download all vpses assigned to the panel. Vpses ID may be used to create new smtp account. ### Method GET ### Endpoint https://api.emaillabs.net.pl/api/vps/ ### Parameters No specific parameters are required for this endpoint, but authentication is needed. ### Request Example ```php //CURL library initialization $curl = curl_init(); //Setting the address from which data will be downloaded $url = "https://api.emaillabs.net.pl/api/vps"; //Setting AppKey $appkey = 'Sample_App_key'; //Setting Secret Key $secret = 'Sample_Secret_Key'; //Setting the authentication type curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Transfer of login data curl_setopt($curl, CURLOPT_USERPWD , "$appkey:$secret"); //Transfer of URL with action curl_setopt($curl, CURLOPT_URL, $url); //Settings for the return from the server curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //Downloading results $result = curl_exec($curl); //Displaying in JSON format echo $result; ``` ### Response #### Success Response (200) - **code** (Number) - HTTP 1.1 Standard code. - **status** (String) - Text version of status. - **message** (String) - Message status. - **data** (Object) - Data in JSON format. - **data[ip]** (Array) - VPS IP addresses. - **data[type]** (String) - Type of VPS (1 - dedicated, 2 - shared). - **data[id]** (String) - VPS ID. - **data[free]** (String) - Indicates if the VPS is free (1 - free, 0 - not free). - **req_id** (String) - Request ID. #### Response Example ```json { "code": 200, "status": "success", "message": "VPS list retrieved successfully.", "data": [ { "ip": "192.168.1.1", "type": "1", "id": "vps_12345", "free": "0" } ], "req_id": "abcde12345" } ``` ### Error Handling - **KeyError** (401) - Not set or incorrect ApiKey or SecretKey. If You want to check keys, log in to your panel. ``` -------------------------------- ### Filter Data by Creation Date - PHP Example Source: https://dev.emaillabs.io/index This snippet demonstrates how to filter API data by a specific creation date range using PHP. It constructs an array with the 'filter' key, specifying the start and end times for 'created_at'. This is useful for retrieving historical data within a defined period. ```php $data = array( 'filter' => '"created_at.from::2014-01-01 00:00|created_at.to::2014-01-02 00:00"', ); ``` -------------------------------- ### Send Email using Templates via EmailLabs API (Java) Source: https://dev.emaillabs.io/index This Java code demonstrates sending an email using the EmailLabs API with a template. It covers setting up basic authentication with Base64 encoding, preparing the request URL, and constructing the request body. The example includes placeholders for app key, secret key, and file handling for attachments. It shows how to set connection properties, write to the output stream, and read the response from the server. ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.sql.Timestamp; import java.io.OutputStreamWriter; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Base64; public class SendMailTemplates { public static void main(String[] args) { try { // setup variables String appKey = "appkey"; String secretKey = "secretkey"; String userpass = appKey + ":" + secretKey; String basicAuth = "Basic " + Base64.getEncoder().encodeToString(userpass.getBytes("UTF-8")); String base64Image = ""; File file = new File("3.png"); FileInputStream imageInFile = new FileInputStream(file); byte imageData[] = new byte[(int) file.length()]; imageInFile.read(imageData); base64Image = Base64.getEncoder().encodeToString(imageData); ``` -------------------------------- ### Download Event Logs by ID (PHP) Source: https://dev.emaillabs.io/index This PHP example demonstrates how to retrieve event logs by ID using cURL. It sets up basic authentication with an AppKey and SecretKey and specifies the API endpoint URL. ```php //CURL library initialization $curl = curl_init(); //Setting the address from which data will be downloaded $url = "https://api.emaillabs.net.pl/api/get_event_api/590b04eac3f02dewrb14219f"; //Setting AppKey $appkey = 'Sample_App_key'; //Setting Secret Key $secret = 'Sample_Secret_Key'; //Setting the authentication type curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Transfer of login data curl_setopt($curl, CURLOPT_USERPWD , "$appkey:$secret"); //Transfer URL with action curl_setopt($curl, CURLOPT_URL, $url); //Settings for the return from the server curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //Downloading results $result = curl_exec($curl); //Displaying in JSON format echo $result; ``` -------------------------------- ### Download Message Openings using PHP cURL Source: https://dev.emaillabs.io/index This snippet demonstrates how to download message opening statistics using PHP's cURL library. It shows how to initialize cURL, set the API endpoint, authentication credentials (AppKey and SecretKey), and construct search criteria using parameters like offset, limit, and sort. The result is fetched and displayed in JSON format. ```php //CURL library initialization $curl = curl_init(); //Setting the address from which data will be downloaded $url = "https://api.emaillabs.net.pl/api/opens"; //Setting AppKey $appkey = 'Sample_App_key'; //Setting Secret Key $secret = 'Sample_Secret_Key'; //reating search criteria $data = array( // 'filter' => '"to::test@niedomena.pl"', // email filter // 'filter     '"msgid::1404397451.53b5678b5ec06@swift.generated"', // message id filter // 'filter' => '"created_at.from::2014-01-01 00:00|created_at.to::2014-09-01 00:00"', // date filter 'offset' => 0, 'limit' => 5, 'sort' => '-created_at', ); //Transmission of search criteria for URL $url = sprintf("%s?%s", $url, http_build_query($data)); //Setting the authentication type curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Transmission of login data curl_setopt($curl, CURLOPT_USERPWD , "$appkey:$secret"); //Transfer URL with action curl_setopt($curl, CURLOPT_URL, $url); //Settings for the return from the server curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //Downloading results $result = curl_exec($curl); //Displaying in JSON format echo $result; ``` -------------------------------- ### Fetch Aggregated Data with Python Requests Source: https://dev.emaillabs.io/index Fetches aggregated data from the EmailLabs API using Python's 'requests' library. This example demonstrates how to construct the authorization header using base64 encoding and build the URL with query parameters for 'smtp_account', 'date_from', and 'date_to'. It sends a GET request and prints the response text. Ensure your API credentials and dates are correctly formatted. ```python import base64 import requests import urllib import time import datetime auth_header = base64.b64encode("appkey:secretkey") url = 'https://api.emaillabs.net.pl/api/agregate' data = { "smtp_account": "1.nazwa_konta.smtp", "date_from": time.mktime(datetime.datetime.strptime("2017-01-01", "%Y-%m-%d").timetuple()), "date_to": time.mktime(datetime.datetime.strptime("2017-02-12", "%Y-%m-%d").timetuple()) } r = requests.get(url + "?" + urllib.urlencode(data), headers={"Authorization": "Basic %s" % auth_header}) print(r.text) ``` -------------------------------- ### GET /websites/dev_emaillabs_io Source: https://dev.emaillabs.io/index Retrieves email status information based on provided parameters. You can filter and sort the results to get specific data. ```APIDOC ## GET /websites/dev_emaillabs_io ### Description This endpoint retrieves email status information. It supports filtering by status, pagination with limit and offset, time-based retrieval, sorting, and filtering by specific fields. ### Method GET ### Endpoint /websites/dev_emaillabs_io ### Parameters #### Query Parameters - **status** (String) - Required - The status parameter is contained in the url of the api function. Change to one of the Emaillabs statuses (ok, dropped, softbounce, hardbounce, spambounce, feedback). - **limit** (Number) - Optional - Limit of elements. - **offset** (Number) - Optional - Skip number of elements. - **from_time** (Number) - Optional - Data from in the form of a timestamp. - **sort** (String) - Optional - Sort by field. Example: `-created_at` for descending sort by creation date. - **from_to** (Number) - Optional - Data to in the form of a timestamp. This field can be empty, then `from_to` has the actual time. - **filter** (String) - Optional - Field after which it will be filtered. It is possible to filter by fields: `message_id`, `tags`, `to`, `created_at`, `updated_at`. Example for `created_at`: `"created_at.from::2014-01-01 00:00|created_at.to::2014-01-02 00:00"`. ### Request Example ```json { "filter": "\"created_at.from::2014-01-01 00:00|created_at.to::2014-01-02 00:00\"", "sort": "-created_at" } ``` ### Response #### Success Response (200) - **code** (Number) - HTTP 1.1 Standard code. - **status** (String) - Text version of status. - **message** (String) - Message status. - **data** (Object) - Data in JSON format. - **data.time** (Object) - Contains `sec` (timestamp) and `usec` (microseconds) for the time the status was received. - **data.status** (String) - Status message (e.g., "softbounce"). - **data.message_id** (String) - ID of the message. - **data.tags** (Array) - Array of tags associated with the message. - **data.to** (String) - Recipient email address. #### Response Example ```json { "code": 200, "status": "success", "message": "ok", "data": [ { "time": { "sec": 1417587318, "usec": 0 }, "status": "softbounce", "message_id": "df76e3c537a5bb0b47ffb5f6554dcbad@panel", "tags": [ "Dispatch", " Television", " Test", " Soft" ], "to": "testsoft@nodomain.com.pl" }, {...} ] } ``` ``` -------------------------------- ### Download Event Logs by ID (Java) Source: https://dev.emaillabs.io/index This Java code snippet demonstrates fetching event logs by ID. It establishes an HTTP connection, sets the authorization header using Basic authentication with provided keys, and reads the response. ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.sql.Timestamp; import java.io.OutputStreamWriter; import java.util.Date; import java.util.HashMap; import java.util.Map; public class GetEventApi { public static void main(String[] args) { try { // setup variables String appKey = "appkey"; String secretKey = "secretkey"; String userpass = appKey + ":" + secretKey; String basicAuth = "Basic " + Base64.getEncoder().encodeToString(userpass.getBytes("UTF-8")); String id = "0dn27xhauejx2jsucc92mlsmxj"; // setup connection URL url = new URL("https://api.emaillabs.net.pl/api/get_event_api/" + id); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", basicAuth); // read output BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); System.out.print(in.readLine()); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### GET /api/agregate Source: https://dev.emaillabs.io/index This endpoint allows you to download aggregated data divided into statuses. Queries should be directed to this address using the GET method. ```APIDOC ## GET /api/agregate ### Description This endpoint allows you to download aggregated data divided into statuses. Queries should be directed to the address below by using the GET method. ### Method GET ### Endpoint https://api.emaillabs.net.pl/api/agregate ### Parameters #### Query Parameters - **smtp_account** (String) - Required - SMTP account name. - **date_from** (Date) - Required - Data from in the form of a timestamp. - **date_to** (Date) - Optional - Data to in the form of a timestamp. The difference between date_from and date_to cannot be greater than 62 days. ### Request Example ```json { "smtp_account": "1.kontosmtp.smtp", "date_from": 1448928000, "date_to": 1449532799 } ``` ### Response #### Success Response (200) - **data** (Object) - Aggregated data. - **count** (Integer) - Total count of records. #### Response Example ```json { "data": { "sent": 1000, "delivered": 950, "bounced": 50 }, "count": 1 } ``` ``` -------------------------------- ### Fetch Event API Logs with PHP using CURL Source: https://dev.emaillabs.io/index This snippet demonstrates how to initialize the CURL library in PHP to fetch event API logs. It sets up authentication with App Key and Secret Key, defines request parameters like offset and limit, and configures CURL options for URL, authentication, and response handling. The result is then printed. ```php //Initialization of CURL library $curl = curl_init(); //Setting the address from which data will be collected $url = "https://api.emaillabs.net.pl/api/get_event_api_logs"; //Setting App Key $appkey = 'APP_KEY'; //Setting Secret Key $secret = 'SECRET_KEY'; //Creating criteria of dispatch $data = array( 'offset' => 0, 'limit' => 2, // 'filter' => 'created_at.from::2017-04-08|created_at.to::2017-05-05', // 'status' => 1 ); $url = sprintf("%s?%s", $apiUrl.$action, http_build_query($data)); //Transfer URL action curl_setopt($curl, CURLOPT_URL, $url); //Setting the authentication type curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD , "$appkey:$secret"); //Settings of the return from the server curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //Download results $result = curl_exec($curl); echo $result; ``` -------------------------------- ### GET /api/agregate_tags Source: https://dev.emaillabs.io/index Retrieves aggregated statistics for email sending, divided by tags. This endpoint uses the GET method and requires authentication. ```APIDOC ## GET /api/agregate_tags ### Description Retrieves aggregated statistics for email sending, divided by tags. This endpoint uses the GET method and requires authentication. ### Method GET ### Endpoint https://api.emaillabs.net.pl/api/agregate_tags ### Query Parameters - **smtp_account** (string) - Required - The SMTP account to filter by. - **date_from** (integer) - Required - A Unix timestamp representing the start date for the aggregation. - **date_to** (integer) - Optional - A Unix timestamp representing the end date for the aggregation. If omitted, the current date is used. ### Request Example (cURL) ```bash curl -u "appkey:secretkey" "https://api.emaillabs.net.pl/api/agregate_tags?smtp_account=1.kontosmtp.smtp&date_from=$(date +%s -d '2015-12-01 00:00:00')&date_to=$(date +%s -d '2015-12-07 23:59:59')" ``` ### Request Example (PHP) ```php '1.kontosmtp.smtp', 'date_from' => strtotime( "2015-12-01 00:00:00" ), 'date_to' => strtotime( "2015-12-07 23:59:59" ) ); // Transmission of search criteria for URL $url = sprintf("%s?%s", $url, http_build_query($data)); //Setting the authentication type curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //Transmission of loggin data curl_setopt($curl, CURLOPT_USERPWD , "$appkey:$secret"); //Transfer URL with action curl_setopt($curl, CURLOPT_URL, $url); //Settings for the return from the server curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //Downloading results $result = curl_exec($curl); //Displaying results echo $result; ?> ``` ### Request Example (Python) ```python import base64 import requests import urllib import time import datetime auth_header = base64.b64encode(b"appkey:secretkey") url = 'https://api.emaillabs.net.pl/api/agregate_tags' data = { "smtp_account": "1.nazwa_konta.smtp", "date_from": int(time.mktime(datetime.datetime.strptime("2017-01-01", "%Y-%m-%d").timetuple())), "date_to": int(time.mktime(datetime.datetime.strptime("2017-02-12", "%Y-%m-%d").timetuple())) } r = requests.get(url+"?"+urllib.urlencode(data), headers={"Authorization": "Basic %s" % auth_header.decode('utf-8')}) print(r.text) ``` ### Request Example (Java) ```java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.Base64; import java.util.Date; import java.util.HashMap; import java.util.Map; public class AggregatedDataTags { public static void main(String[] args) { try { // setup variables String appKey = "appkey"; String secretKey = "secretkey"; String userpass = appKey + ":" + secretKey; String basicAuth = "Basic " + Base64.getEncoder().encodeToString(userpass.getBytes("UTF-8")); long dateFromTimestamp = new Date().getTime() / 1000; // set params HashMap params = new HashMap(); params.put("smtp_account", "1.panelname.smtp"); params.put("date_from", String.valueOf(dateFromTimestamp)); // build url StringBuilder urlParams = new StringBuilder(); boolean first = true; for (Map.Entry entry : params.entrySet()) { if (first) { urlParams.append("?"); first = false; } else { urlParams.append("&"); } urlParams.append(URLEncoder.encode(entry.getKey(), "UTF-8")); urlParams.append("="); urlParams.append(URLEncoder.encode(entry.getValue(), "UTF-8")); } // setup connection URL url = new URL("https://api.emaillabs.net.pl/api/agregate_tags" + urlParams.toString()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", basicAuth); // read output BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; StringBuilder response = new StringBuilder(); while ((line = in.readLine()) != null) { response.append(line); } System.out.print(response.toString()); } catch (Exception e) { System.out.print(e.getMessage()); } } } ``` ### Response #### Success Response (200) Returns a JSON object containing aggregated statistics. The structure of the response depends on the data available. #### Response Example ```json { "data": [ { "tag": "processed", "count": 1000, "bytes": 5000000 }, { "tag": "delivered", "count": 980, "bytes": 4900000 } ] } ``` ``` -------------------------------- ### Python: Download Blacklist Data with Requests Source: https://dev.emaillabs.io/index This Python script utilizes the 'requests' library to fetch blacklist data. It requires base64 encoding for authentication and constructs the URL with query parameters. The retrieved data is then printed to the console. ```python import base64 import requests import urllib auth_header = base64.b64encode("appkey:secretkey") url = 'https://api.emaillabs.net.pl/api/blacklists' data = { "offset": 0, "limit": 5 } r = requests.get(url+"?"+urllib.urlencode(data), headers={"Authorization": "Basic %s" % auth_header}) print(r.text) ``` -------------------------------- ### GET /api/clicks Source: https://dev.emaillabs.io/index Downloads message click data. Queries must be sent using the GET method. Data is stored for seven days. ```APIDOC ## GET /api/clicks ### Description Downloads statistics on users clicking on links within emails. This endpoint accepts additional parameters and stores data for seven days after shipment. ### Method GET ### Endpoint https://api.emaillabs.net.pl/api/clicks ### Parameters #### Query Parameters - **date_from** (string) - Required - Start date for the click data (YYYY-MM-DD). - **date_to** (string) - Required - End date for the click data (YYYY-MM-DD). - **limit** (integer) - Optional - Maximum number of records to return. - **offset** (integer) - Optional - Number of records to skip. ### Request Example ```bash # Example using CURL $appkey = 'Sample_App_key'; $secret = 'Sample_Secret_Key'; $date_from = '2023-10-20'; $date_to = '2023-10-27'; $url = "https://api.emaillabs.net.pl/api/clicks?date_from=$date_from&date_to=$date_to&limit=10&offset=0"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, "$appkey:$secret"); $result = curl_exec($ch); curl_close($ch); echo $result; ``` ### Response #### Success Response (200) - **clicks** (array) - A list of click data objects. - **message_id** (string) - The identifier for the email message. - **recipient** (string) - The email address of the recipient. - **link_url** (string) - The URL that was clicked. - **clicked_at** (string) - Timestamp when the click occurred. #### Response Example ```json { "clicks": [ { "message_id": "msg_abc789", "recipient": "user@example.com", "link_url": "https://example.com/link", "clicked_at": "2023-10-25T14:30:00Z" } ] } ``` ```