Adventures with Azure API Management: Add JSON Property in Set-Body

API Management

I have a policy on all my operations in Azure API Management to validate a JWT Token and extract the sub Claim, which I store in a userId variable that can be used in other policies.

Policy for All API Operations

I have an operation called Organization Add that calls an Azure Function to add an organization to the database.

The Azure Function expects a value for userId in the body.

My policy for the Organization Add operation needs to add the userId to the body.

To do this I convert the incoming message body to a JObject and then add the property and assign it the value of the userId variable.

Organization Add Policy

I tried, unsuccessfully, to use the variable inline using Liquid templates.

Took some time, but finally figured out how to do it thanks to this question posted on the Microsoft forums

Hope this saves a fellow developer some time!

Leave a Reply

Your email address will not be published.