API Summary

Login API

To make API calls, the calling client has to have a valid authentication token pair (Username / Password) which can only be created through the GUI of D·engage Platform by the system administrator of the corresponding account under Configuration -> Users -> New User.

After your system administrator creates the Username / Password pair, please store it in a secure place since passwords are neither regeneratable nor changeable for security reasons.

Once you have the authentication token pair, you have to pass them to Login API and get the session of the calling client authenticated first.

Sending/Reporting Transactional Messages

In MMP Enterprise, the type of the message (transactional vs batch) changes the way of sending and reporting. Transactional messages are kept in MMP Enterprise database and report by many different powerful functions.

To send transactional messages, please check

  1. CreateTemplate: Creates a new template. Templates can also be created using Admin Panel. For transactional messages, creating templates using Admin Panel is strongly suggested.
  2. SendTemplate: Sends a template. Call API and pass parameters. The API will merge the parameters with the template and send the message to final destionation.

APIs under Transactional Send.

It is important to know that SendTemplate API saves the parameters and the merged content (the last content sent to the client) to MMP database. You must use SendTemplate function to send the most important and sensitive messages via this API.

To report this type of sendings, please use

  1. ReportByMessageId: Reports by a messages id
  2. ReportMessagesByRecipient: Reports by an recipient
  3. GetEventsByEventLogId: Infinite event log by event log id.

APIs. These APIs are used to gether transactional sends' reports from the database.

Sending/Reporting Batch Messages

Sending million of messages at a high speed is important for big batches of your company. MMP Enterprise approach to batch messages is completyle different from all others.

MMP Enterprise manages batch sendings completely in RabbitMQ Queues and doesn't use any database. That is why MMP Enterprise batch sends are so fast, so flexible with no problems.

To create batch sends,

  1. CreateTemplate: You need a template to create. Please use CreateTemplate function to create your message template.
  2. SendBatch: Call this API to create and put your batch file with a chosen template. The API will put your request to RabbitMQ in which the system will merge your data with the template and produce the final content and send it to the recipients. Batches with millions of records will take minutes to send.

To report such sendings:

  1. GetBatchReport: Call this API to get reports generated by your batch sendings.

  2. GetBatchError: There may be some errors while producing your messages. Call this API to get error reports occured during the process of batch processing.

