Skip to main content

Notifications

Announcements

No record found.

Dynamics Business Central migration forum
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
Categories:
  • gdrenteria Profile Picture
    gdrenteria 9,472 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans