Computation API

Prerequisites

  • Token with capsule scope

  • The computation ID to pass to the API call

The computation ID can only be accessed from the response from the API calls. A typical use cases are to use List capsule computations API to locate the computation ID from a capsule or Run capsule API to start a new computation. Both of the methods will have the computations ID in the response body that can use in computations API for further tracking and getting the results.

Get computation API

GET https://{domain}codeocean.com/api/v1/computations/{computations_id}

Path Parameters

NameTypeDescription

{domain}*

String

Your VPC domain

{computations_id}*

String

Computation's id

Headers

NameTypeDescription

Content-Type*

String

application/json

-u*

String

\ '${API Token from Code Ocean}:\' \

{
  "id": string - the computation internal id,
  "created": float64 - computation creation time,
  "name": string - the display name of the computation,
  "run_time": int - the total run time in seconds,

  "parameters": [
    {
      "name": string parameter name,
      "value": string parameter value
    },
    {
      "name": string parameter name,
      "value": string parameter value
    }
  ],
  "result_size": float64 - result size,
  "state": string - initializing,running,finalizing, completed
}
Example of getting computation API:

Request Example

curl --location --request GET 'https://acmecorp.codeocean.com/api/v1/computations/{computations_id}' \
--header 'Content-Type: application/json' \
-u \'${CUSTOM_KEY}:\'

use this example, please change the domain to your VPC instead of acmecorp, ${CUSTOM_KEY} to your API token, and use your computation's id.

Response Example

{
    "created":1646687806,
    "end_status":"succeeded",
    "has_results":true,
    "id":"66095e3a-0747-4ec5-b8b1-95b89a428536",
    "name":"Run 6687806",
    "run_time":5,
    "state":"completed"
}

List computation result files API

POST https://{domain}codeocean.com/api/v1/computations/{computations_id}/results

Path Parameters

NameTypeDescription

{domain}*

String

Your VPC domain

{computations_id}*

String

Computation's id

Headers

NameTypeDescription

Content-Type*

String

application/json

-u*

String

\ '${API Token from Code Ocean}:\' \

Request Body

NameTypeDescription

path*

String

string - the path of the folder. The empty path will retrieve the result root folder.

{
  "items": - array
    [
      {
        "name": string - the name of the entry,
        "path": string - full path to the item,
        "size": int64 - the item size in bytes (only available for files),
        "type": file, folder - the type of the item
      }
    ]
}
Example of listing computation result files API:

Request Example

curl --location --request POST 'https://acmecorp.codeocean.com/api/v1/computations/{computations_id}/results' \
--header 'Content-Type: application/json' \
-u \'${CUSTOM_KEY}:\' \
--data-raw '{ 
    "path": ""
}'

use this example, please change the domain to your VPC instead of acmecorp, ${CUSTOM_KEY} to your API token, and use your computation's id.

Response Example

{
  "items":
    [
      {
        "name":"fig1.png",
        "path":"fig1.png",
        "size":34003,
        "type":"file"
      },
      {
        "name":"output",
        "path":"output",
        "size":20,
        "type":"file"
      }
    ]
}

Get result file download URL API

GET https://{domain}codeocean.com/api/v1/computations/{computations_id}/results/download_url?path={PATH_TO_FILE}

Path Parameters

NameTypeDescription

{domain}*

String

Your VPC domain

{computations_id}*

String

Computation's id

{PATH_TO_FILE}*

String

path of the file under /results

Headers

NameTypeDescription

Content-Type*

String

application/json

-u*

String

\ '${API Token from Code Ocean}:\' \

{}

You can use List computation result files API to find the path of the file.

Example of listing computation result files API:

Request Example

curl --location --request GET 'https://acmecorp.codeocean.com/api/v1/computations/66095e3a-0747-4ec5-b8b1-95b89a428536/results/download_url?path=fig1.png' \
--header 'Content-Type: application/json' \
-u \'${CUSTOM_KEY}:\'

use this example, please change the domain to your VPC instead of acmecorp, ${CUSTOM_KEY} to your API token, and use your computation's id and the file path.

Response Example

{
    "url":
        "https://s3.amazonaws.com/acmecorp-s3resultsbucket-jlfcqiv031u3/9b17d7b7-8b48-461a-95c6-ddb1a00a4e49/1d8288da-0785-4e4f-aa37-2d1db3636bc4/66095e3a-0747-4ec5-b8b1-95b89a428536/fig1.png?X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=ASIASEPVU66XOZU3BPAN%2F20220317%2Fus-east-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20220317T144814Z\u0026X-Amz-Expires=3600\u0026X-Amz-Security-Token=IQoJb3JpZ2luX2VjECkaCXVzLWVhc3QtMSJGMEQCIHZsKuwxNa%2B2bFGw8MPV%2B5Th%2Fc6za2DHh6ACEJifi8LHAiBS2%2FVM%2BVvXaXuUyUwJvTOyd7srTkKROVVqqBJfn6rN9iqDBAii%2F%2F%2F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ec180d7c08f83a589cb34310d82a8b98e382a47a2250d88345c46e1c"
}

Last updated