GET $compute

The $compute system query option allows clients to define computed properties that can be used in a $select or within a $filter or $orderby expression.

The $compute system query option is interpreted relative to the entity type or complex type of the resources identified by the resource path section of the URL.

The value of $compute is a comma-separated list of compute instructions, each consisting of a common expression followed by the keyword as, followed by the name for the computed dynamic property. This name MUST differ from the names of declared or dynamic properties of the identified resources.

Example Code

var myHeaders = new Headers();

myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySW5mbyI6IntcIklkXCI6OTgxLFwiSWRlbnRpdHlJZFwiOlwiNjMyMzhhZTQtMzAyMC00NWI5LWEwODktOTE2ZTY4MDMyZTY3XCIsXCJVc2VyTmFtZVwiOlwiMF9URVNUX0NMSUVOVFwiLFwiRW1haWxcIjpcInRlc3RjbGllbnRAd2VhbHRodGVjaHMuY29tXCIsXCJGaXJzdE5hbWVcIjpcIlRlc3RcIixcIkxhc3ROYW1lXCI6XCJDbGllbnRcIixcIklzQ2xpZW50VXNlclwiOmZhbHNlfSIsIm5iZiI6MTY5NDcwMjU3OSwiZXhwIjoxOTI0OTIzNjAwLCJpc3MiOiJXZWFsdGhUZWNocyIsImF1ZCI6IkFQSVVzZXJzIn0.bNcP0ouNwtFoxrI7pYXw0WKiw0TN6w_R2-Ban5moo1A");

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  redirect: 'follow'
};

fetch("https://api.wealthtechs.com/v2/odata/Positions?$compute=MarketValue div Quantity as MarketDivQuantity&$select=MarketDivQuantity&$top=5", requestOptions)
  .then(response => response.json())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Example Response

{
    "@odata.context": "https://api.wealthtechs.com/v2/odata/$metadata#Positions(MarketDivQuantity)",
    "value": [
        {
            "MarketDivQuantity": 0.993264
        },
        {
            "MarketDivQuantity": 0.967223
        },
        {
            "MarketDivQuantity": 0.991096
        },
        {
            "MarketDivQuantity": 0.995504
        },
        {
            "MarketDivQuantity": 0.998977
        }
    ]
}