API - Change Response from server


I have looked at a similar titled post at Format server response on API call but it didn’t have the answers I was looking for.

I am creating an API on the KNIME server that will be called from different programs around my company e.g KNIME flow, a C# App, an Python App etc. One of the first thing I do is validate the input JSON which could look like this:

      "ReferenceNumber": "123456";
      "Name":"Joe Blogs"
      "stuff": "to be or not to be",
      "morestuff": "that is the question"
      "evenmorestuff":"whether 'tis nobler in the mind"

If the ReferenceNumber is invalid I would like to send a response back a 411 status code with an error message of “ReferenceNumber is not valid”

If “otherData” is missing I would like to send a response back a 412 status code with an error message of “otherData is missing”

If the internal flow workings on the API fail (for example in a try catch) I would like to send a response back with a 500 number and a message.

Also I would like to strip out most, if not all, of the standard response body. example of the first part below

Is this possible?


Hi Frank,

I’m afraid it isn’t possible to change or extend the response codes of our rest interface. However, you can influence the data a called workflow returns. Checkout our Workflow Invocation Guide, especially the external clients section: KNIME Workflow Invocation Guide

Kind regards

Actually, it is possible by using the Container Output (Raw HTTP) and Container Input (Raw HTTP) nodes in combination with GET/POST …/rest/v4/repository/{path}:raw-execution.

Side note: you should not abuse existing HTTP status codes. For example 411 means "Length required " and 412 is for “Precondition failed”. Both do have semantic meanings which don’t match your purpose.
Usually if the input sent by the client is not correct you either return a generic 400 or 422 (Unprocessable Content).


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.