Prolateral Consulting Ltd
Prolateral Consulting Ltd
Support
Knowledgebase Articles
Help
Setup examples
Support

Prolateral offers primary and backup domain (DNS) services, with servers in key geographic locations providing the best service possible.

Slider

Problem

How do I get the details of a single outMail service using the Partner API?
Get the details of an outMail service using the RESTful Partner API?

Solution

The following example of code shows you how to GET the details of an outMail service.

Notes

It is assumed that you already have the following.

  • outMail ID - You need the outmail id to retrieve the details of the service. outMail ID can be found by using the /outmails end point. See the examples on outmails-list.

Prerequisites

To use the Partner API you must meet the following criteria

  • Have a working development environment.
  • Have an active Partner account. If you need a partner account you can sign up here.
  • Enabled your account to use the API and set the access controls.
  • Have valid API Credentials.
  • Optional - Setup your development environment to initially use the Sandbox Testing Portal.

For Partner API reference documentation please see https://portal.my-engine.com/apidocs/index.html

Example Code

The examples below uses the sandbox. For a production environment remember to change the following:

  • API Url
  • Partner ID
  • Partner API Key

<?php
/**
 * outmail-get.php
 * 
 * This example with do an API GET for a outmail based on a specified outmail_id.
 * 
 */
 
$apiPartnerId = "<PartnerID>";
$apiSecretKey = "___PartnerKey___";

$apiUrl       = "https://sandbox.my-engine.com/api-v1/outmails/";

$crlf         = "<br />";

// ID of the outmail service to Get.
$outmailIdToGet = "12341504";

// Init Curl
$curl = curl_init();

// API Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "$apiPartnerId:$apiSecretKey");

// Set Curl Options
curl_setopt($curl, CURLOPT_URL, $apiUrl . $outmailIdToGet);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

// API GET
$jsonResult = curl_exec($curl);

// Check for a valid HTTP 200 success and process the returned result
// or handler the failure.
if (curl_getinfo($curl, CURLINFO_RESPONSE_CODE) == 200) {
    $result = json_decode($jsonResult, true);

    if (json_last_error() == JSON_ERROR_NONE)   {
        // We have valid Json data, so lets display the results.
        echo "outMail ID = " . $result['data']["id"] . $crlf;
        echo "Client ID = " . $result['data']["client_id"] . $crlf;
        echo "outMail Status = " . $result['data']["enabled"] . $crlf;
        echo "outMail Billing Status = " . $result['data']["account_status_id"] . $crlf;
        echo "outMail Server = " . $result['data']["outmail_server_id"] . $crlf;
        echo "outMail Username = " . $result['data']["username"] . $crlf;
        echo "outMail Password = " . $result['data']["password"] . $crlf;
        echo "Live Service URL = " . $result['data']["live_service_endpoint_url"] . "    (You will need this URL and ID for Delete & Un/Suspend actions)" . $crlf;
        echo "Live Service ID = " . $result['data']["live_service_id"] . $crlf . $crlf;
    }
    
} else {
    echo "Response Code = " . curl_getinfo($curl, CURLINFO_RESPONSE_CODE) . $crlf;
    
    $result = json_decode($jsonResult, true);
    if (json_last_error() == JSON_ERROR_NONE)   {
        echo "error = " . $result["error"]["name"] . $crlf;
        echo "url = " . $result["error"]["url"] . $crlf;
        echo "message = " . $result["error"]["message"] . $crlf;
    } else {
        echo $jsonResult;
    }
}

curl_close($curl);



/**
 * outmail-get.php
 * 
 * This example with do an API GET for a outmail based on a specified outmail_id.
 * 
 */

