The CreatorCon Call for Content is officially open! Get started here.

Does RESTMessageV2's setRequestBody() work for DELETE method?

Robert Beeman
Kilo Sage

I was able to successfully access DocuSign's REST API from Chrome Web Apps (Postman and Advanced Rest Client) without issue. I am now trying to migrate that to ServiceNow for an integration. From SN, I'm able to access their login_information endpoint with a GET method, the same as I can with the Chrome apps.

I run into a problem when I try access their users endpoint using the DELETE method (DocuSign). It requires that you pass the user to be deleted as the payload in the body content. I'm trying to use .setRequestBody() with the same stringified JSON that I'm using in the Chrome web apps, but I get this error:

find_real_file.png

When I was reading the wiki (http://wiki.servicenow.com/index.php?title=RESTMessageV2_API#setRequestBody.28String_body.29 ), it specifically mentions that it works for PUT and POST. Does that mean that it does not work for DELETE? I've also noticed that the content variable is hidden via UI Policy on Outbound REST Message records for GET and DELETE methods.

find_real_file.png

If this is the case, are there any workarounds/alternatives?

6 REPLIES 6

phoenix516
Tera Contributor

I submitted an enhancement request for this here. Pleas up-vote.

benlittle
Tera Expert

There are a couple of things we tried, specifically with Everbridge, which only accepts Content Body blocks with one of their REST DELETE functions.

 

The first is to create a custom activity with powershell. We were able to use the Invoke-RestMethod command to force a body with a DELETE method. Something like this:

$user = "user"
$pass = "password"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$pass)))

$params = @{
    Uri               = 'https://api.everbridge.net/rest/groups/${activityInput.Organization_ID}...
    Headers       = @{ 'Authorization' = "Basic $base64AuthInfo" }
    Method        = 'DELETE'
    Body            = '["${activityInput.User_ID}"]'
    ContentType = 'application/json'
}

$result = Invoke-RestMethod @params 

 

A second option upi can try is to see if you can pass an “override” function in via HTTP headers. This really depends on the incoming REST interpreter on the destination. Service-now can send what appears to be a POST (which can happily contain a contact block), but uses a specific industry-defined header to override:

Header is “X-HTTP-Method-Override” set to “DELETE”

Example shown on this web page: http://sncommander.com/how-to-send-rest-data-using-the-patch-method-from-servicenow-2/ (It specifically is for PATCH, but might work for DELETE. I have not been able to try it directly)