Skip to main content
Known Participant
June 28, 2019
Answered

Using XML and cfhttp ???

  • June 28, 2019
  • 2 replies
  • 3149 views

Refer:  https://verify-email.org/home/api

I want to use their API to get a result back to see if an email address is valid.

So based on their documentation, I guess I do (something like) the following?

<cffunction name="email_verify"  access="remote" returntype="string">

            <cfargument name="email" type="string" required="true">

            <cfoutput><cfhttp url="https://app.verify-email.org/api/v1/my key/verify/#arguments.email#"        result="variables.resultxml" /></cfoutput>

<cfset variables.parsed_result = xmlParse(variables.resultxml.fileContent)> 

<cfreturn variables.parsed_result>

</cffunction>

The above syntax is obviously wrong as I am getting a console error An error occurred while parsing an XML document.

What am I doing wrong?

(I tried without the <cfoutput> with same result.  Not sure if I need them in there?

This topic has been closed for replies.
Correct answer BKBK

I'm JEALOUS!!!  Not fair!!!

You ran this and it worked?  I have ONLY edited out the key. And no that's not my email.

So what the blank are we doing differently?  CF11, Windows Server???, IIS, I have run it from both localhost here in Europe AND from within my firewalled subnet at the data center in the US.   

<cfset urlString='https://app.verify-email.org/api/v1/mykey/verify/badboy@gmail.com//app.verify-email.org/api/v1/mykey/verify/badboy@gmail.com'>

<cfset apiResult=structNew()>

<cfhttp method="get" url="#urlString#" result="apiResult">

<cfhttpparam type="header" name="Content-Type" value="application/json ">

<cfhttpparam type="Header" name="Accept" value="application/json ">

</cfhttp>

<cfdump var="#apiResult#">


coder1957**  wrote

You ran this and it worked?  I have ONLY edited out the key. And no that's not my email.

So what the blank are we doing differently?  CF11, Windows Server???,

CF11, that's the difference. I am on ColdFusion 2018 Update 3.

My guess is that the error you are getting is caused by the Java engine on which your CF11 runs.

What is the update level of your CF11 installation? What is your Java version? Are you in a position to switch to a newer java version, should need be?

Oh, don't kick yourself. The error is well-known.

https://forums.adobe.com/thread/2209768

https://www.hass.de/content/coldfusion-java-pkix-path-building-failed-javasecuritycertcertpathbuilderexception-could-not

https://www.processio.com/adding-lets-encrypt-trust-certificates-cold-fusion/

2 replies

Charlie Arehart
Community Expert
Community Expert
June 30, 2019

Taking a break sounds good. As for your problem, I recommend you not import certs but instead  simply update Java. See why and how here::

Error: Calling out of CF via https, solved by updating JVM

BKBK, I realize you suggested that as a second possibility. I hope you'll read the post and consider proposing it first going forward. You'll see it's as if I wrote it EXACTLY as if a reply to your suggestion here (and 1957's being on cf11), though it applies still more broadly and was written a few weeks ago.

Finally to you both, I would repeat that my first comment would have told you this was the problem. You both jumped forward to optimizing the code (talking about where and where not to parse the result, whether to do as a cfc or cfm). It was too soon to be worried about that, I would say.

Had you just dumped the cfhttp filecontent you would have seen this was the issue from the first, and then once solved you'd have seen it was json. Then you could tweak and optimize.

We're all here trying to help, so no offense intended.

/Charlie (troubleshooter, carehart. org)
BKBK
Community Expert
Community Expert
June 30, 2019

https://forums.adobe.com/people/Charlie+Arehart  wrote

As for your problem, I recommend you not import certs but instead  simply update Java. See why and how here::

Error: Calling out of CF via https, solved by updating JVM

BKBK, I realize you suggested that as a second possibility. I hope you'll read the post and consider proposing it first going forward. You'll see it's as if I wrote it EXACTLY as if a reply to your suggestion here (and 1957's being on cf11), though it applies still more broadly and was written a few weeks ago.

Agreed. Nevertheless, I do believe that updating ColdFusion 11 to the latest version is the more fundamental change. Such a change includes updating to a higher JVM.


Finally to you both, I would repeat that my first comment would have told you this was the problem. You both jumped forward to optimizing the code (talking about where and where not to parse the result, whether to do as a cfc or cfm). It was too soon to be worried about that, I would say.