using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace outmail_get
{
    class Program
    {
        private const string apiPartnerId = "<PartnerID>";
        private const string apiSecretKey = "_PartnerKey_";

        private const string apiUrl = "https://sandbox.my-engine.com/api-v1/outmails/";

        static async Task Main(string[] args)
        {
            // ID of the outmail service to Get.
            string outmailIdToGet = "12341504";

            // Create HTTP resource
            HttpClient outMail = new HttpClient();

            // Add an Accept header for JSON format.
            outMail.DefaultRequestHeaders.Add("ContentType", "application/json");

            // Set the Authorisation
            var authToken = System.Text.Encoding.UTF8.GetBytes(apiPartnerId + ":" + apiSecretKey);
            outMail.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", System.Convert.ToBase64String(authToken));

            // Do the GET request.
            HttpResponseMessage response = await outMail.GetAsync(apiUrl + outmailIdToGet);
            if (response.IsSuccessStatusCode)
            {
                var content = response.Content.ReadAsStringAsync();

                dynamic details = JsonConvert.DeserializeObject(content.Result);
                if (details.ContainsKey("data"))
                {
                    // View the entire record
                    // Console.WriteLine("data = {0}", item);

                    // Display the data we want.
                    Console.WriteLine("outMail ID = {0}", details["data"]["id"]);
                    Console.WriteLine("Client ID = {0}", details["data"]["client_id"]);
                    Console.WriteLine("outMail Status = {0}", details["data"]["enabled"]);
                    Console.WriteLine("outMail Billing Status = {0}", details["data"]["account_status_id"]);
                    Console.WriteLine("outMail Server = {0}", details["data"]["outmail_server_id"]);
                    Console.WriteLine("outMail Username = {0}", details["data"]["username"]);
                    Console.WriteLine("outMail Password = {0}", details["data"]["password"]);
                    Console.WriteLine("Live Service URL = {0}    (You will need this URL and ID for Delete & Un/Suspend actions)", details["data"]["live_service_endpoint_url"]);
                    Console.WriteLine("Live Service ID = {0} \n", details["data"]["live_service_id"]);
                }
                else
                {
                    Console.WriteLine("response = {0}", response);
                    Console.WriteLine("json response = {0}", details);
                }

            }
            else
            {
                // Get the Json Error response and convert it
                var jsonResponseStr = response.Content.ReadAsStringAsync().Result;
                dynamic jsonResponse = JsonConvert.DeserializeObject(jsonResponseStr);
                Console.WriteLine("name = {0}", jsonResponse["error"]["name"]);
                Console.WriteLine("url = {0}", jsonResponse["error"]["url"]);
                Console.WriteLine("message = {0}", jsonResponse["error"]["message"]);
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }

            //Dispose once all HttpClient calls are complete.
            outMail.Dispose();
        }
		
    }
}


'
' outmail-get.vb
' 
' This example with do an API GET for a outmail based on a specified outmail_id.
' 
'

Imports Newtonsoft.Json
Imports System
Imports System.Net.Http
Imports System.Net.Http.Headers
Imports System.Threading.Tasks

