We have a farm behind an Azure APIM service.
Whenever we want to perform maintenance tasks, we want to flag APIM for returning 503 and preferably a dynamic countdown in the Retry-After header.
Is there a feature in APIM to do this?
Thank you MayankBargali-MSFT ,Posting your suggestion as an answer to help other community members.
"There is no out of box feature that can help you but you can implement the logic using APIM policy. You can use Set status code and set HTTP header policy to transform your backend respond according to your requirement.
You can set some flag to only execute your maintenance policy only during your backend maintenance. You can save the flag status and maintenance duration/time using APIM named values so it is easy to update these value.
In your policy you can get the maintenance time and compare with the current time using APIM policy expression #(DateTime.Now.ToString()) and set the Retry-After header value."
Related
I am currently working with Azure API managemnet where I am stuck at a wired junction. My client wants Product level authentication, so I have created one product and added a policy there. But, now for an particular api the it is not required.
I tried a lot of thing like, deleteing the authorization header but it is not working. can you please suggest a solution for this.
you can remove the base tag in the inbound section of the policy for that operation by doing that the policy applied at product level will not be executed for the particular operation.
reference: https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-policies
I managed to configure in APIM a set of policies that do what I need (authentication). The config XML is long and dirty, but the rules should be applied to all APIs that require authentication, so I can just set them on 'All APIs' level. But of course not all APIs require authentication. The idea is to configure them using some kind of flow control policy so that they are applied only if API is tagged. But I didn't found a way how to get the APIs metadata.
So is there a way the read APIs metadata using APIM expressions? Or any other way to achieve the main goal?
Checking https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions#ContextVariables again I see no way to query tag meta information while in a policy. Of course you could query tags for an API over API Management REST API itself on the way but I guess this would increase latency substantially.
For cases like this I would create an API product, put the authentication part into the product's policy and then only assign relevant APIs to this product.
Disclaimer : I am very new to Azure API Management
Hi Friends,
I have the following requirement to be accomplished -
The user will upload an image from a mobile app as "form-data".
An API will be called through Azure APIM and the image will be stored in Blob.
The call should also invoke a backend API at the same time along with the image which does processing and gives the result back.
Could you please suggest how should I proceed on writing the APIM policy for this. I am aware of handling the image at the API side if it comes as part of JSON data. I am just looking for suggestions on the APIM part or more precisely about how to write the policy if the image is part of form-data.
Any help is appreciated.
Thanks and Regards,
Amit Anand
I am just looking for suggestions on the APIM part or more precisely about how to write the policy if the image is part of form-data.
I have reached out to the APIM team for this scenario and they've confirmed this isn't supported at this time. The recommendation is to use JSON payload and, parse & consume accordingly.
If you feel strongly about this, please consider submitting a feature request on Azure UserVoice for the APIM team to review for the product roadmap.
Refer to this issue.
We have configured APIM and point it to API endpoints which is deployed in WebApp.
We have configured products, subscription keys, APIS, Operations for the same.
For APIM endpoints, it is necessary for developer to pass subscription key, if not passed, APIM will return HTTP 401 with below error message
Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription.
Is there any way, we can change this with custom message as required by business team?
Use choose policy inside on-error section to identify the scenario (you can inspect context.LastError.Reason), and return-response policy to provide custom response.
There is currently no way to do this. Please vote for this request on Azure's feedback forum:
Customize error schema messages
Edit: #Vitaliy Kurokhtin answer is a work-around, although you need to keep in mind where you define the error policy (All APIs level, API level, Operation level) will impact whether or not the On Error policy you defined will get invoked
we have an production issue where the order is submitted twice. Currently we have an API for order and we are exposing this to client using API management and in these we have policies for URL mapping for customer facing to actual .
Now , our actual API got 2 request so we thought customer submitted twice but they have confirmed that they have not submitted twice , so either there is issue with API management which fired 2 request.
How can i Identify the request received by the API management ?
Is there any chance that API management will fire the request twice ?
Appreciate any pointers
The only way to fire request twice in APIM would be by the means of Retry policy or manually using SendRequest. Otherwise it should be a client calling your API two times. Each request in APIM get it's own unique id accessible in policies as context.RequestId, this is the main way to track and identify them. But these ids are produced inside APIM itself thus are useful only if you're tracking a call from APIM and into backend.
Your best option now is to try to identify requests by client ip, method, uri, and time frame. APIM allows you to grab logs for certain periods of time (better if kept short) in JSON or CSV with data I mentioned above. To do that look into byRequest report (https://learn.microsoft.com/en-us/rest/api/apimanagement/reports#ReportByRequest), grab JSON/CSV and try to identify calls of interest,
For future you could look into onboarding your service to azure monitor (https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-use-azure-monitor) or log analytics those provide easier way to traverse logs.