Sample API Codes To Use

Examples of API Codes

Code examples for PHP, C#, VB.NET, Java, Python, PERL, jQuery, and AngularJS are shown below to assist with working with the Email YoYo API.

PHP Code Example

<?php

    // URL which should be requested

    $url = 'http://api.emailyoyo.com/api/a/v1';

    $apikey = 'YOUR API KEY';  // API Key

    $email  = 'Email Address to Test';  // Email to test

    // jSON String for request

    $url .= "?email=$email&key=$apikey";

    // Initializing curl

    $ch = curl_init( $url );

    if($ch == false) {

        die ("Curl failed!");

    } else {

        // Configuring curl options

        $options = array(

            CURLOPT_RETURNTRANSFER => true,            

            CURLOPT_HTTPHEADER => array('Content-type: application/json')

        );

        // Setting curl options

        curl_setopt_array( $ch, $options );

        // Getting results

        $result =  curl_exec($ch); // Getting jSON result string

        // display JSON data

        echo "$result";                        

    }     

?>

C# Code Example

#region Usings

using System;
using System.IO;
using System.Net;

#endregion

    /// <summary>
    /// The program.
    /// </summary>
    internal class Program
    {
        #region Constants

        /// <summary>
        /// The api url.
        /// </summary>
        private const string ApiUrl = @"http://api.emailyoyo.com/api/a/v1";

        /// <summary>
        ///     0 = ApiUrl
        ///     1 = Email address to query
        ///     2 = API Key
        /// </summary>
        private const string QueryFormatString = @"{0}?email={1}&key={2}";

        /// <summary>
        /// The your api key.
        /// </summary>
        /// <remarks>
        /// /*ENTER YOUR API KEY HERE*/
        /// </remarks>
        private const string YourAPIKey = @"<!-- ENTER A VALID KEY HERE-->";

        #endregion

        #region Methods

        /// <summary>
        /// The main program entry point.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            Console.WriteLine("Input email address to verify");

            var readLine = Console.ReadLine();

            Console.WriteLine(string.Empty);

            var requestUrl = string.Format(QueryFormatString, ApiUrl, readLine, YourAPIKey);

            var myRequest = (HttpWebRequest)WebRequest.Create(requestUrl);

            WebResponse webResponse = null;

            try
            {
                webResponse = myRequest.GetResponse();

                using (var reader = new StreamReader(webResponse.GetResponseStream()))
                {
                    var jsonString = reader.ReadToEnd();

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Result:");
                    Console.WriteLine(jsonString);
                    Console.ResetColor();
                    Console.WriteLine("Press <Enter> to continue..");
                    Console.ReadLine();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("An error occured:");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Exception reported: {0}", exception.Message);
                Console.ResetColor();
                Console.WriteLine("Press <Enter> to continue..");
                Console.ReadLine();
            }
            finally
            {
                if (webResponse != null)
                {
                    webResponse.Dispose();
                }
            }
        }

        #endregion
    }

VB.NET Code Example

