Skip to main content
Post a question

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id : oPF/KQO9IRu6cVdgcS3RT1
Finance | Project Operations, Human Resources, ...
Suggested answer

How to build custom service that return bad request if it's not success

Like (2) ShareShare
ReportReport
Posted on 14 Mar 2025 19:22:41 by 8
I build custom service that handle the response if it's valid or not using json object but I can't set status code to 400 if it's not valid as a bad request how can I solve it ??
Categories:
  • Anthony Blake Profile Picture
    2,331 Super User 2025 Season 1 on 16 Mar 2025 at 12:39:48
    How to build custom service that return bad request if it's not success
    Hi,
     
    I've implemented this in projects previously using API Management as suggested by Martin, and can confirm it works great.
     
    Anthony
  • Suggested answer
    Martin Dráb Profile Picture
    231,793 Most Valuable Professional on 16 Mar 2025 at 06:30:03
    How to build custom service that return bad request if it's not success
    Moved from Integration, Dataverse, and general topics forum.
     
    When you're developing a custom service, you don't directly control HTTP status codes. The operation can either end successfully (returning 200) or throw an exception (returning 500, I believe). That's it. (Of course, F&O can return other status code if can't call you operation at all, such as 403.)
     
    What you could do is calling your custom service through an Azure API Management (or something similar), where you'll analyze the response and return 400 if your criteria are met. For example, your custom service could return a response (200) with a data contract object saying in a status field that it's a failed validation. In API management, you'll check the response and if the status field indicates a validation failure, you'll change the HTTP status code to 400. Or you could throw an exception and analyze the error message in API Management.
  • CU15021230-0 Profile Picture
    8 on 15 Mar 2025 at 17:21:08
    How to build custom service that return bad request if it's not success
    In D365F&O
  • Martin Dráb Profile Picture
    231,793 Most Valuable Professional on 15 Mar 2025 at 05:07:48
    How to build custom service that return bad request if it's not success
    Which D365 product are you using? The D365 brand covers quite a few things, such as Finance and Operations, Business Central or Customer Engagement. There are custom services in F&O, but maybe another D365 product has a feature of the same name.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,927 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,793 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans
Loading complete