Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<!DOCTYPE html>
IF RequestParameter("submitted") == "submitted" Then
VAR @httppost,@apiid,@apistatusCode,@apiresponse,@apitoken
SET @apiid = '{"client_id": "client_id","client_secret": "client_secret", "grant_type": "client_credentials","account_id": "MID"}' /* Forming up the string for getting the access token */
SET @httppost = HTTPPost2("","application/json",@apiid,true,@apiresponse,@responseRows) /* Making a POST call to get access token */
IF(@httppost == "200") Then /* If status is Sucess */
set @rows = BuildRowsetFromString(@apiresponse,'"') /* Split the rows based on '"' string */
set @rowCount = rowCount(@rows)
if @rowCount > 0 then
for @i = 1 to @rowCount do
var @apitoken
set @row = row(@rows,4) /* 4th row is where we can get the access token */
set @apitoken = field(@row,1)
next @i
Set @Email = RequestParameter("Email") /* Get the email from the form */
SET @url = "" /* 2nd POST URL */
SET @content = concat('{"email":"',@Email,'","validators":["SyntaxValidator","MXValidator", "ListDetectiveValidator"]}')
SET @finalStatuscode = HTTPPOST2(@url,"application/json",@content,true,@output,@respheader, 'Authorization', CONCAT('Bearer ',@apitoken)) /* Framing up the body */
IF(@httppost == "200") Then
set @outputrows = BuildRowsetFromString(@output,':') /* Split the rows based on ":" string */
set @outputrowCount = rowCount(@outputrows)
if @outputrowCount > 0 then
for @i = 1 to @outputrowCount do
var @status
set @outputrow = row(@outputrows,3) /* You will get True or False value on 3rd row */
set @status = field(@outputrow,1)
next @i
if IndexOf(@status,"True") > 0 then /* Check if the string is having True */
Set @finaloutput = "Valid email address"
set @finaloutput = "In-Valid email address"
output('Error') /* If response is not 200 (success) then return error */
output('Error') /* If response does not have any value then return Error */
output('Error') /* If response is not sucess then return Error */
API Token - %%=v(@apitoken)=%% <br><br><br>
API Status Code - %%=v(@httppost)=%%<br><br><br>
API Response - %%=v(@apiresponse)=%%<br><br><br>
API Response Rows - %%=v(@responseRows)=%%<br><br><br>
Final Status Code- %%=v(@finalStatuscode)=%% <br><br><br>
Final Output status - %%=v(@output)=%%<br><br><br>
Final Output - %%=v(@finaloutput)=%%<br><br><br>
<form action="%%=RequestParameter('PAGEURL')=%%">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value=""><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value=""><br>
<label for="email">Email Address:</label><br>
<input type="email" id="email" name="email" value=""><br><br>
<input id="submitted" name="submitted" type="hidden" value="submitted">
<input type="submit" value="Submit">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment