Hello, I am working on a code unit I have exposed as a web service.
I was able to successfully publish the and expose the codeunit from the Web Services on the page. However, I am struggling with the following:
Passing specific status codes rather than the default 200 OK e.g. 403 forbidden.
Formatting the Value of the return payload to a JSON object or Array rather than a JSON string.
Currently, regardless of the procedure being successful or not, when the web service is consumed, it'll return a 200 ok status code. I'd want the flexibility to return different status codes dependent on the functions called.
Let's say we fail to find a use or some data within a payload is invalid. Hence, rather than returning a 200 OK, it would return a 400 status code. A screen shot of the specific issue I am talking about is below:
A service fails to create a User, but the status code is a 200 OK.
Additionally, the value part of the response body is a JSON string rather than a JSON object or array. How can I change my published code unit as web service to implement the above two features?
Any tips or pointers is greatly appreciated