CalcTree's API allows you to get even more value out of your calculation pages by allowing you to integrate them into your external workflows.
Currently, CalcTree's API is read-only. Here's a quick summary what you can and can't do with the API in it's current state:
What can you do with the API ✅
What can’t you do with the API ❌
API Key
Before you can use the CalcTree API, you need to generate an API key. To do so, follow these steps:
1. Clicking on "Settings & Members" in the top left corner of the CalcTree page
2. In the settings page, locate and click "API keys" in the top left corner
3. Click "Create API key" to create a new API key
4. A popup will appear, prompting you for the key name
Once you've given a name, please save the generated key securely. You won't be able to view this token key again.
Turning on API integration
Before you can start using the CalcTree API, you need to enable API integration. To do so, go to the calculation page that you would like to use. On the right, you will see a sidebar.
On the top right corner of the sidebar, click [+ Add]
Next, click on the API integration button
Now, your API has been added. Click on the arrow next to it and expand the details
From here, you can obtain the current page ID, which you will need to send a request
Using the API with Python without dependencies
First, you must define connection parameters:
API endpoint URL, request headers with API key and content type
👉 Code Sample
2. Request payload depends on an API endpoint. See below for an example of the 'body' for calculation page endpoint
To calculate values for the provided page ID. You must specify at least one input parameter to initiate the calculation. Afterward, you'll get back all parameters from the page, with their values updated based on the provided input.
For any input parameters not explicitly provided, the calculation will use the default values set on the page.
- pageID - the identifier for the page on which you'd like to perform a calculation.
- ctCells - a list of input parameters you'd like to use for calculating outputs. Each parameter has a name identical to the one set on the page, including spaces, and a formula represented as a string type. To input the number 12.25, use the string '12.25'.
Response syntax
Example curl
CalcTree python client
To make it easier to work with the CalcTree API, we've released a CalcTree API Python Client. To use it:
Install CalcTree client using pip:
pip install calctree
Once you’ve installed the client you can used it like in the example below:
👉 sample
Client API
run_calculation
To calculate values for the provided page ID. You must specify at least one input parameter to initiate the calculation. Afterward, you'll get back all parameters from the page, with their values updated based on the provided input.
For any input parameters not explicitly provided, the calculation will use the default values set on the page.
Request syntax:
Parameters
- page_id - the identifier for the page on which you'd like to perform a calculation.
- ct_cells - a list of input parameters you'd like to use for calculating outputs. Each parameter has a name identical to the one set on the page, including spaces, and a formula represented as a string type. To input the number 12.25, use the string '12.25'.
Response
CalculationResult class:
get_params(): Returns a list of all available parameters in the calculation result.
get_values(): Retrieves a list of all parameter values in the calculation result.
get_param_value(param_name): Get the value of a specific parameter by providing its name.
to_dict(): Converts the calculation result into a list of dictionaries, each containing parameter names and values.
This class provides methods to easily access and manage the results of calculations from the CalcTree API. Use get_params() to see all available parameters, get_values() to get all values, get_param_value(param_name) for a specific parameter's value, and to_dict() to convert the result into a dictionary format for further processing.