API Management Gotcha – Empty Body Definition

A while ago I saw a question in the forums where someone was trying to use a POST operation using the API Management action in Logic Apps and the action card didn’t have any way to input the body object.

To replicate the issue I’ve create a very simple logic app, so simple in fact that I didn’t even bother to define a trigger schema. After creating a new API using that logic app, to my surprise I also couldn’t find any input for the message body.After scratching my head a bit and sending a couple of emails, Jon Fancey pointed me out to the right direction by asking if the API was created from a logic app that didn’t have a trigger schema. So that was the culprit…

And indeed, looking at the Swagger generated by APIM, the definition for the body of the operation was set as empty.

Luckily, the fix for that was as simple as manually updating the swagger definition of the operation (which is made simple in the API Management blade within the Azure Portal). To access the definition, I had to connect to my API, select all operations, and edit the front end.

changing the Azure Swagger definition.That took me to the OpenAPI specification area, where I could manually update the API definition:

OpenAPI ScreenScrolling down to the definition of request-manual, I just needed to change it to:

This gave me the required result. Now the action card renders as expected:

Manual invoke with input area for body part.Playing with the definition a bit more, I found that “strong-typing” request-manual with some well defined properties, is reflected in the action card. For example, this definition:

Generates this action card:

That was fun and all, but it would be avoided if I only had bothered to define the schema of the manual trigger. On the other hand, I think that API Management could be user friendly enough to include the solo “object” for definitions for empty objects…

#notetoself: To avoid this trouble, I just need to make sure I define the schema of a manual trigger when I create a new logic app. I found that if I provide an empty json – like {} – to the sample message, a new schema of type object will be created, so at minimum I can do that.

BTW, making sure that you have a schema defined, will also help you when trying to call a logic app from another.

I hope you enjoyed. See you next time.

Leave a Reply

Your email address will not be published. Required fields are marked *