cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove metadata in json Odata response in SAP API Management

kvrsaicharan1152
Explorer
0 Kudos

{

"d":

{"results":

[{"__metadata": {"id": "https://sapes5.sapdevcenter/******/purchaseorders"uri": "https://sapes5.sapdevcenter/******/purchaseorders"

type": "SEPMRA_PO_APV.PurchaseOrder"

},

"ChangedAt": "/Date(1606604400000)/","ProductId": "","CurrencyCode": "USD","DeliveryAddress": "Zeppelinstrasse 2, 8

Here i want to remove or Hide that metadata in the json . When ever call an api that odata response has meta data . Its possible to remove that metadata in sap api management by using javascript policy and some other policies in api portal . Do you have any idea how to implement this

Accepted Solutions (0)

Answers (3)

Answers (3)

drvup
Contributor
0 Kudos

Hi,

make sure it's all the time a json response, then you can remove the metadata object.

Something like this should work (I didn't try, have something similar in place)

var response = context.getVariable("response.content");
var j = JSON.parse(response).d.results;

// delete you metadata content
j.forEach(function(item, index){  
  try{
    j[index].__metadata = "Metadata is now hidden";
  }catch(e){ }
});

response = JSON.stringify(j);
context.setVariable("response.content", response); 

co_walter_zolkin
Explorer
0 Kudos

Hi, I'm sorry, but this is not actually an answer to this question. It need to be removed server side, because f.e. I use an odata service as API. I can't use JS for it.

saisreenivas
Participant
0 Kudos

Hi kvrsaicharan1152,

As metadata is a object named "__metadata", you can use the regex expression in Javascript policy to remove the object __metadata from the response, this will remove every metadata object present in your response.

Hope it helps!

Br/ Sai Sreenivas Addepalli.

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

In OData V4 there is nearly no metadata in an OData response anymore.