I try to call a method in a custom API in a code unit in Ms Dynamics 365 Business Central. I tried everything to make it a simple GET method, but I keep receiving "BadRequest_MethodNotAllowed" in Postman.
The complete response:
{
"error": {
"code": "BadRequest_MethodNotAllowed",
"message": "'GET' requests on unbound actions are not allowed."
}
}
When I call the method with a POST request (in Postman), it works as expected. To me it seems absurd the caller of my API need to use POST when het wants to GET some data from my API. This is of course also against official guide lines and conventions. Am I missing something? Please some advice. Thank you.
based on what you mentioned you are using the Bound Actions. Both Unbound and Bound Actions use only the HttpMethod POST. SOAP was widely used before Business Central. In practice every SOAP web service is called by POST. There is also no other way around it for the Actions you are using. It's like RPC.
If you have control of the object, rename your procedures so that they tell you what you are trying to achieve, e. g. postInvoice, sendEmail, getInformation, etc.
So, no, you're not missing something. It's just the way it worked in the old days. Give it a little more time. Business Central is about 6 years old. Much has changed since then, and much will change in the coming years. But we will always come across traces of the past. REST made its debut in the 2000s, so don't just call it absurd, our elders may have been working with older technology all their lives and they have managed to work with it.
Microsoft has announced that they will no longer support SOAP in Business Central in the future. ODataV4 is now the way to go.
TL;DR
Yes, it is like an RPC, use HttpMethod POST.
Resources: