How to start with delphix API

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered

Hi Guys,

I am new to delphix API. Can anyone suggest how to start with the API?


Photo of Swathy Sukumar

Swathy Sukumar

  • 866 Points 500 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of Mouhssine SAIDI

Mouhssine SAIDI

  • 4,682 Points 4k badge 2x thumb
Hi,

Good starting point is the documentation :)

https://docs.delphix.com/docs/referen...

Once you are ready to go with some lines coding try the delphixpy module tutos by Adam Bowen or go to github and look for dxtoolkit Delphix's PS developed tool.

Regards,

Mouhssine
Photo of Swathy Sukumar

Swathy Sukumar

  • 866 Points 500 badge 2x thumb

Thanks for your response

Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
Photo of Swathy Sukumar

Swathy Sukumar

  • 866 Points 500 badge 2x thumb

Adam,

I have seen these examples and have curl as well but cant able to authenticate. I  am new to curl also.

Here examples I have read what I have understood that we are using the restAPI url in the post command and then we are using curl to invoke the seesion.

For eg we have done VDB provision with CLI so we got the restapi URL for the same. Now i want to know how i can bind with that.

We downloaded CURL as well.

Your help is much appreciated.

Regards,

Swathy


Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
Use these examples to create a session and authenticate. This stores the information in the cookies.txt file. 
https://docs.delphix.com/docs/reference/web-service-api-guide/api-cookbook-common-tasks-workflows-an...
Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
Full example:

DEIP="10.0.1.10"
USER="delphix_admin"
PASS="landshark"


# 1) Create Delphix API Session

curl -s -X POST -k --data @- http://${DEIP}/resources/json/delphix/session \
    -c ~/cookies.txt -H "Content-Type: application/json" <{
    "type": "APISession",
    "version": {
        "type": "APIVersion",
        "major": 1,
        "minor": 6,
        "micro": 0
    }
}
EOF


# 2) Delphix Login

curl -s -X POST -k --data @- http://${DEIP}/resources/json/delphix/login \
    -b ~/cookies.txt -H "Content-Type: application/json" <{
    "type": "LoginRequest",
    "username": "${USER}",
    "password": "${PASS}"
}
EOF


echo "+++++++++++++++++++++++++++++++++++"

# 3) Provision VDB

curl -X POST -k --data @- http://${DEIP}/resources/json/delphix/database/provision \
    -b cookies.txt -H "Content-Type: application/json" <{ 
    "container": {
        "group": "GROUP-2",
        "name": "EGVDB", 
        "type": "OracleDatabaseContainer"
    },
    "source": {
        "type": "OracleVirtualSource",
        "mountBase": "/mnt/provision",
        "allowAutoVDBRestartOnHostReboot": true
    },
    "sourceConfig": {
        "type": "OracleSIConfig",
        "databaseName": "EGVDB", 
        "uniqueName": "EGVDB", 
        "repository": "ORACLE_INSTALL-3",
        "instance": {
            "type": "OracleInstance",
            "instanceName": "EGVDB",
            "instanceNumber": 1
        }
    },
    "timeflowPointParameters": {
        "type": "TimeflowPointLocation",
        "timeflow": "ORACLE_TIMEFLOW-123",
        "location": "3043123"
    },
    "type": "OracleProvisionParameters"
}
EOF
(Edited)
Photo of Mouhssine SAIDI

Mouhssine SAIDI

  • 4,682 Points 4k badge 2x thumb
Hi,

To complete Adam's answer

The sample i've provided detailed the values each param used , but you may need to install one more tool like jq to extract specific values out of the engine jason's answer you will need to feed your api call with to achive an action (eg: in the provisioning one you need for example group ref, repository ref ...)

Regards,

Mouhssine
Photo of Swathy Sukumar

Swathy Sukumar

  • 866 Points 500 badge 2x thumb

Thanks for your response.

Do you have any demo with cURL?If you have could share with us. Still I am unable to work.

Regards,

