REST API service when called from azure APIM returning empty response body with Status code 200
Asked Answered
L

4

9

I have added my REST api service in Azure API Management. I have followed all the steps given in this link Azure APIM. API works fine in local. It also works when accessed through published URL.

I have added OAuth2.0 security as well which is passing through fine.

My issue is When i try to access the operation through APIM published URL, the service is giving response 200 with empty content.

Can Someone please help.

Lananna answered 4/11, 2016 at 17:12 Comment(9)
Do you see forward-request policy statement in efective policy for that operation?Babylon
I checked, I have added only validate jwt token policy.Lananna
I followed the document and the API works well for me. What's the exact URL you were requesting? Did this API work when you test on the development portal?Pocosin
No, even from developer portal I am getting same empty response. I am assuming that my request is not reaching API from APIM at all.Lananna
If you go to management portal, policies, select your product, API and operation and click Show effective policy button, what do you see there?Babylon
when you try from developer portal check under Response content there will be Ocp-Apim-Trace-Location there will be a URL which gives you complete trace which should give you clues if it made a backend api call or not and possibly what went wrong and where.Rotter
As @VitaliyKurokhtin was trying clarify, this problem occurs when people unintentionally delete the top level policy and remove the main forward-request policy that applies to all operations on all apis..Interglacial
Thanks Darrel. When I created new one it worked fine.Lananna
@Lananna Excellent. I created an answer, if you could mark it as accepted that may help other people who run into the same issue.Interglacial
I
15

This problem occurs when people unintentionally delete the top level policy and remove the main forward-request policy that applies to all operations on all apis. Simply click the Add policy button to re-add the default policy at the top level scope.

Interglacial answered 29/11, 2016 at 15:10 Comment(2)
Have to say that this should be more clearly flagged, especially with the move to the new Portal. Just wasted a couple of hours assuming it was me, only to finally resort to SO...Iolaiolande
Future guidance: Go to SO first :-) I will forward the feedback though.Interglacial
W
5

Old question, but I'm posting because I had a similar issue (empty response) caused by a different issue:

I was getting empty responses as I had expressions in a policy that read the response. By default, reading the response clears it (presumably because its a stream underneath).

Found some good docs here: https://learn.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#SetBody

I fixed this by specifying "preserve content" when reading the response:

JObject responseJobj = null;
if (context.Response.Body != null) 
{ 
    responseJobj = context.Response.Body.As<JObject>(preserveContent: true); 
}
Wanettawanfried answered 6/10, 2020 at 7:17 Comment(0)
H
0

As mentioned, you have deleted some policy rules from all APIs. to fix this,

  1. navigate to the API tab in the Azure portal
  2. click on All APIs
  3. click on edit inbound policies
  4. add forward-request policy inside the backend enter image description here
Horrid answered 27/10, 2022 at 12:36 Comment(0)
V
0

If you add this:

<backend>
    <forward-request />
</backend>

It will resolve the issue. This part will forward the request to the URL you set as backend service URL.

Venicevenin answered 8/7, 2024 at 15:34 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.