0
votes

I am building a multi tenant application. We are not using Azure Active directory. We are using logic apps as a back-end services. Since each and every API url has a parameter tenant, we wanted to include at the API management level.

https://apm-eso-01.azure-api.net/{tenant}/v1/{siteid}/inventoryItems

Is there any possibility to add path parameter to the host URL at the API Management level rather than including at the logic app as a relative path.

Backend Urls. We have different instnaces/servers for each tenants

Tenant1 :
https://esous-devpd1.host.com/retail/data/esosm/api/v1-beta2/get/1

Tenant2:

https://esospanish-devpd1.host.com/retail/data/esosm/api/v1-beta2/get/1

APIM Urls

https://apm-eso-host-sbx-01.azure-api.net/lse/{tenant}/ esosm/api/v1/get/1

In-order to support the place holder for tenant at the APIM url/endpoints, I should add tenant place holder or path parameter to the backend url as below.

https://esous-devpd1.host.com/retail/data/esosm/{tennant}/api/v1-beta2/get/1

But all my urls should have tenant as a path parameter.

So my question is can we add tenant place holder or path parameter to the APIM end point and just rewrite the backend server url as such to include the tenant parameter rather than adding it to the backend url

1
I belive that I know what you are asking, but can you please add an example transformation (before/after) so that I am sure?Topher
i have edited my question with more detailsChandra Mohan

1 Answers

0
votes

This can be achieved by making sure that all operation URL templates in APIM start with /{tenant}/. Then you can add a policy at global or API level to make the transformation:

<rewrite-uri template="@{
  var operationPath = context.Operation.UrlTemplate.TrimStart('/').Replace("{*", "{");
  var result = operationPath.Substring(operationPath.IndexOf('/'));
  return ("/retail/data" + result).Replace("/v1/", "/v1-beta2/");
}" />

This policy will rewrite URI of current request by removing first segment from URI template. So if APIM receives request to /{tenant}/xxx operation it will rewrite it to /xxx.

And then you can add tenant as a query parameter by:

<set-query-parameter name="tenant" exists-action="override">
    <value>@(context.Request.MatchedParameters["tenant"])</value>
</set-query-parameter>