Swathy

Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
Here is a complete working example. I just tested it.

#!/bin/bash
DEIP="10.0.1.10"
USER="delphix_admin"
PASS="delphix"

# 1) Create Delphix API Session
echo -e "\n\nCreating Session\n"
curl -s -X POST -k --data @- http://${DEIP}/resources/json/delphix/session \
    -c ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
    "type": "APISession",
    "version": {
        "type": "APIVersion",
        "major": 1,
        "minor": 8,
        "micro": 0
    }
}
EOF

# 2) Delphix Login
echo -e "\n\nLogging in\n"
curl -s -X POST -k --data @- http://${DEIP}/resources/json/delphix/login \
    -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
    "type": "LoginRequest",
    "username": "${USER}",
    "password": "${PASS}"
}
EOF
#3) List Databases
echo -e "\n\nGrabbing list of databases\n"
curl -X GET -k http://${DEIP}/resources/json/delphix/database  \
    -b ~/cookies.txt -H "Content-Type: application/json"
echo -e "\n\nCurl Script Complete\n"
(Edited)
Photo of Swathy Sukumar

Swathy Sukumar

  • 866 Points 500 badge 2x thumb

Hi

Still error is not resolved I have tried the same still getting the same error.

Thanks

Regards

Swathy

Photo of Mouhssine SAIDI

Mouhssine SAIDI

  • 4,682 Points 4k badge 2x thumb
Hi Swathy,

I ha be to check if you got any group with this number in your engine, to do so I need the output elsewhere it will be hard to help.

Can you ensure please that you followed this plan.

1) open browser
2) open a first tab and connect to the admin console
3) open a second tab in the same browser and go to this url "http://DEIP/resources/json/delphix/group" replace DEIP with the up of your engine
4) past the output to the community website

Regards,

Mouhssine
Photo of Mouhssine SAIDI

Mouhssine SAIDI

  • 4,682 Points 4k badge 2x thumb
Hi,

Let's try another plan please if you face problems to get the first one done.

Connect to your engine via ssh as delphix_admin and do the following please.

1) cd group
2) setopt trace=true
3) ls
4 past the output of the latest command in the community website

Regards,

Mouhssine
Photo of Swathy Sukumar

Swathy Sukumar

  • 866 Points 500 badge 2x thumb

Hi

This output I got after ls command:

Objects
=== GET /resources/json/delphix/group ===
=== RESPONSE ===
{
    "type": "ListResult",
    "status": "OK",
    "result": [
        {
            "type": "Group",
            "reference": "GROUP-34",
            "namespace": null,
            "name": "Source-Oracle-174",
            "description": "",
            "dataNode": "DATA_NODE-1"
        },
        {
            "type": "Group",
            "reference": "GROUP-37",
            "namespace": null,
            "name": "virtual-Oralce-138",
            "description": "",
            "dataNode": "DATA_NODE-1"
        }
    ],
    "job": null,
    "action": null,
    "total": 2,
    "overflow": false


Thanks,

Swathy

Photo of Mouhssine SAIDI

Mouhssine SAIDI

  • 4,682 Points 4k badge 2x thumb
Hi Swathy,

Finally figured it out.

You are using "TimeflowPointLocation" as time flow point this means that location parameter should have an scn value, but in your case you set is to "LATEST_SNAPSHOT" and this is only supported for "TimeflowPointSemantic" time flow point.

Please update the "timeflowPointParameters" in your script and set it type to "TimeflowPointSemantic" and you will be fine.

eg:
...
 "timeflowPointParameters": {
        "type": "TimeflowPointSemanticTimeflowPointLocation",
        "timeflow": "ORACLE_TIMEFLOW-38",
        "location": "LATEST_SNAPSHOT"
    },
...

Regards,

Mouhssine
Photo of Mouhssine SAIDI

Mouhssine SAIDI

  • 4,682 Points 4k badge 2x thumb
Hi,

Here is an example i wrot in the past, that need some work to sweet you.

But please check it befor just copy/past/run it, you will have to change the APIversion and check if you have to add new params itroduced with the new version on the API level 
#!/bin/bash
DE="192.168.247.XXX"
DELPHIX_ADMIN="delphix_admin"
DELPHIX_PASS="landshark"
VDB=$1
OPT=$2

get_session() {
curl -s -X POST -k --data @- http://${DE}/resources/json/delphix/session \
    -c ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
    "type": "APISession",
    "version": {
        "type": "APIVersion",
        "major": 1,
        "minor": 4,
        "micro": 3
    }
}
EOF
}

