Enrich Workflow API Code

API codes can be used to integrate Enrich API directly at user end.

Workflow API Code - Java

public static main(String[] args)
		{                                                                                                                  
			System.out.println("Start Processing");
			try
			{
				String url = "http://api.enrich.io/enrichapi/v2/enrichment";
				String requestBody = "{ "
							+ "\"userkey\" : \"Your User Key\", "
							+ "\"subuserkey\" : \"Your Sub User Key\", "
							+ "\"workflowcode\" : \"Your Created Workflow Code\", "
							+ "\"customvalues\" : {\"value\" : \"Your Custom Values\"}, "
							+ "\"params\" : {\"parameter\" : \"parameter value\" }}";
				String response = callService(requestBody, url);
				System.out.println("Response: "+response);
			}
			catch(Exception ex)
			{
				ex.printStackTrace();
			}
			System.out.println("End Processing");
		}
		public String callService(String inputStream,  String apiUrl) 
		{
			StringBuilder sbOutput = new StringBuilder();
			try 
			{
				URL url = new URL(apiUrl);
				HttpURLConnection conn = (HttpURLConnection) url.openConnection();
				conn.setDoOutput(true);
				conn.setRequestMethod("POST");
				conn.setRequestProperty("Content-Type", "application/json");
				OutputStream os =conn.getOutputStream();
				os.write(inputStream.getBytes());
				os.flush();
				BufferedReader br =null;
				if(conn.getResponseCode()!=200)
				{
				
					br = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
				}
				else
				{
					br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
				}
				String output;
				while ((output = br.readLine()) != null) {
					sbOutput.append(output+"\n");
				}
				conn.disconnect();
			} 
			catch (MalformedURLException ex) 
			{
				ex.printStackTrace();
			} 
			catch (IOException ex) 
			{
				ex.printStackTrace();
			}
			return sbOutput.toString();
		}

Workflow API Code - .NET

using System;
		using System.Collections.Generic;
		using System.Linq;
		using System.Text;
		using System.IO;
		using System.Net;
		using System.Xml;
		namespace ConsoleApplication
		{
			class Program
			{
				static void Main(string[] args)
				{
					Console.WriteLine("Start Processing");
					try
					{
						String ServiceUrl = "http://api.enrich.io/enrichapi/v2/enrichment";
						String strRequest = "{ "
							+ "\"userkey\" : \"Your User Key\", "
							+ "\"subuserkey\" : \"Your Sub User Key\", "
							+ "\"workflowcode\" : \"Your Created Workflow Code\", "
							+ "\"customvalues\" : {\"value\" : \"Your Custom Values\"}, "
							+ "\"params\" : {\"parameter\" : \"parameter value\" }}";

						String response = CallService(strRequest, ServiceUrl);
						Console.WriteLine(response);
						Console.ReadKey();
						
					}
					catch (Exception ex)
					{
						Console.WriteLine("Error:" + ex.Message);
					}

					Console.WriteLine("End Processing");
					Console.ReadKey();
				}
				static string CallService(string strRequest, string ServiceUrl)
				{

					byte[] byteArray = Encoding.UTF8.GetBytes(strRequest);
					HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(ServiceUrl);
					httpRequest.Credentials = CredentialCache.DefaultCredentials;
					httpRequest.Method = "POST";
					httpRequest.ContentType = "application/json";
					httpRequest.ContentLength = byteArray.Length;
					httpRequest.Timeout = 300000;
					Stream dataStream = httpRequest.GetRequestStream();
					dataStream.Write(byteArray, 0, byteArray.Length);
					dataStream.Close();

					HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
					StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.UTF8);
					string jsonData = streamReader.ReadToEnd();
					return jsonData;
				}

			}
		}

Workflow API Code - Python

import requests
		import json

		# service url- provided by Enrich.io
		url="http://api.enrich.io/enrichapi/v2/enrichment"

		headers = {'content-type': 'application/json'}

		requestBody = """{ "\"userkey\" : \"Your User Key\", \"subuserkey\" : \"Your Sub User Key\", \"workflowcode\" : \"Your Created Workflow Code\", \"customvalues\" : {\"value\" : \"Your Custom Values\"}, \"params\" : {\"parameter\" : \"parameter value\" }}""";
		response = requests.post(url,data=requestBody,headers=headers)
		resp =json.loads(response.text)
		print (resp)

Workflow API Code - PHP

import requests
		import json

		# service url- provided by Enrich.io
		url="http://api.enrich.io/enrichapi/v2/enrichment"

		requestBody = "{ "\"userkey\" : \"Your User Key\", \"subuserkey\" : \"Your Sub User Key\", \"workflowcode\" : \"Your Created Workflow Code\", \"customvalues\" : {\"value\" : \"Your Custom Values\"}, \"params\" : {\"parameter\" : \"parameter value\" }}";

		headers = {'content-type': 'application/json'}
		response = requests.post(url,data=requestBody,headers=headers)
		resp =json.loads(response.text)
		print (resp)