• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using XML and cfhttp ???

Community Beginner ,
Jun 28, 2019 Jun 28, 2019

Copy link to clipboard

Copied

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?

TOPICS
Advanced techniques

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 30, 2019 Jun 30, 2019

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 kic

...

Votes

Translate

Translate
Community Expert ,
Jun 28, 2019 Jun 28, 2019

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 28, 2019 Jun 28, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2019 Jun 29, 2019

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2019 Jun 29, 2019

Copy link to clipboard

Copied

BKBK, can you tell us where you found that need (of the other headers)? I had looked and the reference I shared indicated that it was just a REST (http) call with seeming nothing else needed. Since i didn't have an account, I couldn't confirm. I was hoping the op would.

And to coder1957**, when you ask , "In 3, What do I dump to view the result I get back?", I don't understand. My point 3 suggested you merely run the URL in your browser, so nothing to dump. Just tell us what you SEE. If you want, you can do a view source in the browser.

But really, to all that I shared, that's your only reply? I suggested and asked you to try so much more.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 29, 2019 Jun 29, 2019

Copy link to clipboard

Copied

I have tried working on this and so far:

The returntype has to be a struct. Or I get errors.

In BK's example, the return from the cfhttp is contained in

apiResult

so based on verify-mail's web site directions :

Example:

The code bellow already contains your API Token so you can use it as it is (I have removed)

https://app.verify-email.org/api/v1/KEY/verify/support@verify-email.org

cURL (example)

curl -X GET "https://app.verify-email.org/api/v1/KEY/verify/support@verify-email.org"

JSON encoded response

{ "email": "support@verify-email.org", "status": 1, "status_description": "OK email", "smtp_code": 250, "smtp_log": "250 2.1.5 OK u8-v6si8965853qvh.5 - gsmtp\r\n" }

I expected to be able to read the status as

apiResult.status

but when I dumped that I got a no such value.

so at this stage I am lost. What am I missing?

I get 30 credits with a new account as so far, even though I have "issued" a dozen polls, I still have 30 credits left.

So it's not a credit unavailable error.

I originally used this to test for an emails syntax validity.  Maybe I can use a simpler approach and simply test the email for valid characters? This seems more thorough?

Never researched that.

So my code right now is:

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

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

<cfset var urlString='https://app.verify-email.org/api/v1/mykey/verify/#arguments.email#'>

<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>

<cfquery datasource="#application.dsn#">          dumps the value into a table used for said purpose

          insert into ajaxnotes       

          (note)       

          values('email:#apiResult.email#')       

</cfquery>

<cfreturn apiResult>

</cffunction>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

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

BKBK, can you tell us where you found that need (of the other headers)?

I found the information by registering on the website https://verify-email.org/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

Second thoughts.

coder1957**​, the code I gave contains the following line

<cfset var apiResult={}>

This line applies only to new ColdFusion versions. Should there be any trouble with it, replace it with

<cfset var apiResult=structNew()>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

I did that ... changed it to <cfset var apiResult=structNew()> and same result SMTP_CODE undefined in APIRESULT

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

That error shows that the call has worked! As SMTP_CODE is a key of the CFHTTP result, the error suggests you have to do validation somewhere, following the CFHTTP call.

Run the code I have given, separately as a CFM page. That is probable the best way to test it.

It works! Here is the result I get when I run it as a CFM page:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

Wish it were for me ...

My code in a standalone cfm

<cfset urlString='https://app.verify-email.org/api/v1/mykey/verify/test@aol.com//app.verify-email.org/api/v1/mykey/verify/test@aol.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#">

I get a table that says Connection Failure

struct
Charset[empty string]
ErrorDetailI/O Exception: sun.security.validator.ValidatorException: PKIX path building failed: java.security.cert.CertPathBuilderException: Could not build a validated path.
FilecontentConnection Failure
Header[empty string]
MimetypeUnable to determine MIME type of file.
Responseheader
struct [empty]
StatuscodeConnection Failure. Status code unavailable.
TextYES

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

UrlString is wrong, contains a duplicate.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

That's a copy and paste error.

It is correct

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

I ran your exact code, with the exception of using my own key.

It worked.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

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#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

Regarding certificates ... that's above my paygrade. 

How do I workaround that?  You suggest " import the certificate of the site"?

Say what?

Then do what with it?

Et-CETERA?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

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-javasecuritycertcertpathbuilde...

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

CF11 would be the latest update.

To be candid I cannot tell suddenly.

I rebooted my laptop today and when I tried to RDP into that server I got an error that there are no remote client accesses on the server.  Even though it's been working fine for years.

I would be happy to upgrade to cf18 but I am locked out til Monday.

Going to take a brake! And a break ...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

coder1957** wrote

CF11 would be the latest update.

To be candid I cannot tell suddenly.

The latest is ColdFusion 11 Update 19. The update level is relevant to the error you're getting. That is because the updates include a change in the Java version.

It may be no consolation, but it usually helps to know you're not alone. Go to the online ColdFusion demo site https://trycf.com/

Click on the engine symbol below, on the right-hand side. Select ColdFusion 11.

Next, enter your standalone CFM code and click on Run Code.

Your will see that the result is exactly the error you got.

coder1957**  wrote

I would be happy to upgrade to cf18 but I am locked out til Monday.

CF18 is a great thought to close with.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

Oh, this gives you the ColdFusion Update level and more besides:

<cfdump var="#server#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

I do have a server running CF18 but it's not ready for the latest version of code. 

But I copied the test file over to it, ran it, and sure enough I got the result you got!

So I'll put this micro project on the back burner until we graduate the pre-production server to CF18.

Too many servers!

Thanks one and all!  But especially to BKBK!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

No worries, coder1957**​.

Please mark this thread as answered. You will, in so doing, help someone else having the same problem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

The error you got,

ErrorDetail I/O Exception: sun.security.validator.ValidatorException: PKIX path building failed: java.security.cert.CertPathBuilderException: Could not build a validated path.

suggests you might need to import the certificate of the site https://verify-email.org

Alexander Hass's blog contains helpful suggestions on the subject: https://www.hass.de/content/coldfusion-java-pkix-path-building-failed-javasecuritycertcertpathbuilde...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2019 Jun 30, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation