This article describes how to start a Job using the Domino REST API while passing arguments to your script. The general syntax and description of required and optional attributes for this API call can be found in Domino's API documentation.
For this example, we'll be looking at a simple script which takes your name and location as arguments and prints a friendly greeting. Parameters to a Job are treated as command-line arguments to your script. In Python, we'll reference these with sys.argv[]
, and in R we can use commandArgs()
.
Sample Scripts for Job
Example in Python:
# Get Arguments
import sys
name = sys.argv[1]
location = sys.argv[2]
# Print Greeting
print(f"Greetings, {name}. How's the weather in {location} today?")
Example in R:
# Get Arguments
args = commandArgs(trailingOnly=TRUE)
user_name = args[1]
user_location = args[2]
# Print Greeting
print(paste("Greetings, ",user_name, " How's the weather in ", user_location, " today?"))
API Endpoint
We can start this Job using the API endpoint:
https://<your domino url>/v1/projects/<username>/<project_name>/runs
Sample cURL requests
cURL with R script:
curl --request POST 'https://<your domino url>/v1/projects/<username>/<projectname>/runs' \
--header 'Content-Type: application/json' \
--header 'X-Domino-Api-Key: <your API key>' \
--data-raw '{
"command": [
"job-w-args.R",
"Domino User",
"My Location"
],
"isDirect": false,
"title": "Sample of starting an R job with arguments!"
}'
cURL with Python script:
curl --request POST 'https://<your domino url>/v1/projects/<username>/<projectname>/runs' \
--header 'Content-Type: application/json' \
--header 'X-Domino-Api-Key: <your API key>' \
--data-raw '{
"command": [
"job-w-args.py",
"Domino User",
"My Location"
],
"isDirect": false,
"title": "Sample of starting a Python job with arguments!"
}'
Output
If I use my name and location, I can see my greeting printing in the stout.txt file:
Greetings, Ashley. How's the weather in Oregon today?
There are many other optional attributes and languages you can use when starting jobs with the Domino REST API, check out our API documentation for more ideas!
Comments
0 comments
Please sign in to leave a comment.