Skip to main content
cherdt
Inspiring
April 2, 2013
Question

Does cfhttp include cfhttpparam elements for delete method requests?

  • April 2, 2013
  • 3 replies
  • 3850 views

I'm using the Canvas LMS API to attempt to delete user enrollments (see https://canvas.instructure.com/doc/api/enrollments.html#method.enrollments_api.destroy).

Here's my CF code:

<cfhttp url="#uri#" result="result" method="delete">

<cfhttpparam type="header" name="Authorization" value="Bearer #access_token#" />

<cfhttpparam type="formfield" name="task" value="delete" />

</cfhttp>

It appears as though the task form field is not making it through, as the server instead concludes the course enrollment (presumably the API default--I've contact the vendor to verify).

However, the following cURL request is successful:

curl <same uri as above> -H 'Authorization: Bearer <same access token as above' -X DELETE -F 'task=delete'

I'm hoping that a second pair of eyes will spot an error in my cfhttp request, but I'm guessing that ColdFusion does not include the formfield data if the method is set to delete? (The cfhttpparam docs do state "The formField type attribute is only meaningful with the cfhttp tag POST and GET methods".) In which case, any way around this issue?

This topic has been closed for replies.

3 replies

cherdt
cherdtAuthor
Inspiring
April 24, 2013

FYI, I filed a bug report with Adobe for this issue:

https://bugbase.adobe.com/index.cfm?event=bug&id=3537036

cherdt
cherdtAuthor
Inspiring
April 24, 2013

There is a better workaround! I found this StackOverflow thread:

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

ColdFusion will still send the request body with PUT and DELETE requests, so we can format the request body as a form field (or series of form fields).

<cfhttp url="#uri#" result="result" method="delete">

  <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded; charset=UTF-8" />

  <cfhttpparam type="body" value="FormFieldKey=#UrlEncode(FormFieldValue)#" />

</cfhttp>

cherdt
cherdtAuthor
Inspiring
April 4, 2013

I found this workaround using Java classes (also with the help of the createByteArray UDF):

<cfset javaUrl = CreateObject( "java", "java.net.URL" ).Init(deleteUri) />

<cfset connection = javaUrl.openConnection()>

<cfset connection.setRequestMethod("DELETE")>

<cfset connection.setRequestProperty("Authorization","Bearer #access_token#")>

<cfset connection.setRequestProperty("Content-Length", "11")>

<cfset connection.setDoOutput(true)>

<cfset outputStream = connection.getOutputStream()>

<cfset outputStream.write(createByteArray("task=delete"))>

<cfset outputStream.flush()>

<cfset outputStream.close()>

<cfset ch = connection.getContent().read()> <!--- read first byte of the response, which seems to help? --->

<cfset responseCode = connection.getResponseCode()>

<cfset connection.disconnect()>

Seems like an ugly workaround to what should be a straightforward REST API call. Let me know if anyone has a better alternative!