Query Parameters vs Template Parameters Azure API Management - azure-api-management

In Azure API Management, what is the difference between template parameters and query parameters when setting up an API operations?

In Template Parameters, you can add Description, Type and default Values.
To retrieve the multiple template parameters of different context, you can use query parameters.
<set-query-parameter name="name" exists-action="override">
<value>#(context.Request.MatchedParameters["name"])</value>
</set-query-parameter>
Reference**:** https://www.linkedin.com/pulse/azure-api-management-use-template-parameters-set-query-anders-eide

Related

Azure Data Factory Webhook with JSON query as parameter

I've just created an ADF pipeline that allow me to refresh different partition of an Analysis Services Model (PBI XMLA) using a json script that I have to pass as parameter to my Webhook.
In the lookup I retrieve the partition to refresh and inside the for each I'm able to create the json query. Once I pass the query as RequestBody parameter when the webhook read it, it recognize also the callback uri as the RequestBody.
But when the Webhook run, this is the result: the RequestBody contains also the callbackUri passed from the ADF Pipeline.
$Query = $WebhookData.RequestBody
Write-Output "$Query"
How can I solve this issue?
Thank you!
If i use the Web Activity everything work in the right way since I haven't the callbackUri inside the body of my parameters.

Can I import required QueryString parameters as QueryString parameters rather than Template Parameters in APIM?

We are generating an OpenApi definition using Swagger/Swashbuckle. This definition is then imported into Azure API Management.
We have some querystring parameters on get requests that we have marked as required. Our validation ensures the querystring parameters are present and valid, otherwise we return a 400 Bad Request with details of which parameters are invalid/missing. The relevant part of the OpenAPI definition is below. Two querystring parameters (marked as required) and one path parameter (marked as required).
My problem is the way the OpenApi definition is converted into APIM operations.
The required querystring parameters are added as template parameters and they are added to the operation url. This means if they are not provided, APIM cannot match the request to an operation and we return a 404 to the caller rather than the helpful 400 that the backend would return.
I can't add easily add empty values into the querystring. I can't do that in the inbound policy of the operation as it doesn't match the operation. Doing it in the global inbound policy would mean I had to identify the operation myself (this is just one of many). Similarly, while I can return a 400 bad request in the onerror policy, I can't easily tell the caller what was wrong with the request.
I think it's built into the import process. When I changed the template parameters to query parameters in the portal and exported, the OpenApi definition was practically identical. When I reimported the exported template, the same thing happened. I also tried going via Wadl which looked more promising but I couldn't reimport that template.
Is there any way to move template query string parameters to be query string parameters? Any other options?
At the moment (since 2018) there is the bug in Azure APIM API import. Link.
It's status under review. We tried to raise this directly to Microsoft, but there was no solution provided from their side.

How do you pass parameters to Azure Logic Apps Liquid Connector for JSON-JSON transformation?

I have a Liquid transformation step in my Azure Logic App, using the "Transform JSON to JSON" version of the Liquid connector. I need to pass some parameters into the transformation - these values will end up in the JSON output from the transformation.
Unfortunately, I can't find any documentation or examples on how you would pass such parameters into the Liquid map.
There's no way to specifically 'pass parameters' to a Liquid template because Liquid does not support that construct.
However, you can easily inject a Parameters object into the source JSON using the Compose Action. Then you access them like any other value.

How can I create API with my custom code in Azure?

Can I create an API that has the definition of the sum of two numbers and returns me the output. I want to write all the logic in Azure Web API Management itself. Is there any provision, or do I need to create it in my machine and import it to Azure Web API Management?
Is it possible to create it in Web API in Azure itself, rather than importing it?
There are two ways to go about this. APIM does support policy expressions: https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions This allows you to plug in arbitrary code into request processing pipeline. You can check policy samples here: https://learn.microsoft.com/en-us/azure/api-management/policy-samples to see this in action. When combined with other policies it does allow you to a lot of things. If we assume that you "addition" operation has URI template of /add?a={a}&b={b} then you can sum up and return result with one simple policy:
<return-response>
<set-status code="200" reason="OK" />
<set-body>#{
var a = int.Parse(context.Request.Url.Query.GetValueOrDefault("a", "0"));
var b = int.Parse(context.Request.Url.Query.GetValueOrDefault("b", "0"));
return (a + b).ToString();
}</set-body>
</return-response>
As you can see this is a pretty much regular C# code, but it's limited in what you can do and what types you can use (see first link). If you can't make it work within these limitations your best bet is to move custom logic outside of APIM, into Azure Functions, for example.

API management with odata backend, would $metadata work

How would I define the template for odata, is this supported with api management? thanks!
e.g.
metadata endpoint
odata filters, $top, $filter, $expand etc
Could someone point me a few examples please?
Just create a normal operation with collection URI. $top, $filter, and $expand - are just query parameters, you can add them to operation definition as well. Shouldn't be any different from registering any other operation with query parameters, really, as APIM does not have any special handling for OData.