Create Wufoo webhook with PUT request in ColdFusion

[亡魂溺海] 提交于 2019-12-11 07:31:47

问题


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.


回答1:


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



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3980064/create-wufoo-webhook-with-put-request-in-coldfusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!