Views:

Summary


With DPX 4.5.5 OVA and later a new REST interface has been added which can be used to control and query various aspects of the DPX server.

Step By Step

Linux CLI

Below is an description on how to start a job instance from a script or CLI using DPX RESTAPI. This description uses curl and assumes the jq (json parser) is installed on a Linux machine and a BASH shell is used

1) The First step is to get an authorization token, I am getting the token by authenticating rest and putting the token header  in a variable(token) for later use using the following command

token="Authorization: Bearer "$( curl --location -k --request POST 'https://<MASTERIP>/auth/login' --header 'Content-Type: application/json' --data '{"username": "<YOURUSER>","password": "<YOURPASSWORD>"}' | jq -r .refreshToken )

2)  Next step is to start a new instance of the job using a POST to the /job_instances endpoint and passing the following values via the request body:

job_instance_command_name - START, CANCEL etc
retention_days - Number of days to retain the catalog after completion.
job - Name of the job
job_instance_run_type - The type of this job_instance (e.g., BASE, DIFR, INCR) Always INCR for Agentless

curl --location -k --request post 'https://<MASTERIP>/app/api/job_instances' --header "$token" --header 'Content-Type: application/json' --data '{ "job_instance_command_name": "START","retention_days": 1,"job": "<JOBNAME>","job_instance_run_type": "INCR"}'| jq

Windows Powershell

The same can be accomplished using the Windows Powershell without any further add-ons or plugins

Note: When using the provided SSL certificate of DPX, the following command needs to be executed beforehand to allow https requests with self-signed certificates to be accepted:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }

1) Create a variable with the credentials

$body = "{`"username`": `"<YOURUSER>`", `"password`": `"<YOURPASSWORD>`" }"

2) Request the token and save it to the $token variable

$token = Invoke-RestMethod -Uri https://<MASTERIP>/auth/login -method 'POST' -Body $body -ContentType application/json | Select-Object -ExpandProperty refreshtoken

3) Create $header variable which will be used for the final request

$headers = @{
Authorization="Bearer $token"
}

4) Send the request to start the job instance

Invoke-RestMethod -Method POST -Header $headers -ContentType "application/json" -uri https://<MASTERIP>/app/api/job_instances -Body "{ `"job_instance_command_name`": `"START`",`"retention_days`": 1,`"job`": `"<JOBNAME>`",`"job_instance_run_type`": `"INCR`"}"

Other API calls

You can find a full list of possible API calls on your master server under the following URL:

http://<MASTERIP>:8095/api/webjars/swagger-ui/index.html?url=/api/openapi/openapi.yml#/

Comments (0)