English 中文(简体)
Create Wufoo webhook with PUT request in ColdFusion
原标题:

I m having troubles with building correct PUT request to the Wufoo.

In all my attempts I see the same error:

404 A WebHook must contain a url parameter.

Here is the version with JSON data type:

<cfset local.action = "forms/#local.formHash#/webhooks.json" />

<cfset local.request = {"url" : local.webHookURL, "handshakeKey" : local.webHookKey} />

<cfset local.request["handshakeKey"] = local.webHookKey />

<cfhttp url="#local.baseURL##local.action#" method="put" username="#local.apiKey#" password="#local.apiPass#">
    <cfhttpparam type="header" name="Content-Type" value="application/json; charset=UTF-8" />
    <cfhttpparam type="body" value="#SerializeJSON(local.request)#" />
</cfhttp>

Same failure when using file:

<cfset local.action = "forms/#local.formHash#/webhooks.json" />

<cfset local.request = {"url" : local.webHookURL, "handshakeKey" : local.webHookKey} />

<cffile action="write" file="#GetTempDirectory()#webhook.json" output="#SerializeJSON(local.request)#">

<cfhttp url="#local.baseURL##local.action#" method="put" username="#local.apiKey#" password="#local.apiPass#">
    <cfhttpparam type="header" name="Content-Type" value="application/json; charset=UTF-8" />
    <cfhttpparam type="file" mimetype="application/json" name="json" file="#GetTempDirectory()#webhook.json" />
</cfhttp>

UPDATE:

To make the code working in ACF (my code works in Railo only) use this syntax for request:

<cfset local.request = {} />
<cfset local.request["url"] = local.webHookURL />
<cfset local.request["handshakeKey"] = local.webHookKey />

Both methods should produce same JSON with case-sensitive keys.


Also I ve tried the XML data type:

<cfset local.action = "forms/#local.formHash#/webhooks.xml" />

<cfsavecontent variable="putXML">
<cfoutput>
<?xml version="1.0" encoding="UTF-8"?>
<WebHookPutRequest>
<url>#XMLFormat(local.webHookURL)#</url>
<handshakeKey>#XMLFormat(local.webHookKey)#</handshakeKey>
</WebHookPutRequest>
</cfoutput>
</cfsavecontent>

<cffile action="write" file="#GetTempDirectory()#webhook.xml" output="#Trim(putXML)#">

<cfhttp url="#local.baseURL##local.action#" method="put" username="#local.apiKey#" password="#local.apiPass#">
    <cfhttpparam type="header" name="Content-Type" value="application/xml; charset=UTF-8" />
    <cfhttpparam type="body" value="#putXML#" />
</cfhttp>

Here I m not sure if my XML is correct, though for JSON everything should be fine.

Any ideas what s wrong with my code?

Thanks in advance.

最佳回答

Wufoo asks for the parameters to be "be passed as post parameters to the Web Hook API". Try using the application/x-www-form-urlencoded encoding for the body of the request. In ColdFusion, you can do this with <cfhttpparam type="FormField" />.

<cfhttpparam type="FormField" name="url" value="#local.webHookURL#" />
<cfhttpparam type="FormField" name="handshakeKey" value="#local.webHookKey#" />

However, ColdFusion rejects this technique with PUT methods. You can encode the body yourself using:

<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded; charset=UTF-8" />
<cfhttpparam type="body" value="url=#UrlEncode(local.webHookURL)#&handshakeKey=#UrlEncode(local.webHookKey)#" />
问题回答

In ColdFusion, generally, variable names are case-insensitive and uppercase.

<cfset local.request = {
  url = local.webHookURL,
  handshakeKey = local.webHookKey
} />

This gives you a struct with keys URL and HANDSHAKEKEY.

On the Web, presumably including with the Wufoo REST API, keys are case-sensitive. In this case, Wufoo accepts keys url, handshakeKey, and metadata - in that casing.

In ColdFusion, associative-array notation with struct puts (assignments) lets you keep the precise casing you want.

<cfset local.request = { } />
<cfset local.request["url"] = local.webHookURL />
<cfset local.request["handshakeKey"] = local.webHookKey />

This gives you a struct with keys url and handshakeKey.

Not familiar with this api but should the url, handshakekey, etc be form post params?

The following parameters must be passed as post parameters to the Web Hook API

url - this required parameter represents the URL on your server that the Web Hook will call when a new entry is submitted. We do validate the URL and reject malformed URLs.

handshakeKey - this optional parameter is described in the Web Hook integration getting started documentation.

metadata=true - this optional value parameter the Web Hook to send along form/field

The way I read that, it looks like they are asking for each of the params.

The error is suggesting it can t find the URL param, maybe that is it.





相关问题
JQuery AJAX .load - flash chart doesnt load in IE

An IE issue has me completely stumped. I have a coldfusion page that uses JQuery s AJAX .load function to load in a new flash file that is generated by coldFusion s cfchart tag. This works completely ...

Best Coldfusion Library for OpenID [closed]

I am getting ready to start a project that requires using OpenID within Coldfusion 8. I have found a number of different options and was wondering what has worked the best, get s the most support, ...

Find ColdFusion Generated ID

Is there a way to find the elements generated by ColdFusion s <CFLayout> and <CFLayoutArea> tags? These tags: <cflayout type="tab" name="MyAccount"> <cflayoutarea name="...

ColdFusion COM error

I am upgrading from CF4.5 to CF8. Calls to COM dll s that used to work in version 4.5 now throw a "Complex object types cannot be converted to simple values.." error. The COM object has a few arrays ...

What s the best way to write engine-specific CFML code?

Sometimes it is necessary to write different code for Adobe ColdFusion vs Railo vs OpenBD, due to differences in implementation. Do people have a specific method that they use for this? For example, ...

热门标签