I am trying to complete a DELETE request using SSJS on a landing page, using API mocking tools (beeceptor.com) I'm able to fake the API calls to see how the page reacts.
Calling the DELETE request, the resource will either return a 204 or a 404 response code, and nothing in the body.
When a 204 is returned the cost works without issues, when a 404 is returned I get the following error:
System.Collections.Generic.Dictionary`2[System.String,System.Object]
Here is my code:
<script runat=server language="javascript">
Platform.Load("Core", "1");
var DELETE_URL = "https://delete-api.free.beeceptor.com";
try {
var payload = {};
payload.url = 'http://site.com/image.jpg';
var req = new Script.Util.HttpRequest(DELETE_URL);
req.emptyContentHandling = 0;
req.retries = 2;
req.continueOnError = false;
req.contentType = "application/json";
req.setHeader('Authorization', 'App api-key-goes-here');
req.postData = Stringify(payload);
req.method = "DELETE";
var resp = req.send();
Write(resp);
} catch (e) {
Write(e);
}
</script>