1.3.1 Changing the agent of an activity corresponding to a specific step in My Workflow

(1) Obtaining the workflow context ID

Use the workflow Execution ID obtained in <% ctx().st2.action_execution_id %>* to retrieve the context ID of the currently running workflow. An example of API execution is shown below.

<Example> api/v1/practice-contexts

# curl -XGET "Ops I URL/api/v1/practice-contexts?filterBy=executionId%3Aeq%3AMy Workflow Execution ID" ¥
-H "X-OpsI-Token: Ops I token"

The context ID can be obtained from the “id” included in the API response. For details, see “dtos.ContextDTO” in the response details for “GET /practice-contexts” in the API details under “Standard API functions (v1)”.

*For more information, please refer to the official StackStorm page.
https://docs.stackstorm.com/3.8/orquesta/stackstorm.html#stackstorm-context


(2) Obtaining detailed My Workflow information

Use the context ID to retrieve the workflow details and obtain the ID of the parent schedule object. An example of API execution is shown below.

<Example> api/v1/practice-contexts/{id}

# curl -XGET "Ops I URL/api/v1/practice-contexts/Context id" ¥
-H "X-OpsI-Token: Ops I token"

The ID of the parent schedule object can be obtained from the “schedule” field included in the API response. For details, see “dtos.ContextDTO” in the response details for “GET /practice-contexts/{id}” in the API details under “Standard API functions (v1)”.

(3) Obtaining schedule information

Use the ID of the parent schedule object to retrieve the schedule details.
The parent schedule object is the schedule associated with the workflow, called as the parent activity.
The schedule details also includes information on child schedules corresponding to each step’s activity. Identify the child schedule corresponding to the step for which you want to update the assignee, and retrieve its ID. An example of the API call is shown below:

<Example> /api/v1/schedules/{id}

# curl -XGET "Ops I URL/api/v1/schedules/ID of the parent schedule object" ¥
-H "X-OpsI-Token: Ops I token"

You can retrieve the details of the schedule to be updated, which are included in the parent schedule object’s details, from the “children” section in the API response.
To identify the step for which you want to update the assignee, verify that the “activity” field in “dtos.ChildSchedule” under “children” in the response matches the name of the activity you want to update. The “id” in “dtos.ChildSchedule” for the identified step is the ID of the schedule object to be updated. For details, see “dtos.ScheduleDTO” and “dtos.ChildSchedule” in the response details for “GET /schedules/{id}” in the API details under “Standard API functions (v1)”.

(4) Change the agent of My Workflow from the information in the schedule

Use the ID of the schedule object to be updated to set the user ID in the assignee field of the target schedule, thereby changing the activity assignee. An example of API execution is shown below.

<Example> api/v1/schedules/{id}

# curl -XPUT "Ops I URL/api/v1/schedules/ID of the schedule object to be updated" ¥
-H "X-OpsI-Token: Ops I token" ¥
-H "Content-Type: application/json" -d @sample.json

Here, specify the user ID in the “assignedTo” field (the assignee field of the schedule to be updated) of the “dtos.ScheduleDTO” in the API request body. For details, see “dtos.UpdateScheduleDTO” in the request details for “PUT /schedules/{id}” in the API details under “Standard API functions (v1)”.

You can retrieve the user ID for a specific user name using the “GET /api/v1/users” API. An example of the API call is shown below:

<Example> api/v1/users

GET /api/v1/users?filterBy=username:like:admin

You can retrieve the user ID from the “id” included in the response. For details, see “dtos.UserDTO” in the response details for “GET /users” in the API details under “Standard API functions (v1)”.