Prolateral Consulting Ltd
Prolateral Consulting Ltd
Support
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.

Problem

How do I Delete a Client (end-user) under my Partner account using the Partner API?
Deleting a client end-user using the RESTful Partner API?

Solution

The following example of code shows you how to delete a client (end-user) under your partner account.

Note, the client record is not fully deleted straight away, this is due to the client having services for which historic data is needed to be preserved. Please refer to the policy statement and data retention. When the client is deleted it is infact anonymised. When deleting a client it will disable & suspend all services under that client. It doesn't delete those services, for that you would need to list the live_services for a given client_id and individually delete them.

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
/**
 * client-del.php
 * 
 * This example will Delete a client.
 * Well in actual fact it disables the client ready for anonymising. 
 * 
 */
$apiPartnerId = "<PartnerID>";
$apiSecretKey = "___PartnerKey___";

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

$crlf         = "<br />";

// Set the ID of the client to delete.
$id = "9987608";

// 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 . "/$id");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

// API DELETE 
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
$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)   {
        echo "status = " . $result["meta"]["success"] . $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);




/**
 * client-del.cs
 * 
 * This example will Delete a client.
 * Well in actual fact it disables the client ready for anonymising. 
 * 
 */


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

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

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

        static void Main(string[] args)
        {
            // ID of the client to Delete.
            // Remember this is the my-engine id, not your own id (aka external-id)
            string id = "9987608";

            // Create HTTP resource
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(apiUrl + "/" + id);

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

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

            // Do the DELETE
            var response = client.DeleteAsync(id).Result;

            // Check the result
            if (response.IsSuccessStatusCode)
            {
                var jsonResponseStr = response.Content.ReadAsStringAsync().Result;
                dynamic jsonResponse = JsonConvert.DeserializeObject(jsonResponseStr);
                if (jsonResponse.ContainsKey("meta"))
                {
                    Console.WriteLine("status = {0}", jsonResponse["meta"]["success"]);
                }
                else
                {
                    Console.WriteLine("response = {0}", response);
                    Console.WriteLine("json response = {0}", jsonResponse);
                }

                // Echo the result
                Console.WriteLine("response = {0}", response);
            }
            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.
            client.Dispose();
        }
    }
}


'
' client-del.vb
' 
' This example will Delete a client.
' Well in actual fact it disables the client ready for anonymising.
' 
'

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

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/clients"

    Sub Main(args As String())

        ' ID of the client to Delete.
        ' Remember this Is the my-engine id, Not your own id (aka external-id)
        Dim id As String = "9987608"

        ' Create HTTP resource
        Dim client As New HttpClient()
        client.BaseAddress = New Uri(apiUrl + "/" + id)

        ' 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 DELETE
        Dim response As HttpResponseMessage = client.DeleteAsync(id).Result

        ' Check the result 
        If (response.IsSuccessStatusCode) Then
            Dim jsonResponseStr = response.Content.ReadAsStringAsync().Result
            Dim jsonResponse As Object = JsonConvert.DeserializeObject(jsonResponseStr)
            If jsonResponse.ContainsKey("meta") Then
                Console.WriteLine("status = {0}", jsonResponse("meta")("success"))
            Else
                Console.WriteLine("response = {0}", response)
                Console.WriteLine("json response = {0}", jsonResponse)
            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 Sub

End Module




/**
 * client-del.js
 * 
 * This example will Delete a client.
 * Well in actual fact it disables the client ready for anonymising. 
 * 
 */

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

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

// Set the ID of the client to delete.
var id = "9987608";

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

// API DELETE
$.ajax(settings)
    .done(function(response) {
        console.log("status = " + response.meta.success);
        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);
        }
    });
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.