web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

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

(2) ShareShare
ReportReport
Posted on by 16
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:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    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.
  • CU15021230-0 Profile Picture
    16 on at
    In D365F&O
  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    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.
  • Anthony Blake Profile Picture
    2,963 Super User 2025 Season 2 on at
    Hi,
     
    I've implemented this in projects previously using API Management as suggested by Martin, and can confirm it works great.
     
    Anthony

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 434 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans