GET $expand

The $expand system query option specifies the related resources or media streams to be included in line with retrieved resources. Each expandItem is evaluated relative to the entity containing the navigation or stream property being expanded.

Examples:

  • Expand a navigation property of an entity type: http://host/odata/Accounts?$expand=Positions
  • Expand a navigation property of a complex type: http://host/odata/Customers?$expand=Addresses/Country

Query options can be applied to an expanded navigation property by appending a semicolon-separated list of query options, enclosed in parentheses, to the navigation property name. Allowed system query options are $filter, $select, $orderby, $skip, $top, $count, $search, and $expand.

  • http://host/odata/Accounts?$expand=Positions($filter=ProcessDate eq 2023-01-14)

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/Accounts?$expand=Positions($top=3)&$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#Accounts(Positions())",
    "value": [
        {
            "Id": 12,
            "CustodianId": 0,
            "CustomerId": 0,
            "Number": "X72843476R",
            "Master": "123456789",
            "Name": "Test Account Name",
            "AccountStatus": "Test Account Status",
            "AccountType": "Test Account Type",
            "PrimaryContact": "Test Primary Contact",
            "MailingAddress": "Test Mail Address",
            "MailingCity": "Test Mail City",
            "MailingState": "Test Mail State",
            "MailingCountry": "Test Mail Country",
            "MailingZipCode": "Test Mail Zip Code",
            "Email": "email@email.com",
            "Phone": "xxx-xxx-xxxx",
            "BussinesPhone": "xxx-xxx-xxxx",
            "DateOpened": "2023-01-01T00:00:00-05:00",
            "CurrencyId": null,
            "Positions": [
                {
                    "CustodianId": 0,
                    "CustomerId": 0,
                    "ProcessDate": "2023-09-11T00:00:00-04:00",
                    "AccountId": 12,
                    "SecurityId": 8492,
                    "ShortPosition": false,
                    "Quantity": 200000,
                    "MarketValue": 198652.8,
                    "OriginalCost": 199112,
                    "OriginalCostDate": "1950-01-01T00:00:00-05:00",
                    "OriginalFace": null
                },
                {
                    "CustodianId": 0,
                    "CustomerId": 0,
                    "ProcessDate": "2023-09-11T00:00:00-04:00",
                    "AccountId": 12,
                    "SecurityId": 8516,
                    "ShortPosition": false,
                    "Quantity": 200000,
                    "MarketValue": 193444.6,
                    "OriginalCost": 200011,
                    "OriginalCostDate": "1950-01-01T00:00:00-05:00",
                    "OriginalFace": null
                },
                {
                    "CustodianId": 0,
                    "CustomerId": 0,
                    "ProcessDate": "2023-09-11T00:00:00-04:00",
                    "AccountId": 12,
                    "SecurityId": 8646,
                    "ShortPosition": false,
                    "Quantity": 500000,
                    "MarketValue": 495548,
                    "OriginalCost": 500012,
                    "OriginalCostDate": "1950-01-01T00:00:00-05:00",
                    "OriginalFace": null
                }
            ]
        },
        {
            "Id": 13,
            "CustodianId": 0,
            "CustomerId": 0,
            "Number": "Y41213443S",
            "Master": "123456789",
            "Name": "Test Account Name",
            "AccountStatus": "Test Account Status",
            "AccountType": "Test Account Type",
            "PrimaryContact": null,
            "MailingAddress": "Test Mail Address",
            "MailingCity": "Test Mail City",
            "MailingState": "Test Mail State",
            "MailingCountry": "Test Mail Country",
            "MailingZipCode": "Test Mail Zip Code",
            "Email": null,
            "Phone": "xxx-xxx-xxxx",
            "BussinesPhone": "xxx-xxx-xxxx",
            "DateOpened": "2023-01-01T00:00:00-05:00",
            "CurrencyId": null,
            "Positions": [
                {
                    "CustodianId": 0,
                    "CustomerId": 0,
                    "ProcessDate": "2023-09-12T00:00:00-04:00",
                    "AccountId": 13,
                    "SecurityId": 16085,
                    "ShortPosition": false,
                    "Quantity": 5547.5,
                    "MarketValue": 5547.5,
                    "OriginalCost": null,
                    "OriginalCostDate": null,
                    "OriginalFace": null
                },
                {
                    "CustodianId": 0,
                    "CustomerId": 0,
                    "ProcessDate": "2023-09-18T00:00:00-04:00",
                    "AccountId": 13,
                    "SecurityId": 16085,
                    "ShortPosition": false,
                    "Quantity": 68937.57,
                    "MarketValue": 68937.57,
                    "OriginalCost": null,
                    "OriginalCostDate": null,
                    "OriginalFace": null
                },
                {
                    "CustodianId": 0,
                    "CustomerId": 0,
                    "ProcessDate": "2023-09-19T00:00:00-04:00",
                    "AccountId": 13,
                    "SecurityId": 16085,
                    "ShortPosition": false,
                    "Quantity": 2943.79,
                    "MarketValue": 2943.79,
                    "OriginalCost": null,
                    "OriginalCostDate": null,
                    "OriginalFace": null
                }
            ]
        },
        {
            "Id": 14,
            "CustodianId": 0,
            "CustomerId": 0,
            "Number": "Z68397130T",
            "Master": "123456789",
            "Name": "Test Account Name",
            "AccountStatus": "Test Account Status",
            "AccountType": "Test Account Type",
            "PrimaryContact": "Test Primary Contact",
            "MailingAddress": "Test Mail Address",
            "MailingCity": "Test Mail City",
            "MailingState": "Test Mail State",
            "MailingCountry": "Test Mail Country",
            "MailingZipCode": "Test Mail Zip Code",
            "Email": "email@email.com",
            "Phone": "xxx-xxx-xxxx",
            "BussinesPhone": "xxx-xxx-xxxx",
            "DateOpened": "2023-01-01T00:00:00-05:00",
            "CurrencyId": null,
            "Positions": [
                {
                    "CustodianId": 0,
                    "CustomerId": 0,
                    "ProcessDate": "2023-09-11T00:00:00-04:00",
                    "AccountId": 14,
                    "SecurityId": 8437,
                    "ShortPosition": false,
                    "Quantity": 80000,
                    "MarketValue": 74432.8,
                    "OriginalCost": 79945.8,
                    "OriginalCostDate": "1950-01-01T00:00:00-05:00",
                    "OriginalFace": null
                },
                {
                    "CustodianId": 0,
                    "CustomerId": 0,
                    "ProcessDate": "2023-09-11T00:00:00-04:00",
                    "AccountId": 14,
                    "SecurityId": 8561,
                    "ShortPosition": false,
                    "Quantity": 75000,
                    "MarketValue": 61068.38,
                    "OriginalCost": 73964.5,
                    "OriginalCostDate": "1950-01-01T00:00:00-05:00",
                    "OriginalFace": null
                },
                {
                    "CustodianId": 0,
                    "CustomerId": 0,
                    "ProcessDate": "2023-09-11T00:00:00-04:00",
                    "AccountId": 14,
                    "SecurityId": 8639,
                    "ShortPosition": false,
                    "Quantity": 100000,
                    "MarketValue": 89882.1,
                    "OriginalCost": 99871,
                    "OriginalCostDate": "1950-01-01T00:00:00-05:00",
                    "OriginalFace": null
                }
            ]
        }
    ]
}