Tired of manually updating OIC Connection details? Learn how to automate with REST and Python

All of the Oracle Fusion environments I use have a weekly password refresh. That results in a tedious task of updating all the OIC Connections every now and then.

To overcome this I created a Python Script that makes use of the OIC REST API’s.

Get Connections

For that I will use the GetConnections REST API. This will retrieve all the connections for that OIC instance.

This is a sample of the response.

 {
            "adapterType": {
                "displayName": "ERP Adapter",
                "name": "ERP",
                "type": "PREINSTALLED"
            },
            "id": "ERPAdapterF13",

The idea is to pick up all the adapters with ERP, HCM or CX in the name – Of course this only works if you have a naming convention where you have ERP/HCM/CX as a prefix – which I do 🙂

Python

I will use the requests package for the HTTP calls.

In the first part of the script I simply map the URL and the Credentials, and pass all of that to the requests.get() method.

Then I map the response to a dict variable.

import requests
import json

url = 'https://xx.integration.ocp.oraclecloud.com/ic/api/integration/v1/connections/'
cred = ('myuser', 'mypassword')

response=requests.get(
  url,
  auth = cred
)

dict = response.json()

Before processing the response it’s easier to convert it to JSON

#converting dict to json 
data = json.dumps(dict)

Then we Iterate over all the connections, searching for a keyword (ERP in this case) in the attribute id, and for each connection id we update the connection using this REST API.


index=len(dict['items'])

for i in range(index):
  if "ERP" in json.loads(data)['items'][i]['id']:
    finalurl=url+ json.loads(data)['items'][i]['id']
    resp=requests.post(finalurl,headers=h,auth=cred,data=payload)
    print(f"Updating the Password for Connection with ID: {json.loads(data)['items'][i]['id']}\n Result is: {resp}")

The above code uses 2 new variables – Payload and h(eaders), which are required for the POST method. The Payload contains the password that we want to update the connection.

payload="{\"securityProperties\":[{\"propertyName\":\"password\",\"propertyValue\": \"<newpassword>\"}]}"
h = {'Content-type': 'application/json','Accept': 'application/json','X-HTTP-Method-Override': 'PATCH'}

More parameters can be updated with different Payloads.

Running the script

Once this is executed you can see the below output. The name of the connection and the response status.

200 means all went good. 423 means the resource is locked and 400 something went wrong.

Automation makes life easier, that’s for sure!