What you call the problem did actually change. "An error occurred while parsing an XML document." suggests, as you rightly say, a problem with the HTTP result. Later, the problem turned out to be about Java certificates.

The code was not optimized. It was pared down to a CFM, consisting of a simple HTTP call, as recommended by the API publisher.

Had you just dumped the cfhttp filecontent you would have seen this was the issue from the first, and then once solved you'd have seen it was json. Then you could tweak and optimize.

We found the content-type of an API response from the documentation of the API's publisher. In my opinion, that is a better source of information than cfhttp.filecontent. The latter may give you XML or JSON, depending on the nature of your call.

We're all here trying to help, so no offense intended.

None taken.

Charlie Arehart
Community Expert
Community Expert
June 30, 2019

I have to say I disagree with each of your conclusions in reply to my last comment, BKBK. But I will leave it at that and for others to judge who  may read the thread and for time to tell, rather than drag things out.

The good news is that the OP's problem is solved, and we each helped him in our own ways, with each being valuable from different perspectives. That said, it will be a challenge for him to identify any one reply as the "answer", as there were indeed multiple issues identified through multiple answers.

/Charlie (troubleshooter, carehart. org)
Charlie Arehart
Community Expert
Community Expert
June 29, 2019

Well, you’ve got a few issues I see, but we should be able to resolve them.

1) First, to debug this problem, start a LOT more slowly and build your way up. For instance, just do:

What do you get? Maybe it’s not XML. Modern services tend to return json instead. If that’s the issue, then that’s why you can’t pass it to xmlparse. You may want to use deseralizejson instead, to get to what is within the json.

I will say that if we visit the URL you offered (with literally /my key/) in the CFHTTP URL, and passing in a valid email address, we DO get back a “user not found” error, AS JSON.

2) As we look at that service, and its FAQ page: https://verify-email.org/faq.html, it shows that the form you’re supposed to pass in is simply this:

https://app.verify-email.org/api/v1//verify/

So you are indeed supposed to pass in some key. Perhaps you were doing that. What’s not clear from that page if is whether you are supposed to include the braces ({}) or not. I notice that you do not, in your example:

https://app.verify-email.org/api/v1/my key/verify/#arguments.email#

3) So what do you see in your browser when you use that URL and pass in your real key, and a real email address? Again, if it’s a valid json result, that’s your problem. You need to use deserializejson, not xmlparse.

4) Finally, no, you do NOT need (and should not put) the cfoutput around the cfhttp.

Let us know how it goes.

/charlie

/Charlie (troubleshooter, carehart. org)
Known Participant
June 29, 2019

In 3, What do I dump to view the result I get back?

BKBK
Community Expert
Community Expert
June 29, 2019

coder1957**

The API service provider says you should include 2 headers in your calls. Content-Type and Accept. The HTTP get method is also a requirement. So I would specify that, too, instead of assuming it would b used by default.

The following should work:

<cffunction name="email_verify"  access="remote" returntype="Struct">

<cfargument name="apiUrl" type="string" required="true">

<cfargument name="apiKey" type="string" required="true">

<cfargument name="email" type="string" required="true">

<cfset var urlString=arguments.apiUrl & arguments.apiKey & "/verify/" & arguments.email>

<cfset var apiResult={}>

<cfhttp method="get" url="#urlString#" result="apiResult">

<cfhttpparam type="header" name="Content-Type" value="application/json ">

<cfhttpparam type="Header" name="Accept" value="application/json ">

</cfhttp>

<cfreturn apiResult>

</cffunction>

<cfscript>

// test-code on the page that calls the API

testApiUrl="https://app.verify-email.org/api/v1/";

testApiKey="STTRrM0IIhLxxxxxxxxxxxxxxxxxxxxxv0caP5i1ZRsGv";

testEmail="firstName.lastName@myDomain.com";

// a struct

emailVerificationResult=email_verify(testApiUrl, testApiKey, testEmail);

writeDump(var=emailVerificationResult, label="CFHTTP Result");

// (Extracting the content should NOT be the responsibility

// of the function email_verify. It should be that of the caller.

// Re: SOLID, GRASP principles)

emailVerificationContent=emailVerificationResult.filecontent;

// filecontent is also a struct

writeDump(var=emailVerificationContent);

</cfscript>