C# Example

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Mechanic.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            // Test Environment Credentials
            var testApiUrl = "http://mmpdemo.dengage.com:9050";
            var testApiUsername = "blabla";
            var testApiPassword = "blabla";

            var testAccountId = 0;

            var emailPoolId = 0;
            var smsPoolId = 0;


            var smsNewTemplatePublicId = Guid.NewGuid().ToString();
            var batchId = "ExampleBatch01";
            var reportQueueName = "mmp-report";

            // 1 - Init
            ApiClient.InitAsync(testApiUrl, testApiUsername, testApiPassword).Wait();

            // 2 - Create Template
            var createTemplateResult = ApiClient.CreateTemplateAsync(testAccountId, "sms", smsPoolId, smsNewTemplatePublicId, "Test Sms Template", "Test Sms Message").Result;
            System.Console.WriteLine(createTemplateResult);

            // 3 - Send Batch
            var sendBatchResult = ApiClient.SendBatchAsync(batchId, smsNewTemplatePublicId, testAccountId).Result;
            System.Console.WriteLine(sendBatchResult);

            // 4 - Get Report (Gets the next message from message broker)
            var getReportResult = ApiClient.GetReportAsync(reportQueueName).Result;
            System.Console.WriteLine(getReportResult);

            // 5 - Parse Report Data
            dynamic reportMessage = JsonConvert.DeserializeObject(getReportResult);

            string channel = reportMessage.channel;
            DateTime reportDate = reportMessage.createdAt;
            int messageCount = int.Parse(reportMessage.messageCount.ToString());
            string reportType = reportMessage.reportType;
            string payload = reportMessage.payload;

            dynamic reportData = JsonConvert.DeserializeObject(payload);
            dynamic reportItem = reportData.ReportItem;

            List<object> messageReports = new List<object>();

            foreach (var msgReport in reportItem)
            {
                messageReports.Add((
                    msgReport["Message-ID"],
                    msgReport["bounce-time"],
                    msgReport["relay-time"],
                    msgReport["record-time"],
                    msgReport["partner-batch-id"],
                    msgReport["partner-message-id"],
                    msgReport["bounce-code"],
                    msgReport["bounce-text"]));
            }

            // You have 'messageReports'
        }
    }
}
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace MMPE.Example
{
    public static class ApiClient
    {
        public static string BaseApiUrl { get; set; }

        public static string UserName { get; set; }

        public static string Password { get; set; }

        public static string Token { get; set; }

        public static bool IsInitialized { get; set; }

        public static async Task InitAsync(string baseApiUrl, string userName, string password)
        {
            BaseApiUrl = baseApiUrl;
            UserName = userName;
            Password = password;
            Token = await GetTokenAsync();
            IsInitialized = true;
        }

        private static async Task<string> GetTokenAsync()
        {
            if (IsInitialized)
                return Token;

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    // 1 - Get Token...
                    var tokenUrl = $"{BaseApiUrl}/auth/login";
                    var tokenMsg = new HttpRequestMessage(HttpMethod.Post, tokenUrl);
                    var userName = UserName;
                    var password = Password;

                    var tokenRequest =
                        "{" +
                            $"\"userName\": \"{userName}\"," +
                            $"\"password\": \"{password}\"" +
                        "}";

                    tokenMsg.Content = new StringContent(tokenRequest, Encoding.UTF8, "application/json");
                    HttpResponseMessage response = await client.SendAsync(tokenMsg, HttpCompletionOption.ResponseHeadersRead);

                    var result = string.Empty;
                    HttpContent content = response.Content;
                    using (Task<string> completedTask = content.ReadAsStringAsync())
                    {
                        result = completedTask.Result;
                        completedTask.Dispose();
                    }

                    dynamic deserializedResultObject = JsonConvert.DeserializeObject(result);
                    var token = deserializedResultObject.token.Value;

                    return token;
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex);
                return null;
            }
        }
        
        public static async Task<string> CreateTemplateAsync(int accountId, string templateType, int poolId, string publicId, string templateName, string templateBody)
        {
            if (!IsInitialized)
                throw new Exception("Init ApiClient!");

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    // Add token to request...
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);

                    // Better you create a class for request and serialize it here... 
                    var request = "{\"accountId\": " + accountId + ",\"name\": \"" + templateName + "\",\"body\": \"" + templateBody + "\",\"publicId\": \"" + publicId + "\",\"poolId\": " + poolId + "}";

                    // Target Url of at api...
                    var uri = new Uri($"{BaseApiUrl}/template/{templateType}/create");

                    // Perform api call...
                    var msg = new HttpRequestMessage(HttpMethod.Post, uri);
                    msg.Content = new StringContent(request, Encoding.UTF8, "application/json");
                    var response = await client.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead);

                    //Reading result & returning...
                    var result = string.Empty;
                    var content = response.Content;
                    using (Task<string> completedTask = content.ReadAsStringAsync())
                    {
                        result = completedTask.Result;
                        completedTask.Dispose();
                    }

                    // If success, again you better create a class for api response and deserialize it here...
                    return result;
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex);
                return null;
            }
        }

        public static async Task<string> SendBatchAsync(string batchId, string publicId, int accountId)
        {
            if (!IsInitialized)
                throw new Exception("Init ApiClient!");

            try
            {
                var result = string.Empty;

                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    // Add token to request...
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);

                    using (var formData = new MultipartFormDataContent("request"))
                    {
                        var fileName = "data_sms_sample.csv";
                        var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
                        var fileBytes = File.ReadAllBytes(filePath);

                        formData.Add(new StreamContent(new MemoryStream(fileBytes)), "batchFile", fileName);
                        formData.Add(new StringContent(accountId.ToString()), "accountId");
                        formData.Add(new StringContent(publicId), "publicId");
                        formData.Add(new StringContent(batchId), "batchId");
                        formData.Add(new StringContent("0"), "batchPartId");
                        formData.Add(new StringContent("Message-ID;To;Name;Surname"), "fileHeaderMap");
                        formData.Add(new StringContent(";"), "delimiter");
                        formData.Add(new StringContent("1200"), "startTimes");
                        formData.Add(new StringContent("1600"), "finishTimes");
                        formData.Add(new StringContent("3000"), "speed");
                        formData.Add(new StringContent("1"), "priority");
                        formData.Add(new StringContent("2020-12-31T11:00:00.0000000+03:00"), "scheduleTime");

                        // Target Url of at api...
                        var uri = new Uri($"{BaseApiUrl}/batch/send");

                        // Perform api call...
                        var response = await client.PostAsync(uri, formData);

                        //Reading result & returning...
                        using (Task<string> completedTask = response.Content.ReadAsStringAsync())
                        {
                            result = completedTask.Result;
                            completedTask.Dispose();
                        }
                    }

                    // If success, you better create a class for api response and deserialize it here...
                    return result;
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex);
                return null;
            }
        }
        
        public static async Task<string> GetReportAsync(string queueName)
        {
            if (!IsInitialized)
                throw new Exception("Init ApiClient!");

            try
            {
                var result = string.Empty;

                using (HttpClient client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    // Add token to request...
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);

                    // Target Url of at api...
                    var uri = new Uri($"{BaseApiUrl}/batch/report?reportQueueName={queueName}");

                    // Perform api call...
                    var response = await client.GetAsync(uri);

                    //Reading result & returning...
                    using (Task<string> completedTask = response.Content.ReadAsStringAsync())
                    {
                        result = completedTask.Result;
                        completedTask.Dispose();
                    }

                    // If success, you better create a class for api response and deserialize it here...
                    return result;
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex);
                return null;
            }
        }
    }
}

dda15ac9-70ed-44c8-b723-74a6e044e7d4;905321112233;John;Doe