Module Program

    Private Const apiPartnerId As String = "<PartnerID>"
    Private Const apiSecretKey As String = "_PartnerKey_"

    Private Const apiUrl As String = "https://sandbox.my-engine.com/api-v1/outmails/"

    Public Sub Main(args As String())
        outmailGet().Wait()
    End Sub


    Public Async Function outmailGet() As Task

        ' ID of the outmail service to Get.
        Dim outmailIdToGet As String = "12341504"

        ' Create HTTP resource
        Dim client As New HttpClient()

        ' Add an Accept header for JSON format.
        client.DefaultRequestHeaders.Add("ContentType", "application/json")

        ' Set the Authorisation
        Dim authToken = System.Text.Encoding.UTF8.GetBytes(apiPartnerId + ":" + apiSecretKey)
        client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Basic", System.Convert.ToBase64String(authToken))

        ' Do the GET request.
        Dim response As HttpResponseMessage = Await client.GetAsync(apiUrl + outmailIdToGet)
        If response.IsSuccessStatusCode Then

            Dim content = response.Content.ReadAsStringAsync()

            Dim details As Object = JsonConvert.DeserializeObject(content.Result)
            If details.ContainsKey("data") Then
                ' Display the data we want.
                Console.WriteLine("outmail ID = {0}", details("data")("id"))
                Console.WriteLine("Client ID = {0}", details("data")("client_id"))
                Console.WriteLine("outMail Status = {0}", details("data")("enabled"))
                Console.WriteLine("outMail Billing Status = {0}", details("data")("account_status_id"))
                Console.WriteLine("outMail Server = {0}", details("data")("outmail_server_id"))
                Console.WriteLine("outMail Username = {0}", details("data")("username"))
                Console.WriteLine("outMail Passowrd = {0}", details("data")("password"))
                Console.WriteLine("Live Service URL = {0}    (You will need this URL and ID for Delete & Un/Suspend actions)", details("data")("live_service_endpoint_url"))
                Console.WriteLine("Live Service ID = {0} {1}", details("data")("live_service_id"), vbCrLf)
            Else
                Console.WriteLine("response = {0}", response)
                Console.WriteLine("json response = {0}", details)
            End If
        Else
            ' Get the Json Error response And convert it
            Dim jsonResponseStr = response.Content.ReadAsStringAsync().Result
            Dim jsonResponse As Object = JsonConvert.DeserializeObject(jsonResponseStr)
            Console.WriteLine("name = {0}", jsonResponse("error")("name"))
            Console.WriteLine("url = {0}", jsonResponse("error")("url"))
            Console.WriteLine("message = {0}", jsonResponse("error")("message"))
            Console.WriteLine("{0} ({1})", response.StatusCode, response.ReasonPhrase)
        End If

        'Dispose once all HttpClient calls are complete.
        client.Dispose()


    End Function

End Module




/**
 * outmail-get.js
 * 
 * This example with do an API GET for a outmail based on a specified outmail_id.
 * 
 */

var apiPartnerId = "<PartnerID>";
var apiSecretKey = "_PartnerKey_";

var apiUrl = "https://sandbox.my-engine.com/api-v1/outmails/";

// ID of the outmail service to Get.
var outmailIdToGet = "12341504";

// Setup the Ajax request
var settings = {
    url: apiUrl + outmailIdToGet,
    headers: {
        'Authorization': 'Basic ' + btoa(apiPartnerId + ":" + apiSecretKey),
        'cache-control': 'no-cache'
    },
    crossDomain: true,
    dataType: 'json',
    async: true,
    method: "GET"
};

// API GET
$.ajax(settings)
    .done(function(response) {
        console.log("outMail ID = " + response.data.id);
        console.log("Client ID = " + response.data.client_id);
        console.log("outMail Status = " + response.data.enabled);
        console.log("outMail Billing Status = " + response.data.account_status_id);
        console.log("outMail Server = " + response.data.outmail_server_id);
        console.log("outMail Username = " + response.data.username);
        console.log("outMail Password = " + response.data.password);
        console.log("Live Service URL = " + response.data.live_service_endpoint_url + "    (You will need this URL and ID for Delete & Un/Suspend actions)");
        console.log("Live Service ID = " + response.data.live_service_id);
        console.log(" ");
    })
    .fail(function(request, textStatus, errorThrown) {
        try {
            var errObj = $.parseJSON(request.responseText);
            console.log("API Error - " + errObj.name);
            console.log("API Msg   - " + errObj.message);
            console.log("API url   - " + errObj.url);
        } catch (e) {
            console.log("Error - " + errorThrown);
            console.log("Status - " + request.status);
            console.log(request);
        }
    });
	

User Rating: 5 / 5   

like it, love it, then share it. Share this article on social media.

Did you enjoy this article?

Disclaimer

The Origin of this information may be internal or external to Prolateral Consulting Ltd. Prolateral makes all reasonable efforts to verify this information. However, the information provided in this document is for your information only. Prolateral makes no explicit or implied claims to the validity of this information. Any trademarks referenced in this document are the property of their respective owners.