Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Stripping of HTML part from response returned by API endpoint having content as mix of json+html

Hello all,

We have a backend returning as API response the mix of json and html. In our company we are using apigee as proxy for all client calls. We need to strip off html part and keep only JSON part returned to the client.

Unfortunately endpoint is controlled by a vendor tool and for now we have no control over activating/deactivating xml part before response is sent back to apigee. Right now response is returned from the endpoint with Content-Type: text/html  and content like :

 

 

{
   key1: value1,
   key2: value2,
   ...
}
<webresult>
 ...
</webresult>

 

 

I have written simple JS code put into JS policty to strip off <webresult> however when I try to add it into response Target Endpoints PostFlow but my problem is that  I always get response.content value empty.

I have tried to get response in the following ways but without any luck:

 

 

var content1 = response.content;

 

 

however when I tried to display response.status.code it worked.

I have also tried to add a policy before JS policy to set Content-Type to text/plain but that did not help.

Trying to get content asJSON does not work, returns empty JSON:

 

 

print("json response:"+content.response.asJSON")

 

seems like response.content is empty, but that's not true, because the response contains json and html tags as explained above, so something is either not set or misconfigured in my case.

 

Can someone advise whether apigee will allow us to process mix of json+htmlresponse and modify it in the way to strip off html part and keep only json as final response? I was looking at ExtractVariable step as well, but first trials did not give any success.

Thanks for support,

0 11 2,097
11 REPLIES 11