> For the complete documentation index, see [llms.txt](https://calctree.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calctree.gitbook.io/docs/integrations/graphql-api/queries/getcalculation.md).

# GetCalculation

Retrieves detailed information about a specific calculation

## GetCalculation

The GetCalculation query retrieves detailed information about a specific calculation in a CalcTree workspace, including its statements, formulas, and values

This query allows you to fetch the details of a calculation by specifying:

* The workspace where the calculation is stored
* The calculation itself
* A specific revision of the calculation

It returns the calculation’s ID along with all statements and their associated properties.

### Input Parameters

| Parameter       | Type  | Required | Description                               |
| --------------- | ----- | -------- | ----------------------------------------- |
| `workspaceId`   | `ID!` | Yes      | The unique ID of the CalcTree workspace   |
| `calculationId` | `ID!` | Yes      | The unique ID of the calculation          |
| `revisionId`    | `ID!` | Yes      | The unique ID of the revision to retrieve |

{% hint style="info" %}
**calculationId and pageId**

The 'calculationId' refers to the ID of the calculation constructed on a page. It is the same as the pageId, which is the unique ID of the page a calculation is on. The pageId appears as the URL address of any given page: <https://app.calctree.com/edit/workspaceId/pageId.\\>
\
The pageId can be found in the integrations pane of any page as well.
{% endhint %}

#### Sample Query

```graphql
query GetCalculation($workspaceId: ID!, $calculationId: ID!, $revisionId: ID!) {
  calculation(workspaceId: $workspaceId, calculationId: $calculationId, revisionId: $revisionId) {
    calculationId
    statements {
      statementId
      title
      engine
      formula
      namedValues {
        name
        value
      }
    }
  }
}
```

#### Sample Header

```
{
  "x-api-key": "your_API_key" 
}
```

#### Sample Variables

```json
{
  "workspaceId": "your-workspace-id",
  "calculationId": "your-calculation-id",
  "revisionId": "your-revision-id"
}
```

{% hint style="info" %}
**Revision ID**

Every calculation in CalcTree has multiple revisions over time, allowing you to track and retrieve changes at any point.

* To fetch the **latest version**, you can use an all-`f` string such as `"ffffffffff"` for the `revisionId`. This will always return the most recent revision.
* If you want to **work with a specific version**, you must provide the exact `revisionId` from a previous response. When you fetch or update a calculation, you'll receive the current `revisionId`—store and reuse this for future operations to maintain consistency.
* UI elements to help navigate through calculation revisions will be added soon.
  {% endhint %}

#### Sample Response

```json
{
  "data": {
    "calculation": {
      "calculationId": "12345",
      "statements": [
        {
          "statementId": "s1",
          "title": "Moment of Inertia Calculation",
          "engine": "mathjs",
          "formula": "I = (b * h^3) / 12",
          "namedValues": [
            {
              "name": "b",
              "value": 300
            },
            {
              "name": "h",
              "value": 500
            }
          ]
        },
        {
          "statementId": "s2",
          "title": "Shear Force Calculation",
          "engine": "mathjs",
          "formula": "V = F / A",
          "namedValues": [
            {
              "name": "F",
              "value": 5000
            },
            {
              "name": "A",
              "value": 150
            }
          ]
        }
      ]
    }
  }
}
```

### Description of Returned Fields

| Field           | Type               | Description                                                                                                 |
| --------------- | ------------------ | ----------------------------------------------------------------------------------------------------------- |
| `calculationId` | `String`           | The unique ID of the retrieved calculation.                                                                 |
| `statements`    | `Array`            | An array of statements included in the calculation.                                                         |
| `statementId`   | `String`           | The unique ID of the statement.                                                                             |
| `title`         | `String`           | The title of the statement, in the platform UI this is referred to as '**Display Name**'.                   |
| `engine`        | `String`           | The execution engine — one of `mathjs`, `multiline_mathjs`, `python`, `excel`, `dataset`, `connection`.     |
| `formula`       | `String`           | The formula used in the statement, this shows the **'Name'** = **'Formula'** as per these fields in the UI. |
| `namedValues`   | `Array of Objects` | An array of name-value pairs representing variables used in the formula.                                    |
| `name`          | `String`           | This shows the Name of a particular statement.                                                              |
| `value`         | `Number`           | The current result value of a particular statement.                                                         |

### Usage Example

Here’s how to use this query with an example in **Python**:

```python
import requests

# Define the API endpoint and your API key
url = "https://graph.calctree.com/graphql"
headers: {
          "Content-Type": "application/json",
          "x-api-key": apiKey,
        }

# Define the GraphQL query and variables
query = """
query GetCalculation($workspaceId: ID!, $calculationId: ID!, $revisionId: ID!) {
  calculation(workspaceId: $workspaceId, calculationId: $calculationId, revisionId: $revisionId) {
    calculationId
    statements {
      statementId
      title
      engine
      formula
      namedValues {
        name
        value
      }
    }
  }
}
"""
variables = {
    "workspaceId": "your-workspace-id",
    "calculationId": "your-calculation-id",
    "revisionId": "your-revision-id"
}

# Make the POST request
response = requests.post(url, json={"query": query, "variables": variables}, headers=headers)

# Print the response
print(response.json())

```

### Tips for Using the Query

* Ensure your `workspaceId`, `calculationId`, and `revisionId` are correct.
* Unless working with a specific revision, set `revisionId` to an all-`f` string such as `ffffffffff` to access the latest version of the calculation.
* Use the `namedValues` array to understand name and values of a particular statement.
* `namedValues` are only response outputs however, you can not update names or values using the `namedValue` list. Refer to the [Calculate](https://calctree.gitbook.io/docs/integrations/graphql-api/queries/calculate) for updating values.
