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:
  • Anthony Blake Profile Picture
    2,359 Super User 2025 Season 1 on at
    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
    233,013 Most Valuable Professional on at
    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
    16 on at
    How to build custom service that return bad request if it's not success
    In D365F&O
  • Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March 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... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,013 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans