GetCalculation
Retrieves detailed information about a specific calculation
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
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
Sample 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
}
}
}
}
Sample Header
{
"x-api-key": "your_API_key"
}
Sample Variables
{
"workspaceId": "your-workspace-id",
"calculationId": "your-calculation-id",
"revisionId": "your-revision-id"
}
Sample Response
{
"data": {
"calculation": {
"calculationId": "12345",
"statements": [
{
"statementId": "s1",
"title": "Moment of Inertia Calculation",
"engine": "python",
"formula": "I = (b * h^3) / 12",
"namedValues": [
{
"name": "b",
"value": 300
},
{
"name": "h",
"value": 500
}
]
},
{
"statementId": "s2",
"title": "Shear Force Calculation",
"engine": "python",
"formula": "V = F / A",
"namedValues": [
{
"name": "F",
"value": 5000
},
{
"name": "A",
"value": 150
}
]
}
]
}
}
}
Description of Returned Fields
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 used for the statement (e.g., Python).
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:
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
, andrevisionId
are correct.Unless working with a specific revision, set
revisionID
toffffffff
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 thenamedValue
list. Refer to the Calculate for updating values.
Last updated