Skip to main content

Notifications

Small and medium business | Business Central, N...
Unanswered

Web Services from Code units: Tailor responses and status codes

Posted on by 21
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
  • gdrenteria Profile Picture
    gdrenteria 11,265 Most Valuable Professional on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,902 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,336 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans