Register REST API in Webservices under the application composer tool.

 The article gives the sample scripts with the use of Oracle Fusion Cloud REST APIs in Groovy. it includes all the crud operations and some advanced methods to access the REST APIs.


Sometimes only groovy can't be used to fulfill the requirement. we might need web services to connect the two systems or the same system in groovy. Oracle Fusion Cloud will allow web service usage in groovy after registering in the application composer with host details and the path. this article will explain the optimum way of using web services in oracle fusion cloud groovy.

Benefits:

1) Use a single web service for multiple objects if it is a similar endpoint structure.

2) Minimum No of  Webservice registrations in application composer.

UseCases:

1) Use a single web service for creating lead/opportunity/account/contact/custom objects.

2) Use a single web service to update any entity child object in the oracle fusion cloud.

Important Notes:

a) The host can't dynamic in the oracle fusion cloud. i.e we need to register web services for each environment.

b) After P2T/T2T delete the web servicesof the lower environment and register with the current environment URL.

c) Authorization can be anything available on the web-service registration page.

d) Once the credential key is defined for basic authentication, can't be updated. we need to create another one with new credentials.

e) Webservice call is more expensive than groovy call in terms of performance.

f) Test the web service endpoint in POSTMAN or SOAPUI before registering.

Creating Webservice:

Consider the URL for Account in Oracle Engagement Cloud:

https://<myHost>/crmRestApi/resources/latest/accounts/<PartyNumber>

The only dynamic part of this appears to be the Party Number, so the URL could be entered as:

Dynamic segments are defined using the notation ##<path_segment>##

https://<myHost>/crmRestApi/resources/latest/accounts/##PartyNumber##

Consider the URL for Opportunity in Oracle Engagement Cloud:

https://<myHost>/crmRestApi/resources/latest/opportunities/<OptyNumber>

The only dynamic part of this appears to be the Opty Number, so the URL could be entered as:

https://<myHost>/crmRestApi/resources/latest/opportunities/##OptyNumber##

now look at these two URLs, we can also make the object name dynamic.

so the dynamic URL can be constructed as below

https://<myHost>/crmRestApi/resources/latest/##ObjectName##/##ObjectKey##

Child Object: https://<myHost>/crmRestApi/resources/latest/##ObjectName##/##key##/child/##childName##  

so if other objects follow the same pattern we can just pass the object name and key value to get the respective record.

 

The sample payloads are used to provide design-time hints in the expression builder, but a simple payload {} works too. 



The above endpoint will work for the methods GET, PATCH, and DELETE as we are passing the key in the URL.

for the POST method create another web service without the Object Key parameter.

 

Webservice Registration Page for GET Method:

 

Note: we have not given anything in as no payload is required for get operation

 

A screenshot of a computer

Description automatically generated

 

Webservice Registration Page for PATCH Method:

 

Note: we have given {} in as payload is required for patch operation in both request and response payloads.

 

 

 

Webservice Registration Page for DELETE Method:

 

A screenshot of a computer

Description automatically generated

 

Webservice Registration Page for POST Method:

 

Similarly for POST use the below method



A screenshot of a computer

Description automatically generated





Groovy to call REST API with GET Operation:

 

def ObjService = adf.webServices.getRecord 

def objectName = 'accounts'

def objectID = '288666'           //Pass the record identifier as dynamic if required

def queryParms = [:] 

queryParms.fields='PartyId,OrganizationName'  // Provide field Names only, you required. if you skip queryParms all fields will come in the response.

queryParms.onlyData='true' 

ObjService.dynamicQueryParams = queryParms 

def response = ObjService.GET(objectName, objectID) 

 

setAttribute("ApprovedProducts_c", response)

 

Groovy to call REST API with POST Operation:



def ObjService = adf.webServices.getRecord 

def objectName='opportunities' 

def objectID = OptyNumber              //assumes this code is being run in the context of an Opportunity record  

def headers = [:] 

headers.'Content-Type' = 'application/vnd.oracle.adf.resourceitem+json' 

ObjService.requestHTTPHeaders=headers 

def body = [:] 

body.Name = 'Test Opportunity Name Sunil' 

body.StatusCode = 'ORA_OPEN' 

def response = ObjService.POST(objectName, objectID, body) 

 

setAttribute("ApprovedProducts_c", response) // just to see the response



Comments

Popular posts from this blog

Access REST APIs in Oracle Fusion Using Cloud Groovy

OIC to perform the Integration