0

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>
1

A 404 is an error and frequently returns no response payload. Set emptyContentHandling and continueOnError to true and then inspect the response using its statusCode, returnStatus, errorMessage and content properties.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.