Testsigma allows creating or updating the environment parameters and their values via API. It is possible to do so using API endpoints or using the cURL command. An example is shown below using Postman. To do so the following steps has to be followed:


1. Creating an API key:

A “Bearer Token” type of authorization is required to access the environment parameters. And an API Key generated in Testsigma should be used as a bearer token for authorization while interacting with the global environment parameters using API.
An API Key can be created by navigating to the Settings > API Keys from the left vertical tab. We can create a new API Key using the create button on the top right corner or use an existing Key.

 

The below image shows the details of an API Key generated in Testsigma.

 



2. Get all environment details: 

Here we use the URL (https://app.testsigma.com/api/v1/environments/) to GET all the details of the existing environments. It is required to pass the authorization as Bearer Token and basic headers to obtain the details of all the environments present. This includes the environments in all the projects. The below image shows the response obtained.


It can be seen that each environment is associated with an id. This id is used to GET the specific environment details while fetching, creating, or updating the parameter values.


We can also use the CURL command to GET all the details of the existing environments using the syntax below.

curl --request GET "https://app.testsigma.com/api/v1/environments" --header "Authorization: Bearer <API_Key>"



3. Get specific environment details:

Here we use the URL (https://app.testsigma.com/api/v1/environments/<EnvironmentID>) to GET all the specific environment details. It is required to pass the authorization as Bearer Token and basic headers to obtain the details of the environment. The below image shows the response obtained.



We can also use the CURL command to GET the specific environment details using the syntax below.


curl --request GET "https://app.testsigma.com/api/v1/environments/<ENVIRONMENT_ID" --header "Authorization: Bearer <API_Key>"



4. Get Project id:

To update the global parameters, it is essential to know the project in which the environment is present. To get the project id we have to navigate to the Project Settings > Project details and view the address bar. The number shown here is the project id. project

 The below picture shows an example of how to fetch the project id <PROJECT ID>.




5. Updating Global parameter Value

We use the PUT method to update the existing parameter value or add a new Global parameter. To do so using Postman we have to make sure to:

>> Enter https://app.testsigma.com/api/v1/environments/<ENVIRONMENT ID> in the URL field with the environment id (from Step 2).

>> Select the Authorization as Bearer token and add the API key (from Step 1)

>> Select PUT as the API call method

>> Select the content type as JSON

>> Add the BODY content in JSON format as given below, with new values to Global Parameters.

{

"projectId":"<PROJECT ID>",

"parameters":{

    "env_param1":"test-value1",

    "env_param2":"test-value2",

    "env_param_new":"<NEW VALUE>"

    }

}

 

The pictures below show the same in the Postman window and the updated Global Parameter values in the Testsigma app.




We can also use the CURL command to add new parameters or update the existing parameter values. It is required to pass the <API_KEY>, <ENVIRONMENT_ID>, <PROJECT_ID>, <ENVIRONMENT_NAME>, <ENVIRONMENT_DESCRIPTION>in the cURL syntax is given below.


curl --request PUT "https://app.testsigma.com/api/v1/environments/<ENVIRONMENT_ID>" --header "Authorization: Bearer <API_Key>" --header "Content-Type: application/json" --data-raw "{\"name\":\"<ENVIRONMENT NAME>\",\"description\":\"<ENVIRONMENT_DESCRIPTION>\",\"projectId\":\"<PROJECT_ID>\",\"parameters\":{\"env_param1\":\"test-Value1\",\"env_param2\":\"test-value2\",\"env_param_new\":\"<NEW_PARAM_VALUE>\"}}"



6. Creating Global/Environment parameters using REST API


Here we use the POST CURL command to create a new environment and add parameters inside it. It is required to pass the <API_KEY>, <PROJECT_ID>, <ENVIRONMENT_NAME>in the command syntax given below.


curl --request POST "https://app.testsigma.com/api/v1/environments" --header "Authorization: Bearer <API_KEY>" --header "Content-Type: application/json" --data-raw "{\"name\":\"<ENVIRONMENT_ NAME>\",\"description\":\"<ENVIRONMENT_DESCRIPTION>\",\"projectId\":\"<PROJECT_ID>\",\"parameters\":{\"env_param1\":\"test-Value1\",\"env_param2\":\"test-value2\"}}"