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

Does cfhttp include cfhttpparam elements for delete method requests?

Participant ,
Apr 02, 2013 Apr 02, 2013

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?

3.8K
Translate
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
Participant ,
Apr 03, 2013 Apr 03, 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!

Translate
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
Participant ,
Apr 24, 2013 Apr 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>

Translate
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
Participant ,
Apr 24, 2013 Apr 24, 2013
LATEST

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

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

Translate
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