Exploring Various Data Retrieval Options Using GET request
Objective
After completing this lesson, you will be able to control request output using various retrieval options
Retrieval Options Using Service Layer API
Retrieving data is the most heavily used operation in any web application. Service Layer provides various OData complaint retrieval options.
Retrieving data through Simple requests - Retrieve raw data for the entity.
Retrieving data through association and navigation - The association expresses the relationship between two entities bound by navigation properties. The association and navigation rules are defined in the Service Layer metadata.
Retrieving data through query options - Query options are query string parameters that control the amount and order of the data returned for the resource/entity.
How to Use Different Data Retrieval Options
In this video, you’ll learn various retrieval options in SAP Business One using Service Layer.
Control Request Output Using Various Retrieval Options
In this exercise, you’ll practice retrieving data in the Service Layer API using different query options.
Before starting this exercise, make sure that you:
Complete a login request so that you have a session ready to use.
Steps
To retrieve a sales order collection, amend the following HTTP sample request and send:
Sample request
Code Snippet
1
GET https://localhost:50000/b1s/v2/Orders
Check the response:
Check the response code - it should be 200 OK if the HTTP request is successful.
Check the response content - it should contain the list of sales orders with all the properties starting from the first 20 documents. (20 documents are retrieved based on the Pagesize set in the Service Layer Configuration).
At the end of the response content is the property, odata.nextLink, which provides the link for the next collection chunk.
To retrieve specific sales order with all property, amend the following HTTP sample request and send:
Sample request
Code Snippet
1
GET https://localhost:50000/b1s/v2/Orders(10)
Check the response:
Check the response code - it should be 200 OK if the HTTP request is successful.
Check the response content - it should contain all the properties for the sales order docentry mentioned in the request.
To retrieve individual property for a sales order, amend the following HTTP sample request and send:
Sample request
Code Snippet
1
GET https://localhost:50000/b1s/v2/Orders(10)/DocNum
Check the response:
Check the response code - it should be 200 OK if the HTTP request is successful.
Check the response content - it should contain only the DocNum property along with the @odata.context and @odata.etag.
To retrieve individual property value for a sales order, amend the following HTTP sample request and send:
Sample request
Code Snippet
1
GET https://localhost:50000/b1s/v2/Orders(10)/DocNum/$value
Check the response:
Check the response code - it should be 200 OK if the HTTP request is successful.
Check the response content - it should contain only the value of DocNum.
To retrieve the list of the delivery note associated with the Business Partner for a particular sales order, amend the following HTTP sample request and send:
Sample request
Code Snippet
1
GET https://localhost:50000/b1s/v2/Orders(10)/BusinessPartner/DeliveryNotes
Check the response:
Check the response code - it should be 200 OK if the HTTP request is successful.
Check the response content - it should contain the first 20 delivery notes associated with the Business Partner used in the sales order. (20 documents are retrieved based on the Pagesize set in the Service Layer Configuration).
At the end of the response content, there is the property odata.nextLink, which provides the link for the next collection chunk.
To retrieve the sales order collection only with three properties DocNum,DocDueDate,DocTotal using query options, amend the following HTTP sample request and send:
Sample request
Code Snippet
1
GET https://localhost:50000/b1s/v2/Orders/?$select=DocNum,DocDate,DocTotal
Check the response:
Check the response code - it should be 200 OK if the HTTP request is successful.
Check the response content - it should contain the first 20 sales orders with properties: DocNum,DocDate,DocTotal. (20 documents are retrieved based on the Pagesize set in the Service Layer Configuration).
At the end of the response content is the property, odata.nextLink, which provides the link for the next collection chunk.
To retrieve the sales order collection only with three properties (DocNum,DocDate,Doctotal), and filter the document based on DocDate using query options, amend the following HTTP sample request and send:
Sample request
Code Snippet
1
GET https://localhost:50000/b1s/v2/Orders$filter=DocDate ge '2020-03-23'& $select=DocNum,DocDueDate,DocTotal
Check the response:
Check the response code - it should be 200 OK if the HTTP request is successful.
Check the response content - it should contain the first 20 sales orders with properties: DocNum,DocDate,DocTotal. (20 documents are retrieved based on the Pagesize set in the Service Layer Configuration).
At the end of the response content is the property, odata.nextLink, which provides the link for the next collection chunk.
To retrieve the count of sales order in the database using query options, amend the following HTTP sample request and send:
Sample request
Code Snippet
1
GET https://localhost:50000/b1s/v2/Orders?$apply=aggregate($count as OrdersCount)
Check the response:
Check the response code - it should be 200 OK if the HTTP request is successful.
Check the response content - it should contain the count value under the property name OrdersCount.
To retrieve the list of sales orders grouped by CardCode and DocTotal using query options, amend the following HTTP sample request and send:
Sample request
Code Snippet
1
GET https://localhost:50000/b1s/v2/Orders?$apply=groupby((CardCode), aggregate(DocTotal with sum as Total))
Check the response:
Check the response code - it should be 200 OK if the HTTP request is successful.
Check the response content - it should contain the list of CardCode with sum of the DocTotal value..
To retrieve the associated business partner information from the sales order in the same payload, amend the following HTTP sample request and send:
Sample request
Code Snippet
1
GET https://localhost:50000/b1s/v2/Orders(10)?$select=*,BusinessPartner&$expand=BusinessPartner
Check the response:
Check the response code - it should be 200 OK if the HTTP request is successful.
Check the response content - After the "@odata.etag" property the BusinessPartner entity information is displayed followed by the sales order properties.
Result
You have successfully performed various data retrieval options and checked how the request output can be controlled.