OData URLs in SAP
OData URLs follow a standardized pattern for accessing resources in SAP systems. This page provides comprehensive documentation on OData URL patterns, query options, and examples for accessing SAP data.
OData URL Structure
OData URLs in SAP typically follow this structure:
https://<server>:<port>/sap/opu/odata/<service_path>/<resource_path>?<query_options>
Components:
- Server and Port: The SAP Gateway server hostname and port
- Service Path: The path to the OData service (e.g.,
/sap/opu/odata/SAP/ZGWSAMPLE_SRV
) - Resource Path: The path to the specific resource (e.g.,
/SalesOrderSet
) - Query Options: Optional parameters to filter, sort, or modify the request
Common URL Patterns
Service Document
Retrieves the service document listing all available entity sets:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/
Metadata Document
Retrieves the metadata document describing the data model:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/$metadata
Entity Set
Retrieves all entities in an entity set:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet
Entity
Retrieves a specific entity by key:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet('0500000000')
Navigation Property
Retrieves related entities through a navigation property:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet('0500000000')/ToLineItems
Property
Retrieves a specific property of an entity:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet('0500000000')/CustomerName
Property Value
Retrieves the raw value of a specific property:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet('0500000000')/CustomerName/$value
Query Options
OData URLs support various query options to modify the request:
$filter
Filters the entities in the result:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet?$filter=CustomerName eq 'SAP'
Common filter operators:
eq
: Equalne
: Not equalgt
: Greater thange
: Greater than or equallt
: Less thanle
: Less than or equaland
: Logical andor
: Logical ornot
: Logical negationsubstringof
: Contains substringstartswith
: Starts withendswith
: Ends with
$select
Selects specific properties to include in the result:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet?$select=SalesOrderID,CustomerName
$expand
Expands related entities inline:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet?$expand=ToLineItems
$orderby
Orders the result by one or more properties:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet?$orderby=CreatedAt desc
$top
Limits the number of returned entities:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet?$top=10
$skip
Skips a specified number of entities:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet?$skip=10
$inlinecount
Includes a count of the total number of entities:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet?$inlinecount=allpages
$format
Specifies the response format:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet?$format=json
Common formats:
json
: JSON formatxml
: XML format (default)atom
: Atom format
Combining Query Options
Multiple query options can be combined using the ampersand (&
) character:
https://<server>:<port>/sap/opu/odata/SAP/ZGWSAMPLE_SRV/SalesOrderSet?$filter=CustomerName eq 'SAP'&$top=10&$orderby=CreatedAt desc
Common SAP OData Services
SAP Gateway Foundation
/sap/opu/odata/IWFND/CATALOGSERVICE
: Service catalog/sap/opu/odata/IWFND/METADATA
: Metadata repository
SAP Business Suite
/sap/opu/odata/SAP/API_BUSINESS_PARTNER
: Business Partner API/sap/opu/odata/SAP/API_SALES_ORDER_SRV
: Sales Order API/sap/opu/odata/SAP/API_MATERIAL_DOCUMENT_SRV
: Material Document API/sap/opu/odata/SAP/API_PURCHASEORDER_PROCESS_SRV
: Purchase Order API
SAP S/4HANA
/sap/opu/odata/SAP/API_BUSINESS_PARTNER
: Business Partner API/sap/opu/odata/SAP/API_SALES_ORDER_SRV
: Sales Order API/sap/opu/odata/SAP/API_PURCHASE_ORDER_SRV
: Purchase Order API/sap/opu/odata/SAP/API_PRODUCT_SRV
: Product API
HTTP Methods
OData supports standard HTTP methods for CRUD operations:
- GET: Retrieve data
- POST: Create new entities
- PUT: Update existing entities
- PATCH: Partially update entities
- DELETE: Delete entities
Error Handling
OData services return standard HTTP status codes:
- 200 OK: Successful request
- 201 Created: Entity created successfully
- 204 No Content: Successful request with no response body
- 400 Bad Request: Invalid request
- 401 Unauthorized: Authentication required
- 403 Forbidden: Insufficient permissions
- 404 Not Found: Resource not found
- 500 Internal Server Error: Server error
Best Practices
- Use
$select
to limit the properties returned for better performance - Use
$filter
to reduce the amount of data transferred - Use
$expand
judiciously as it can impact performance - Consider pagination with
$top
and$skip
for large result sets - Use batch requests for multiple operations
- Handle errors gracefully in client applications
- Cache frequently accessed data when appropriate