do_login() {
curl -s -X POST -k --data @- http://${DE}/resources/json/delphix/login \
    -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
    "type": "LoginRequest",
    "username": "${DELPHIX_ADMIN}",
    "password": "${DELPHIX_PASS}"
}
EOF
}

get_params() {
ref=`curl -s -X GET -k http://${DE}/resources/json/delphix/database  \
    -b ~/cookies.txt -H "Content-Type: application/json" | python -m json.tool | jq -r '.result[] | select(.name=="'$VDB'") | .reference'`
cont=`curl -s -X GET -k http://${DE}/resources/json/delphix/database  \
    -b ~/cookies.txt -H "Content-Type: application/json" | python -m json.tool | jq -r '.result[] | select(.name=="'$VDB'") | .provisionContainer'`
vsrc=`curl -s -X GET -k http://${DE}/resources/json/delphix/source  \
    -b ~/cookies.txt -H "Content-Type: application/json" | python -m json.tool | jq -r '.result[] | select(.name=="'$VDB'") | .reference'`
}

do_refresh() {
curl -s -X POST -k --data @- http://${DE}/resources/json/delphix/database/$ref/refresh  \
    -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
       "type": "OracleRefreshParameters",
       "timeflowPointParameters": {
               "type": "TimeflowPointSemantic",
               "container": "$cont",
               "location": "LATEST_SNAPSHOT"
       }
}

EOF
}

do_snapsync() {
curl -s -X POST -k --data @- http://${DE}/resources/json/delphix/database/$ref/sync  \
    -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
       "type": "OracleSyncParameters"
}

EOF
}

do_start() {
  curl -s -X POST -k http://${DE}/resources/json/delphix/source/${vsrc}/start \
    -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
    "type": "OracleStartParameters"
}

EOF
}

do_stop() {
  curl -s -X POST -k http://${DE}/resources/json/delphix/source/${vsrc}/stop \
    -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
    "type": "OracleStopParameters"
}

EOF
}

do_delete() {
  curl -s -X POST -k http://${DE}/resources/json/delphix/database/$ref/delete \
    -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
    "type": "OraclDeleteeParameters"
}

EOF
}

do_enable() {
  curl -s -X POST -k http://${DE}/resources/json/delphix/source/${vsrc}/enable \
    -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
    "type": "OracleEnableParameters"
}

EOF
}

do_disable() {
  curl -s -X POST -k http://${DE}/resources/json/delphix/source/${vsrc}/disable \
    -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
    "type": "OracleDisableParameters"
}

EOF
}

get_session
do_login
get_params
case $OPT in
start)
do_start
;;
stop)
do_stop
;;
refresh)
do_refresh
;;
snapsync)
do_snapsync
;;
delete)
do_delete
;;
enable)
do_enable
;;
disable)
do_disable
;;
*)
  echo "Unknown option: $OPT"
;; 
esac



Regards,

Mouhssine
Photo of Mouhssine SAIDI

Mouhssine SAIDI

  • 4,682 Points 4k badge 2x thumb
Hi,

Make a mixe of both for my base script it will need jq to be installed.


Regards,

Mouhssine
Photo of Swathy Sukumar

Swathy Sukumar

  • 866 Points 500 badge 2x thumb

Thank you so much


Photo of Mouhssine SAIDI

Mouhssine SAIDI

  • 4,682 Points 4k badge 2x thumb
welcome