API

Expand and select

Expand and select can be used to add or remove fields from the response of GET requests.

1. Expand

Expand can be used to add fields to the response of some GET requests. Fields that can be added/expanded is defined for each API, and can be seen as grayed out in the Output tab when browsing the documentation pages of an API.

To add expandable fields to the response, specify a comma-separated list of fields in the $expand query parameter.

Examples

The resource sales/order-items has many expandable fields. These will by default not be returned, but by using $expand several options is available:

  • sales/order-items?$expand=Accounting
    Will add all fields grouped under Accounting to the response

  • sales/order-items?$expand=HighlightedNotification
    Will add all fields grouped under HighlightedNotification to the response

  • sales/order-items?$expand=SalesOrderItem.HighlightedNotification
    Same as above, but can be used to avoid ambiguous between several expand fields

  • sales/order-items?$expand=Accounting,HighlightedNotification
    Will add fields grouped under Accounting and HighlightedNotification to the response

Note that $expand should be used by caution, as it might affect the reponse time of the API request

2. Select

Select can be used to limit the number of fields in the response of GET requests. By limiting the number of fields, the API reponse time is improved and the response size is reduced. This is particularly useful when developing mobile applications or other applications where slow internet connection might be a problem.

Any output field of the resource can be selected. A comma-seperated list of fields, or group of fields, is specified in the $select query parameter.

Note that when the $select query parameter is specified, all other fields is removed from the response

Examples

The resource sales/order-items returns a lot of fields, and most of them will by default be returned. By using $select it is possible to limit the fields in the response:

  • sales/order-items?select=SalesOrderItemId
    Only the field SalesOrderItemId is returned. All other fields is removed from the response.

  • sales/order-items?select=SalesOrderItemId,Status
    Both SalesOrderItemId and Status is returned. All other fields is removed from the response.

  • sales/order-items?select=Customer
    All the fields in the Customer-group is is returned. All other fields is removed from the response.

  • sales/order-items?select=Currency
    Both the Currency-field in the Price-group and the Currency-field in the Totals-group is returned. All other fields is removed from the response.

  • sales/order-items?select=Price.Currency
    Only the Currency field in the Price-group is returned. All other fields is removed from the response.

Note that fields specified in the $expand query parameter will be selected even if they are not specified in the $select query parameter.