Provide examples of how to interrogate the API endpoints remotely using cURL.
-
Prior to executing any cURL commands the user should export their
access_token
into their local environment -
The example token below has been shortened for readability
export TOKEN='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...UqbthpwM4_be4d1or2qpdd_w_3TjjDxiT85f3kvwWbI'
The user TOKEN
is then attached as part of the request header along with other information when issuing a cURL command.
Common Headers:
- Bearer Token:
-H "Authorization: Bearer ${TOKEN}"
- GET requests:
-H "Accept: application/json"
- POST, PUT, PATCH requests:
-H "Content-Type: application/json"
- Any request that includes request data as part of the body in JSON format (
-d ${DATA}
whereDATA
is in JSON format)
- Any request that includes request data as part of the body in JSON format (
The request header "preamble" will be excluded from the examples below for readability, but it is required for the cURL command to execute successfully within the appropriate context option (GET
, POST
, PUT
, PATCH
, DELETE
).
- GET paginated list of all used (but not deleted) canonical experiment numbers
- Access: role =
operator
- Access: role =
- GET detailed information about a single canonical number by ID
- Access: role =
operator
- Access: role =
- GET the current canonical experiment number which would be issued to the next experiment
- Access: user
is_active
- Access: user
- PUT a new current canonical experiment number
- Access: role =
operator
- Parameter (optional):
number
as integer- e.g.
/canonical-experiment-number/current?number=100
- e.g.
- Access: role =
- GET paginated list of all canonical experiment resource definitions
- Access: role =
operator
- Parameter (optional):
experiment_id
- e.g.
/canonical-experiment-resource?experiment_id=10
- e.g.
- Parameter (optional):
resource_id
- e.g.
/canonical-experiment-resource?resource_id=5
- e.g.
- Parameter (optional):
experiment_id
andresource_id
- e.g.
/canonical-experiment-resource?experiment_id=10&resource_id=5
- e.g.
- Access: role =
- GET detailed information about a single canonical canonical experiment resource definition by ID
- Access: role =
operator
- Access: role =
- GET paginated list of all experiments
- Access: role =
operator
- Access: user has project membership in the project containing the experiment
- Parameter (optional):
search
- e.g.
/experiments?search=wheeler
- e.g.
- Access: role =
- POST create new experiment
- Access: user has experiment membership
- Data (required):
-
description
- experiment description as string -
name
- experiment name as string -
project_id
- ID of project which to add experiment to as integer -
Example:
{ "description": "my project description", "name": "my project", "project_id": 5 }
-
- GET detailed information about a single experiment by ID
- Access: role =
operator
- Access: user has project membership in the project containing the experiment
- Access: role =
- GET: list of
experiment_members
for a single experiment by ID- Access: user has experiment membership
- PUT: update
experiment_members
for a single experiment by ID- Access: user has experiment membership
- Data (optional):
-
experiment_members
- experiment members by user ID (users must have membership within the project associated to the experiment) as array of integers -
Example:
{ "experiment_members": [1, 3, 10] }
-
- GET: list of
experiment_resources
for a single experiment by ID- Access: user has experiment membership
- PUT: update
experiment_resources
for a single experiment by ID- Access: user has experiment membership
- Data (optional):
-
experiment_resources
- array of resource IDs -
Example:
{ "experiment_resources": [1, 2] }
-
- GET paginated list of all projects
- Access: user is active
- Parameter (optional):
search
- e.g.
/projects?search=demo
- e.g.
- POST create new project
- Access: role =
pi
- Data (required):
-
description
- project description as string -
is_public
- project is publicly viewable as boolean -
name
- project name as string -
Example:
{ "description": "my project description", "is_public": true, "name": "my project" }
-
- Access: role =
- GET detailed information about a single project by ID
- Access: role =
operator
- Access: user has project membership
- Access: user is active and project
is_public
(limited view)
- Access: role =
- GET: list of
experiments
for a single project by ID- Access: user has project membership
- GET: list of
project_members
andproject_owners
for a single project by ID- Access: user has project membership
- PUT: update
project_members
and/orproject_owners
for a single project by ID- Access: user is
project_creator
- Access: user is
project_owner
- Data (optional):
-
project_members
- project members by user ID as array of integers -
project_owners
- project owners by user ID as array of integers -
Example:
{ "project_members": [1, 3, 10], "project_owners": [1] }
-
- Access: user is
- GET paginated list of all resources
- Access: user is active
- Parameter (optional):
search
- e.g.
/resources?search=ugv
- e.g.
- POST create new resource
- Access: role =
operator
- Data (* denotes required):
-
*
description
- resource description as string -
hostname
- resource hostname as string -
ip_address
- resource IP Address as string -
*
is_active
- resource is active as boolean (default =False
) -
location
- resource location as string -
*
name
- resource name as string -
ops_notes
- operator notes as string -
*
resource_class
- resource class as string (default = ``) -
*
resource_mode
- resource mode as string -
*
resource_type
- resource type as string -
Example:
{ "description": "Centennial Campus Node 1", "hostname": "aerpaw182", "ip_address": "123.23.34.678", "is_active": true, "location": "Centennial Campus", "name": "CC1", "ops_notes": "", "resource_class": "canonical", "resource_mode": "testbed", "resource_type": "AFRN" }
-
- Access: role =
- GET detailed information about a single resource by ID
- Access: user is active
- GET paginated list of all experiment sessions
- Access: role =
operator
- Parameter (optional):
experiment_id
- e.g.
/sessions?experiment_id=10
- e.g.
- Access: role =
- GET detailed information about a single experiment session by ID
- Access: role =
operator
- Access: role =
- GET paginated list of all user experiment definitions
- Access: role =
operator
- Parameter (optional):
experiment_id
- e.g.
/user-experiment?experiment_id=10
- e.g.
- Parameter (optional):
user_id
- e.g.
/user-experiment?user_id=5
- e.g.
- Parameter (optional):
experiment_id
anduser_id
- e.g.
/user-experiment?experiment_id=10&user_id=5
- e.g.
- Access: role =
- GET detailed information about a single user experiment definition by ID
- Access: role =
operator
- Access: role =
- GET paginated list of all user project definitions
- Access: role =
operator
- Parameter (optional):
project_id
- e.g.
/user-project?project_id=10
- e.g.
- Parameter (optional):
user_id
- e.g.
/user-project?user_id=5
- e.g.
- Parameter (optional):
project_id
anduser_id
- e.g.
/user-project?project_id=10&user_id=5
- e.g.
- Access: role =
- GET detailed information about a single user project definition by ID
- Access: role =
operator
- Access: role =
- GET paginated list of all users
- Access: user is active
- Parameter (optional):
search
- e.g.
/projects?search=bob
- e.g.
- GET detailed information about a single user by ID
- Access: user as self
- Access: user is active (limited view)
- GET detailed information about tokens by user by ID
- Access: user as self
- POST generate a new
access_token
-
Access: user as self
-
Data (required):
refresh_token
-
NOTE: this endpoint does not update data in the User's profile
-
Example:
{ "refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...n3VM2kzzXOF4AWOSb4M3QmEgitnByaokmecTO423vXI" }
-
Set up basic exports
export API_URL='http://aerpaw-dev.renci.org:8000/api'
export ACCESS_TOKEN='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...yYACY9QZqmKXppXluUeW_A95lZVLqm9Xt0AXFCAV1Xg'
Define a request body in JSON format for the project to POST
PROJECT='{
"description": "demo project description",
"is_public": true,
"name": "demo project"
}'
Use the POST command to create a new project
$ curl -X "POST" -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "Content-Type: application/json" -d ${PROJECT} "${API_URL}/projects"
{
"created_date": "2022-06-28T20:56:25.581196-04:00",
"description": "demo project description",
"is_public": true,
"last_modified_by": 1,
"modified_date": "2022-06-28T20:56:25.581243-04:00",
"name": "demo project",
"project_creator": 1,
"project_id": 3,
"project_members": [],
"project_owners": [
{
"granted_by": 1,
"granted_date": "2022-06-28T20:56:25.586423-04:00",
"user_id": 1
}
]
}
From the above we can see a new project was created with project_id=3
Search for "Yufeng" from the users endpoint
$ curl -X "GET" -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "Accept: application/json" "${API_URL}/users?search=yufeng"
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"display_name": "Yufeng Xin",
"email": "[email protected]",
"user_id": 2,
"username": "[email protected]"
}
]
}
Yufeng has a user_id=2
which is used to add him to the project members
Define a request body in JSON format for project members to PUT
PROJECT_MEMBERS='{
"project_members": [2]
}'
And then use the PUT command to add the project members
$ curl -X "PUT" -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "Content-Type: application/json" -d ${PROJECT_MEMBERS} "${API_URL}/projects/3/membership"
{
"project_members": [
{
"granted_by": 1,
"granted_date": "2022-06-28T21:04:05.604689-04:00",
"user_id": 2
}
],
"project_owners": [
{
"granted_by": 1,
"granted_date": "2022-06-28T20:56:25.586423-04:00",
"user_id": 1
}
]
}
Next define an experiment to the project with JSON
EXPERIMENT='{
"description": "demo experiment description",
"name": "demo experiment",
"project_id": 3
}'
And POST to the experiments endpoint
$ curl -X "POST" -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "Content-Type: application/json" -d ${EXPERIMENT} "${API_URL}/experiments"
{
"canonical_number": 1,
"created_date": "2022-06-28T21:08:40.290333-04:00",
"description": "demo experiment description",
"experiment_creator": 1,
"experiment_id": 3,
"experiment_members": [
{
"granted_by": 1,
"granted_date": "2022-06-28T21:08:40.292835-04:00",
"user_id": 1
}
],
"experiment_state": "saved",
"is_canonical": false,
"is_retired": false,
"last_modified_by": 1,
"modified_date": "2022-06-28T21:08:40.290350-04:00",
"name": "demo experiment",
"project_id": 3,
"resources": []
}
We can see that a new experiment was created with experiment_id=3
and it's linked to project_id=3
Finally find a canonical resource named "CC1" to add to the experiment
$ curl -X "GET" -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "Accept: application/json" "${API_URL}/resources?search=cc1"
"count": 1,
"next": null,
"previous": null,
"results": [
{
"description": "Centennial Campus Node 1",
"is_active": true,
"location": "Centennial Campus",
"name": "CC1",
"resource_class": "canonical",
"resource_id": 1,
"resource_mode": "testbed",
"resource_type": "AFRN"
}
]
}
CC1 has resource_id=1
, define some JSON to experess this
EXP_RESOURCES='{
"experiment_resources": [1]
}'
Use PUT to add the resource to the experiment
$ curl -X "PUT" -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "Content-Type: application/json" -d ${EXP_RESOURCES} "${API_URL}/experiments/3/resources"
[
{
"description": "Centennial Campus Node 1",
"is_active": true,
"location": "Centennial Campus",
"name": "CC1",
"resource_class": "canonical",
"resource_id": 1,
"resource_mode": "testbed",
"resource_type": "AFRN"
}
]
We can see the array of resource associate to the project (currently just CC1)
With all of the resources for the experiment of class "canonical", the experiment itself should also be denoted as "canonical"
$ curl -X "GET" -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "Accept: application/json" "${API_URL}/experiments/3"
{
"canonical_number": 1,
"created_date": "2022-06-28T21:08:40.290333-04:00",
"description": "demo experiment description",
"experiment_creator": 1,
"experiment_id": 3,
"experiment_members": [
{
"granted_by": 1,
"granted_date": "2022-06-28T21:08:40.292835-04:00",
"user_id": 1
}
],
"experiment_state": "saved",
"is_canonical": true,
"is_retired": false,
"last_modified_by": 1,
"modified_date": "2022-06-28T21:15:06.635979-04:00",
"name": "demo experiment",
"project_id": 3,
"resources": [
1
]
}