> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opigno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetching Time Spent Records

The API provides two ways to retrieve time spent records:

1. The time a user spent on a specific **attempt**
2. The \*\*cumulative \*\*time spent across all attempts associated with a specific learning item (e.g., activity, module, or training), or across the entire platform.

<Note>
  The API always returns the time spent value in seconds. Formatting the output should be handled on the client platform.
</Note>

## 🧪 Attempt-Level Time Spent

Time spent for a specific attempt is available in the `AttemptMetrics` object, accessible via the `Attempt -> metrics` field. This applies to all **learning items** (e.g. trainings, modules activities).

See the example below:

<CodeGroup>
  ```filename GraphQL [expandable] theme={null}
  query getLearningPath {
    getLearningPath(lpId: 7) {
      navigation {
        edgeRid
        title
        attempt {
          metrics {
            globalScore
            progress
            status
            timeSpent
          }
        }
      }
      training {
        title
        attempt {
          metrics {
            globalScore
            progress
            status
            timeSpent
          }
        }
      }
    }
  }
  ```

  ```File Query result [expandable] theme={null}
  {
      "data": {
          "getLearningPath": {
              "navigation": [
                  {
                      "edgeRid": "177",
                      "title": "Module 1",
                      "attempt": {
                          "metrics": {
                              "globalScore": 100,
                              "progress": 100,
                              "status": "PASSED",
                              "timeSpent": 154
                          }
                      }
                  },
                  {
                      "edgeRid": "178",
                      "title": "Module 2",
                      "attempt": {
                          "metrics": {
                              "globalScore": 100,
                              "progress": 100,
                              "status": "PASSED",
                              "timeSpent": 202
                          }
                      }
                  }
              ],
              "training": {
                  "title": "Test training 2123",
                  "attempt": {
                      "metrics": {
                          "globalScore": 100,
                          "progress": 100,
                          "status": "PASSED",
                          "timeSpent": 356
                      }
                  }
              }
          }
      }
  }
  ```
</CodeGroup>

As shown in the example above, the `attempt` field is available for both training and navigation items. Within it, you’ll find the time spent (in seconds) for each attempt.

## 📊 Cumulative Time Spent

Cumulative time spent can be retrieved using the `getCumulativeTimeSpent` query. This query accepts several optional arguments that can be combined to filter the results.\
\
**Query Arguments**

| Argument          | Type | Required | Description                                                                                     |
| :---------------- | :--- | :------- | :---------------------------------------------------------------------------------------------- |
| `userContextUuid` | ID   | No       | The user context UUID. If omitted, the user context from the API request will be used.          |
| `lpId`            | ID   | No       | The learning path ID.                                                                           |
| `edgeRid`         | ID   | No       | The edge revision ID (e.g., for a specific activity or module). Requires `lpId` to be provided. |
| `startDate`       | Date | No       | Start date in `YYYY-MM-DD` format. Must be used together with `endDate`.                        |
| `endDate`         | Date | No       | End date in `YYYY-MM-DD` format. Must be used together with `startDate`.                        |

## **🧾 Usage Examples**

By specifying the appropriate arguments, you can retrieve cumulative time spent data for a variety of use cases:

* ⏱️ **Cumulative time spent on a specific learning item (activity or module)**, optionally filtered by date range

<CodeGroup>
  ```filename GraphQL theme={null}
  query getCumulativeTimeSpent {
      getCumulativeTimeSpent (userContextUuid: "a1b2c3d4-e5f6-7890-abcd-ef1234567890", lpId: 7, edgeRid: 154)
  }
  ```

  ```File Query result theme={null}
  {
      "data": {
          "getCumulativeTimeSpent": 154
      }
  }
  ```
</CodeGroup>

* 📘 **Cumulative time spent within a learning path**, optionally filtered by date range

<CodeGroup>
  ```GraphQL GraphQL theme={null}
  query getCumulativeTimeSpent {
      getCumulativeTimeSpent (userContextUuid: "a1b2c3d4-e5f6-7890-abcd-ef1234567890", lpId: 8, startDate: "2025-05-14", endDate: "2025-05-16")
  }
  ```

  ```File Query result theme={null}
  {
      "data": {
          "getCumulativeTimeSpent": 611
      }
  }
  ```
</CodeGroup>

* 🌐 **Cumulative time spent by a user across the entire platform**, optionally filtered by date range

<CodeGroup>
  ```GraphQL GraphQL theme={null}
  query getCumulativeTimeSpent {
      getCumulativeTimeSpent (userContextUuid: "a1b2c3d4-e5f6-7890-abcd-ef1234567890", startDate: "2025-05-14", endDate: "2025-05-16")
  }
  ```

  ```File Query result theme={null}
  {
      "data": {
          "getCumulativeTimeSpent": 1083
      }
  }
  ```
</CodeGroup>
