Oracle Fusion Applications provide a comprehensive set of REST APIs that act as gateway for essential operations: Getting data out (GET), Creating new records (POST), Updating existing data (PATCH/PUT), and Deleting (DELETE).
While Oracle's documentation serves as a necessary foundation, the sheer number of possible use cases and data combinations means it can't cover every specific scenario. It is up to us, the developers and integrators, to master the nuances of these APIs to extract maximum value.It is on us to explore them and use for our purpose.
In this Post we will focus on how we can effectively use GET operation for Oracle Fusion rest API's.
To execute precise and efficient data requests, we need to understand the powerful query parameters available for any Fusion resource. We will be exploring the following key parameters in this post, using the purchaseOrders REST API for our examples:
q- Query Filter (The WHERE Clause)finder- Predefined Optimized Searchesexpand- Nested/Related Data RetrievalonlyData- Suppressing Metadata( Child Links)hasMore- Pagination Indicatoroffset- Controlling Paginglimit- Controlling PagingtotalResults- Getting the Total Countfields- Data Projection (Selecting specific columns)
1. q - query parameter
q parameter is the most fundamental and frequently used method for filtering our data. It acts exactly like the WHERE clause in a traditional SQL query, allowing us to define one or more expressions to restrict the resource collection returned.The resource collection will
be queried using the provided expressions. The value of this query
parameter is one or more expressions
Format: ?q=expression1;expression2
Let us take example of purchase order.
We want to query by purchase order number.
Example : https://abcd-fa.oraclepdemos.com/fscmRestApi/resources/11.13.18.05/purchaseOrders?q=OrderNumber=US164932https://abcd.fa.oraclepdemos.com/fscmRestApi/resources/11.13.18.05/purchaseOrders?q=SupplierId=300000047507499;StatusCode=CLOSED
2. Finder
Used as a predefined finder to search the collection.
Format: ?finder=<finderName>;<variableName>=<variableValue>,<variableName2>=<variableValue2>
The following are the available finder names and corresponding finder variables:
- PrimaryKey: Finds a purchase order according to the purchase order identifier.
Finder Variables:- POHeaderId; integer; Value that uniquely identifies a purchase order.
- findByIntent: Finds purchase orders according to the intent.
Finder Variables: - Intent; string; Value that uniquely identifies the intent. Valid values are APUser, POUser, LOBUser, SSPUser, and NonAgentUser.
- POHeaderId; integer; Value that uniquely identifies the purchase order.
- SysEffectiveDate; object.
/purchaseOrders, is designed to return only the primary or Header details of the resource. This minimizes the initial payload size.However, in real-world integration, we frequently need the related Child resources (like lines, distributions, or attachments) in the same API call. This is where the powerful expand parameter comes in.
The expand parameter tells the server to fetch and embed related resources directly within the main resource's JSON response, saving us from making multiple round-trip API calls.
We can see in te below screenshot that lines data of the queried po also came in response:
Hierarchy Example:
Goal: Get the Purchase Order Header, its Lines, and the Schedules for each line in a single, efficient call.
Syntax for Deep Expansion: We specify the parent resource (lines) and then the child resource (schedules) separated by a dot.
https://abcd.fa.oraclepdemos.com/fscmRestApi/resources/11.13.18.05/purchaseOrders?q=POHeaderId= 4&expand=lines.schedules.distributions
After we use onlyData=true we get respone like below.
By default Oracle Fusion Rest API's returns 25 records in the result and if there are more records in the result then it mentions hasMore as true like below:
We can use this along with limit and offset to iterate to get remaining data untill it becomes false.
We use this to iterate over to get the remaining records, the offset value has to be changed in every iteration and it becomes the next value to start from and get the reults with the specified limit.
By default the offset will be 0 to fetch records from starting.
We can use offset like below:
It is useful in iterating to get the remaining data in subsequent calls.
We can specify limit upto 500 to bring records in one call.
If we use limit value mre than 500, for eg. 1000 then Oracle Fusion makes it to 500 by default as we can see in below example.
By default the value is set to false.
The totalResults provide us the total count of records we have for the resource we are making the call for.
If we set the value to true in the request then we get the totalResults in the response:
totalResults=true
As mentioned in the below screenshot.
9. Fields
Format for fields in child resource: ?fields=Accessor1:Attribute1,Attribute2
https://abcd.fa.oraclepdemos.com/fscmRestApi/resources/11.13.18.05/purchaseOrders?fields=OrderNumber,Supplier;lines:Description,LineType,LineNumber
OrderNumber and Supplier fields are from headers and Description,LineType and LineNumber are from line level.
Now that we have seen all the different types of parameters we can easily combine these and use in our rest calls as required.
Here is one example to fetch all POs for supplier EDF, selected fields from headers and lines, get only data to remove child links, set limit of 200 records per page and display totalResults
example request:
https://abcd.fa.oraclepdemos.com/fscmRestApi/resources/11.13.18.05/purchaseOrders?q=Supplier=EDF &fields=OrderNumber,Supplier;lines:Description,LineType,LineNumber&onlyData=true&limit=200&totalResults=true
The resonse payload will look like below:
No comments:
Post a Comment