Forum Discussion

4 Replies

  • I'm not entirely sure it's possible to change the status code to something other than 200, but what I do to still report any unsuccessful outcomes in my custom endpoints is to define "status" and "message" values (similar to v2 responses) and return them in JSON format.  Then I just use FreeMarker (or Python or whatever if not directly within Khoros) to parse the JSON response.

    For example:

     

    <@compress>
    <#-- Define default variables -->
    <#assign status = "error" />
    <#assign message = "" />
    
    <#attempt>
      <#-- Perform my endpoint operations -->
      <#assign status = "success" />
      <#assign message = "Operation completed successfully" />
    <#recover>
      <#assign message = .error?json_string />
    </#attempt>
    
    <#-- Define the JSON data to return -->
    </@compress>
    {
      "status": "${status}",
      "message": "${message}"
    }

     

    Hope this helps!