Imports System.IO
Imports System.Net

  ''' <summary>
	''' The program.
	''' </summary>
	Friend Class Program
		#Region "Constants"

		''' <summary>
		''' The api url.
		''' </summary>
		Private Const ApiUrl As String = "http://api.emailyoyo.com/api/a/v1"

		''' <summary>
		'''     0 = ApiUrl
		'''     1 = Email address to query
		'''     2 = API Key
		''' </summary>
		Private Const QueryFormatString As String = "{0}?email={1}&key={2}"

		''' <summary>
		''' The your api key.
		''' </summary>
		''' <remarks>
		''' /*ENTER YOUR API KEY HERE*/
		''' </remarks>
		Private Const YourAPIKey As String = "<!-- ENTER A VALID KEY HERE-->"

		#End Region

		#Region "Methods"

		''' <summary>
		''' The main program entry point.
		''' </summary>
		''' <param name="args">
		''' The args.
		''' </param>
		Private Shared Sub Main(args As String())
			Console.WriteLine("Input email address to verify")

			Dim readLine = Console.ReadLine()

			Console.WriteLine(String.Empty)

			Dim requestUrl = String.Format(QueryFormatString, ApiUrl, readLine, YourAPIKey)

			Dim myRequest = DirectCast(WebRequest.Create(requestUrl), HttpWebRequest)

			Dim webResponse As WebResponse = Nothing

			Try
				webResponse = myRequest.GetResponse()

				Using reader = New StreamReader(webResponse.GetResponseStream())
					Dim jsonString = reader.ReadToEnd()

					Console.ForegroundColor = ConsoleColor.Green
					Console.WriteLine("Result:")
					Console.WriteLine(jsonString)
					Console.ResetColor()
					Console.WriteLine("Press <Enter> to continue..")
					Console.ReadLine()
				End Using
			Catch exception As Exception
				Console.WriteLine("An error occured:")
				Console.ForegroundColor = ConsoleColor.Red
				Console.WriteLine("Exception reported: {0}", exception.Message)
				Console.ResetColor()
				Console.WriteLine("Press <Enter> to continue..")
				Console.ReadLine()
			Finally
				If webResponse IsNot Nothing Then
					webResponse.Dispose()
				End If
			End Try
		End Sub

		#End Region
	End Class

JAVA Code Example

*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Program
{

        /*
         * The URL which should be requested
         */
        private static final String ApiUrl = "http://api.emailyoyo.com/api/a/v1";

        /*
         * Query string for request
         * %1$s = ApiUrl
         * %2$s = Email address to check
         * %3$s = API Key
         */
        private static final String QueryFormatString = "%1$s?email=%2$s&key=%3$s";

        /*
         * Your API Key
         *
         */
        private static final String YourAPIKey = "/* ENTER A VALID KEY HERE */";

        /**
         * The main program entry point
         * @param args the command line arguments
         * @throws IOException If the server does not return a success response
         */
        public static void main(String[] args)
        {
                System.out.println("Input email address to verify");

                // Create a scanner to read in the requested email address
                Scanner in = new Scanner(System.in);
                String readLine = in.next();

                try
                {
                        // Format the request url to the correct structure for the request
                        URL requestUrl = new URL(String.format(QueryFormatString, ApiUrl, readLine, YourAPIKey));

                        // Open a connection to the website
                        HttpURLConnection myRequest =  (HttpURLConnection) requestUrl.openConnection();

                        // Set the type to HTTP GET
                        myRequest.setRequestMethod("GET");

                        // Create a new buffered reader to read the response back from the server
                        BufferedReader reader = new BufferedReader(
                                new InputStreamReader(myRequest.getInputStream()));

                        String inputLine;
                        StringBuilder response = new StringBuilder();

                        // Read in the response line from the server
                        while ((inputLine = reader.readLine()) !=null )
                        {
                                response.append(inputLine);
                        }

                        // Close the reader
                        reader.close();

                        // Output the result to console
                        System.out.println(response.toString());
                }
                catch (IOException ex)
                {
                        Logger.getLogger(Program.class.getName()).log(Level.SEVERE, null, ex);
                }
        }

}

Python Code Example

# Import the module for handling the http request
    import urllib.request

    # The url for the service
    ApiUrl = "http://api.emailyoyo.com/api/a/v1"

    # The format  of the full query string
    QueryFormatString = "{0}?email={1}&key={2}"

    # The API key provided from Email YoYo goes here
    YourAPIKey = ""

    # Read in the user input
    readLine = input("Enter Email:\n")

    # Format the full url and make the http GET request and read the response
    response = urllib.request.urlopen(QueryFormatString.format(ApiUrl, readLine, YourAPIKey)).read()

    # Print the response
    print(response)

PERL Code Example

use LWP;

    # The url for the service
    $ApiUrl = "http://api.emailyoyo.com/api/a/v1";

    # The format  of the full query string
    $QueryFormatString = "%s?email=%s&key=%s";

    print "Enter Email:\n";
    $readLine = ;

    # The API key provided from Email YoYo goes here
    $YourAPIKey = "";

    # Format the url request
    $requestUrl = sprintf $QueryFormatString, $ApiUrl, $readLine, $YourAPIKey;

    # Make the request against the REST service
    $browser = LWP::UserAgent->new;
    $response = $browser->get($requestUrl);

    # Print the response
    print $response->content;

jQuery Code Example


AngularJS Code Example

-->

            

*

* not a valid email

validating…
Email address is valid.
Email address is not valid.
Unable to verify email. Reason={{additionalStatusMessage}}
Error. Message={{errorMessage}}

<< Back to main API overview

Request Free API Trial