How to pull data from Oracle IDCS (Identity Cloud Services) rest API

Updated: Nov 3, 2018

Oracle IDCS has various rest apis which can be used to pull data and you can utilize it further for data analytics. Lets see how we can pull data using simple shell scripts.

Step1: Create a parameter file "param.txt" which will contain Customer ID, Customer secret and organization url (all in new line). You can leave the environment name as it is. Please note below values are just dummy values to showcase how you need to create param file. Validate using postman if your keys are working properly before running the script.

scripts> pwd


scripts> more param.txt








Step2: At the same path create the script for pulling data in JSON format, brief description is given before each step.

#Check if parameter file exists and its parameters


[ -f ./param.txt ] && echo "Parameter file is present" || echo "Parameter file not found!! Create param.txt with CID,CSEC,ORG,ENV details."

ENV=`head -8 ./param.txt | tail -1`

[ -z "$ENV" ] && echo "Environment variable is empty" || echo "Environment variable looks good"

case $ENV in

DEV) echo "Welcome to DEV environment!" ;;

QUAL) echo "Welcome to QUAL environment!"

CID=`head -2 ./param.txt | tail -1`

CSEC=`head -4 ./param.txt | tail -1`

ORG=`head -6 ./param.txt | tail -1`

sleep 1;;

PL) echo "Welcome to ProdLike environment!" ;;

PT) echo "Welcome to ProdTest environment!" ;;

PROD) echo "Welcome to PROD environment!" ;;

*) echo "Invalid environment selection!" ;;


# Create basic_token base64, basic_token generated at

basic_token=`echo -n $CID:$CSEC | base64 -w 0`

# Function to regenerate token if token test fails or expires



curl -X POST \

"$ORG/oauth2/v1/token" \

-H "Authorization: Basic $basic_token" \

-H "Cache-Control: no-cache" \

-H "Content-Type: application/x-www-form-urlencoded" \

-d "grant_type=client_credentials&scope=urn%3Aopc%3Aidm%3A__myscopes__" | awk -F[":"] '{print$2}' | awk -F[","] '{print$1}' | awk '{print substr($0, 2, length($0) - 2)}' > access_token.tmp

echo "New token is generated.. access_token refreshed!!"


# Testing if token is valid, if invalid generate the new token

access_token=`more access_token.tmp`