Run a Python Function multiple times
post
/py-scripts/v1/index-apply/{scriptName}
Runs a user-owned Python Function "times" times.
Request
Path Parameters
-
scriptName(required):
The name of the Python script
Response
200 Response
By default, returns the job result.
201 Response
If asyncFlag=true, returns the location header where the status of the job can be fetched.
Headers
400 Response
Invalid parameters specified, output exceeding size limit or other script execution error.
500 Response
Problem connecting to Broker, executing job or other unexpected error.
Examples
Example 1
The following example runs the script named compute_random_mean.
curl -i -X POST --header "Authorization: Bearer ${token}" \
--header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"times":10}' \
"<oml-cloud-service-location-url>/oml/api/py-scripts/v1/index-apply/compute_random_mean"
Response Headers
The response headers are the following:
HTTP/1.1 200 OK
Date: Wed, 26 Aug 2020 21:07:35 GMT
Content-Type: application/json
Content-Length: 196
Connection: keep-alive
Cache-Control: no-cache, no-store, private
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1;mode=block
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
Set-Cookie: JSESSIONID=node0685gs5zc7ijac22t5ofbfcxo653.node0; Path=/oml; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Response Body
The response body in JSON format is the following:
{"result":
[7.203244934421581,0.25926231827891333,7.081478226181048,5.4723224917572235,
8.707323061773764,3.3197980530117723,7.7991879224011464,
9.68540662820932,5.018745921487388,0.207519493594015]}
Example 2
The following example runs the script named test_seaborn_idx
.
curl -i -k -X POST --header "Authorization: Bearer ${token}" --header
'Content-Type: application/json' --header 'Accept: application/json' -d
'{"times": 2, "envName": "seaborn", "graphicsFlag": true}' "<oml-cloudservice-
location-url>/oml/api/py-scripts/v1/index-apply/test_seaborn_idx"
Response Body
The result of the REST endpoint is a JSON representation of the value returned from the Python script, which includes the image and the data. Image bytes are returned in PNG format.
{
"result": {
"0": {
"IMAGE": "iVBORw0KGgoAAAAN.....AAAAASUVORK5CYII=",
"DATA": "1",
"TIME": 1,
"TITLE": "Title 1",
"ID": 1
},
"1": {
"IMAGE": "iVBORw0KGgoAAAAN......AAABJRU5ErkJggg==",
"DATA": "2",
"TIME": 2,
"TITLE": "Title 2",
"ID": 1
}
}
}