Controls

Estimated reading: 3 minutes 721 views

Controls are processes you follow as an organization to prevent a potential risk from happening and affecting your business. In TrustCloud, controls are the foundational building blocks of the organization’s compliance program. In this guide, we will learn how to retrieve controls from the TrustCloud API using REST calls, and then retrieve tests associated with a specific control. 

Retrieving an API Key

To make requests to the TrustCloud API, an API key is required. To obtain an API key, follow the instructions in the Getting Started Guide to connect to the API.  

Setting up the Request

Before we make any requests, we need to set up our HTTP headers. We need to include the API key in the “Authorization” header, and set the “x-trustcloud-api-version” header to 1 to ensure we are using the correct API version.

Here is an example of the headers we need to include in our HTTP request:

Javascript
				
					const axios = require('axios');

async function getApiKey() {
  const apiKey = '<your_api_key_here>';
  const apiUrl = 'https://api.trustcloud.ai/apikeys/me';

  try {
    const response = await axios.get(apiUrl, {
      headers: {
        'Authorization': `Bearer ${apiKey}`,
        'x-trustcloud-api-version': '1'
      }
    });

    console.log(response.data);
  } catch (error) {
    console.error(error);
  }
}
				
			
Java
				
					import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

HttpGet request = new HttpGet("https://api.trustcloud.ai/controls");
request.setHeader("Authorization", "<your_api_key_here>");
request.setHeader("x-trustcloud-api-version", "1");

				
			
Csharp
				
					using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;

string apiKey = "<your_api_key_here>";
string apiVersion = "1";
string baseUrl = "https://api.trustcloud.ai";

				
			
Python
				
					import requests
headers = {
   'Authorization': '<your_api_key_here>',
   'x-trustcloud-api-version': '1'
}

				
			
Go
				
					package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

apiKey := "<your_api_key_here>"
url := "https://api.trustcloud.ai/controls"

req, err := http.NewRequest("GET", url, nil)
if err != nil {
    fmt.Println(err)
    return
}

req.Header.Set("Authorization", apiKey)
req.Header.Set("x-trustcloud-api-version", "1")

				
			
Bash
				
					GET /controls HTTP/1.1
Host: api.trustcloud.ai
Authorization: Bearer <your_api_key_here>
x-trustcloud-api-version: 1

				
			

Retrieving All Controls

To retrieve a list of all controls, make a GET request to the /controls endpoint using the headers set up in Step 2.

Javascript
				
					import axios from 'axios';

const headers = {
  'Authorization': '<your_api_key_here>',
  'x-trustcloud-api-version': '1'
};

axios.get('https://api.trustcloud.ai/controls', { headers })
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.log(error);
  });

				
			
Java
				
					import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

HttpGet request = new HttpGet("https://api.trustcloud.ai/controls");
request.setHeader("Authorization", "<your_api_key_here>");
request.setHeader("x-trustcloud-api-version", "1");

HttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(request);

try {
    String responseBody = EntityUtils.toString(response.getEntity());
    System.out.println(responseBody);
} finally {
    response.close();
}

				
			
Csharp
				
					using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;

string apiKey = "<your_api_key_here>";
string apiVersion = "1";
string baseUrl = "https://api.trustcloud.ai";

var client = new RestClient(baseUrl);
var request = new RestRequest("/controls", Method.GET);
request.AddHeader("Authorization", apiKey);
request.AddHeader("x-trustcloud-api-version", apiVersion);

IRestResponse response = client.Execute(request);

if (response.IsSuccessful)
{
    Console.WriteLine(response.Content);
}
else
{
    Console.WriteLine("Error: " + response.Content);
}

				
			
Python
				
					import requests
headers = {
   'Authorization': '<your_api_key_here>',
   'x-trustcloud-api-version': '1'
}

response = requests.get('https://api.trustcloud.ai/controls', headers=headers)
if response.status_code == 200:
   controls = response.json()
   print(controls)
else:
   print('Error retrieving Controls:', response.text)

				
			
Go
				
					package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

apiKey := "<your_api_key_here>"
url := "https://api.trustcloud.ai/controls"

req, err := http.NewRequest("GET", url, nil)
if err != nil {
    fmt.Println(err)
    return
}

req.Header.Set("Authorization", apiKey)
req.Header.Set("x-trustcloud-api-version", "1")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    fmt.Println(err)
    return
}
defer resp.Body.Close()

var data []interface{}
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
    fmt.Println(err)
    return
}

fmt.Printf("%+v\n", data)

				
			
Bash
				
					GET /controls HTTP/1.1
Host: api.trustcloud.ai
Authorization: Bearer <your_api_key_here>
x-trustcloud-api-version: 1

				
			

Here is an example of the response we might receive:

Html
				
					HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 1234

				
			
Html
				
					[
  {
    "id": "cd2d4fe0-187f-4126-9cdb-edb9867b8040",
    "catalogControlId": "0a0c3e60-f66d-4ac3-9c60-0fe9819512d7",
    "category": "Product Delivery Process",
    "controlName": "Change Management Workflow",
    "controlText": "The Change Management documentation outlines the internal workflow for propagating application and infrastructure code changes to the production environment, including tracking, testing, reviewing and approving.",
    "state": "adopted",
    "maturityLevel": 1,
    "groupName": "Engineering",
    "lastStateChangeBy": "59246246-ed25-48a8-ae5e-67732c6ee332",
    "lastStateChangeOn": "2022-02-15 17:14:36.305+00",
    "evidenceDetails": {
      "status": "NA",
      "nextEviddenceDueDate": "NA"
    },
    "compliance": {
      "soc2": [
        {
          "complianceStandardControlId": "b9377637-b3c6-47f8-96f1-0f056878edef",
          "controlId": "0a0c3e60-f66d-4ac3-9c60-0fe9819512d7",
          "referenceId": "CC8.1",
          "description": "The entity authorizes, designs, develops or acquires, configures, documents, tests, approves, and implements changes to infrastructure, data, software, and procedures to meet its objectives.",
          "name": "SOC 2",
          "complianceStdName": "soc2",
          "groupName": "infosec_compliance",
          "complianceStandardId": "e5f9fbfb-a10b-4900-9de0-c60f936b4feb"
        }
      ]
    },
    "intervalDuration": {
      "years": 1
    },
    "owner": {
      "id": {},
      "name": {}
    },
    "_metadata": {
      "createdby": "59246246-ed25-48a8-ae5e-67732c6ee332",
      "createddate": "2022-02-15 17:14:23.81+00",
      "lastmodifiedby": "59246246-ed25-48a8-ae5e-67732c6ee332",
      "lastmodifieddate": "2022-02-15 17:14:36.305+00"
    }
  }, ...
]

				
			

Retrieving a Single Control

To retrieve a single control, include the control ID in the URL by appending the ID to the /controls endpoint. In this example, we will retrieve the control with ID

cd2d4fe0-187f-4126-9cdb-edb9867b8040:

Javascript
				
					import axios from 'axios';

const headers = {
  'Authorization': '<your_api_key_here>',
  'x-trustcloud-api-version': '1'
};

const id = 'cd2d4fe0-187f-4126-9cdb-edb9867b8040'; // Replace with the ID of the Control you want to retrieve

axios.get(`https://api.trustcloud.ai/controls/${id}`, { headers })
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.log(error);
  });

				
			
Java
				
					import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

HttpGet request = new HttpGet("https://api.trustcloud.ai/controls/cd2d4fe0-187f-4126-9cdb-edb9867b8040");
request.setHeader("Authorization", "<your_api_key_here>");
request.setHeader("x-trustcloud-api-version", "1");

HttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(request);

try {
    String responseBody = EntityUtils.toString(response.getEntity());
    System.out.println(responseBody);
} finally {
    response.close();
}

				
			
Csharp
				
					using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;

string apiKey = "<your_api_key_here>";
string apiVersion = "1";
string baseUrl = "https://api.trustcloud.ai";

var client = new RestClient(baseUrl);
var request = new RestRequest("/controls/{id}", Method.GET);
request.AddHeader("Authorization", apiKey);
request.AddHeader("x-trustcloud-api-version", apiVersion);
request.AddUrlSegment("id", "cd2d4fe0-187f-4126-9cdb-edb9867b8040");

IRestResponse response = client.Execute(request);

if (response.IsSuccessful)
{
    Console.WriteLine(response.Content);
}
else
{
    Console.WriteLine("Error: " + response.Content);
}

				
			
Python
				
					import requests
headers = {
   'Authorization': '<your_api_key_here>',
   'x-trustcloud-api-version': '1'
}

response = requests.get('https://api.trustcloud.ai/controls/cd2d4fe0-187f-4126-9cdb-edb9867b8040', headers=headers)
if response.status_code == 200:
   control = response.json()
   print(control)
else:
   print('Error retrieving Control:', response.text)

				
			
Go
				
					package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

apiKey := "<your_api_key_here>"
url := "https://api.trustcloud.ai/controls/cd2d4fe0-187f-4126-9cdb-edb9867b8040"

req, err := http.NewRequest("GET", url, nil)
if err != nil {
    fmt.Println(err)
    return
}

req.Header.Set("Authorization", apiKey)
req.Header.Set("x-trustcloud-api-version", "1")

req, err := http.NewRequest("GET", url, nil)
if err != nil {
    fmt.Println(err)
    return
}

req.Header.Set("Authorization", apiKey)
req.Header.Set("x-trustcloud-api-version", "1")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    fmt.Println(err)
    return
}
defer resp.Body.Close()

var data map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
    fmt.Println(err)
    return
}

fmt.Printf("%+v\n", data)

				
			
Bash
				
					GET /controls/cd2d4fe0-187f-4126-9cdb-edb9867b8040 HTTP/1.1
Host: API.trustcloud.ai
Authorization: <your_api_key_here>
x-trustcloud-api-version: 1

				
			

Here is an example of the response we might receive:

Html
				
					HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 234
				
			
Html
				
					{
    "id": "cd2d4fe0-187f-4126-9cdb-edb9867b8040",
    "catalogControlId": "0a0c3e60-f66d-4ac3-9c60-0fe9819512d7",
    "category": "Product Delivery Process",
    "controlName": "Change Management Workflow",
    "controlText": "The Change Management documentation outlines the internal workflow for propagating application and infrastructure code changes to the production environment, including tracking, testing, reviewing and approving.",
    "state": "adopted",
    "maturityLevel": 1,
    "groupName": "Engineering",
    "lastStateChangeBy": "59246246-ed25-48a8-ae5e-67732c6ee332",
    "lastStateChangeOn": "2022-02-15 17:14:36.305+00",
    "evidenceDetails": {
      "status": "NA",
      "nextEviddenceDueDate": "NA"
    },
    "compliance": {
      "soc2": [
        {
          "complianceStandardControlId": "b9377637-b3c6-47f8-96f1-0f056878edef",
          "controlId": "0a0c3e60-f66d-4ac3-9c60-0fe9819512d7",
          "referenceId": "CC8.1",
          "description": "The entity authorizes, designs, develops or acquires, configures, documents, tests, approves, and implements changes to infrastructure, data, software, and procedures to meet its objectives.",
          "name": "SOC 2",
          "complianceStdName": "soc2",
          "groupName": "infosec_compliance",
          "complianceStandardId": "e5f9fbfb-a10b-4900-9de0-c60f936b4feb"
        }
      ]
    },
    "intervalDuration": {
      "years": 1
    },
    "owner": {
      "id": {},
      "name": {}
    },
    "_metadata": {
      "createdby": "59246246-ed25-48a8-ae5e-67732c6ee332",
      "createddate": "2022-02-15 17:14:23.81+00",
      "lastmodifiedby": "59246246-ed25-48a8-ae5e-67732c6ee332",
      "lastmodifieddate": "2022-02-15 17:14:36.305+00"
    }
  }

				
			

Retrieving tests associated with a control

To retrieve tests associated with a single control, append /tests to the single control endpoint.   In this example, we will retrieve tests associated with the control with ID

cd2d4fe0-187f-4126-9cdb-edb9867b8040:

Javascript
				
					import axios from 'axios';

const headers = {
  'Authorization': '<your_api_key_here>',
  'x-trustcloud-api-version': '1'
};

const id = 'cd2d4fe0-187f-4126-9cdb-edb9867b8040'; // Replace with the ID of the Control you want to retrieve

axios.get(`https://api.trustcloud.ai/controls/${id}/tests`, { headers })
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.log(error);
  });

				
			
Java
				
					import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

HttpGet request = new HttpGet("https://api.trustcloud.ai/controls/cd2d4fe0-187f-4126-9cdb-edb9867b8040/tests");
request.setHeader("Authorization", "<your_api_key_here>");
request.setHeader("x-trustcloud-api-version", "1");

HttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(request);

try {
    String responseBody = EntityUtils.toString(response.getEntity());
    System.out.println(responseBody);
} finally {
    response.close();
}

				
			
Csharp
				
					using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;

string apiKey = "<your_api_key_here>";
string apiVersion = "1";
string baseUrl = "https://api.trustcloud.ai";

var client = new RestClient(baseUrl);
var request = new RestRequest("/controls/{id}/tests", Method.GET);
request.AddHeader("Authorization", apiKey);
request.AddHeader("x-trustcloud-api-version", apiVersion);
request.AddUrlSegment("id", "cd2d4fe0-187f-4126-9cdb-edb9867b8040");

IRestResponse response = client.Execute(request);

if (response.IsSuccessful)
{
    Console.WriteLine(response.Content);
}
else
{
    Console.WriteLine("Error: " + response.Content);
}

				
			
Python
				
					import requests
headers = {
   'Authorization': '<your_api_key_here>',
   'x-trustcloud-api-version': '1'
}

response = requests.get('https://api.trustcloud.ai/controls/cd2d4fe0-187f-4126-9cdb-edb9867b8040/tests', headers=headers)
if response.status_code == 200:
   control = response.json()
   print(control)
else:
   print('Error retrieving tests∂:', response.text)

				
			
Go
				
					package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

apiKey := "<your_api_key_here>"
url := "https://api.trustcloud.ai/controls/cd2d4fe0-187f-4126-9cdb-edb9867b8040/tests"

req, err := http.NewRequest("GET", url, nil)
if err != nil {
    fmt.Println(err)
    return
}

req.Header.Set("Authorization", apiKey)
req.Header.Set("x-trustcloud-api-version", "1")

req, err := http.NewRequest("GET", url, nil)
if err != nil {
    fmt.Println(err)
    return
}

req.Header.Set("Authorization", apiKey)
req.Header.Set("x-trustcloud-api-version", "1")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    fmt.Println(err)
    return
}
defer resp.Body.Close()

var data map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
    fmt.Println(err)
    return
}

fmt.Printf("%+v\n", data)

				
			
Bash
				
					GET /controls/cd2d4fe0-187f-4126-9cdb-edb9867b8040/tests HTTP/1.1
Host: API.trustcloud.ai
Authorization: <your_api_key_here>
x-trustcloud-api-version: 1

				
			

Here is an example of the response we might receive:

Html
				
					HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 234
				
			
Html
				
					[
  {
    "id": "cd2d4fe0-187f-4126-9cdb-edb9867b8040",
    "type": "self_assessment",
    "name": "Change management workflow",
    "testId": null,
    "question": "Do you have a documented change management process outlining the workflow for propagating application and infrastructure code changes to production environments, including tracking, testing, review, and approval?",
    "recommendation": "Document your change management process, outlining the workflow for propagating application and infrastructure code changes to the production environment. Including information about tracking, testing, review, and approval processes.",
    "evidenceCount": null,
    "evidenceDescription": "Your change management, release management, or software development life cycle process documentation, outlining the workflows for propagating application and infrastructure code changes to production environments, including tracking, testing, review and approval",
    "evidenceStatus": "missing",
    "executionOutcome": null,
    "executionStatus": null,
    "nextEvidenceDueDate": null,
    "owner": {
      "name": null,
      "id": null
    },
    "system": {
      "id": "98ff23b1-6d57-4417-ac1c-00c1db92b44b",
      "name": "TrustCloud",
      "systemId": "trustcloud"
    },
    "_metadata": {
      "createdBy": "228ad587-98a0-485e-8a2b-7664805e8401",
      "createdDate": "2023-04-28 03:59:11.305+00",
      "lastModifiedBy": "228ad587-98a0-485e-8a2b-7664805e8401",
      "lastModifiedDate": "2023-04-28 03:59:11.305+00"
    }
  },
  {
    "id": "fee5e75f-9dbb-4c5f-8dc1-8943f62e8366",
    "type": "self_assessment",
    "name": "Change management workflow",
    "testId": null,
    "question": "Do you have a documented change management process outlining the workflow for propagating application and infrastructure code changes to production environments, including tracking, testing, review, and approval?",
    "recommendation": "Document your change management process, outlining the workflow for propagating application and infrastructure code changes to the production environment. Including information about tracking, testing, review, and approval processes.",
    "evidenceCount": null,
    "evidenceDescription": "Your change management, release management, or software development life cycle process documentation, outlining the workflows for propagating application and infrastructure code changes to production environments, including tracking, testing, review and approval",
    "evidenceStatus": "missing",
    "executionOutcome": "success",
    "executionStatus": "completed",
    "nextEvidenceDueDate": null,
    "owner": {
      "name": null,
      "id": null
    },
    "system": {
      "id": null,
      "name": null,
      "systemId": null
    },
    "_metadata": {
      "createdBy": "228ad587-98a0-485e-8a2b-7664805e8401",
      "createdDate": "2020-11-11 01:27:55.814161+00",
      "lastModifiedBy": "228ad587-98a0-485e-8a2b-7664805e8401",
      "lastModifiedDate": "2022-03-17 02:23:37.625599+00"
    }
  }
]

				
			

Paging

If there are a large number of controls in a response, it is recommended to use paging to retrieve them in batches. To do this, we can use the limit and page query parameters.

The limit parameter specifies the number of records to retrieve in each page. The default value is 100, but we can set it to any value up to 1000.

The page parameter specifies which page to retrieve. The first page is page 1.

For example, to retrieve the first 10 controls:

Javascript
				
					import axios from 'axios';

const headers = {
  'Authorization': '<your_api_key_here>',
  'x-trustcloud-api-version': '1'
};

const limit = 10; // The number of Controls to retrieve per page
const page = 1; // The page number to retrieve (starts at 1)

axios.get('https://api.trustcloud.ai/controls', {
  headers,
  params: {
    limit,
    page,
  }
})
  .then(response => {
    console.log(response.data);
    console.log(response.headers.link); // log link header
  })
  .catch(error => {
    console.log(error);
  });

				
			
Java
				
					import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

HttpGet request = new HttpGet("https://api.trustcloud.ai/controls?limit=10&page=1");
request.setHeader("Authorization", "<your_api_key_here>");
request.setHeader("x-trustcloud-api-version", "1");

HttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(request);

try {
    String responseBody = EntityUtils.toString(response.getEntity());
    System.out.println(responseBody);
} finally {
    response.close();
}

				
			
Csharp
				
					using System;
using System.Collections.Generic;

string apiKey = "<your_api_key_here>";
string apiVersion = "1";
string baseUrl = "https://api.trustcloud.ai";

var client = new RestClient(baseUrl);
var request = new RestRequest("/controls", Method.GET);
request.AddHeader("Authorization", apiKey);
request.AddHeader("x-trustcloud-api-version", apiVersion);
request.AddParameter("limit", 50);
request.AddParameter("page", 1);

IRestResponse response = client.Execute(request);

if (response.IsSuccessful)
{
    Console.WriteLine(response.Content);
}
else
{
    Console.WriteLine("Error: " + response.Content);
}

				
			
Python
				
					import requests
headers = {
   'Authorization': '<your_api_key_here>',
   'x-trustcloud-api-version': '1'
}

response = requests.get('https://api.trustcloud.ai/controls?limit=10&page=1', headers=headers', headers=headers)
if response.status_code == 200:
   control = response.json()
   print(control)
else:
   print('Error retrieving Control:', response.text)

				
			
Go
				
					package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

apiKey := "<your_api_key_here>"
url := "https://api.trustcloud.ai/controls?page=1&limit=10"

req, err := http.NewRequest("GET", url, nil)
if err != nil {
    fmt.Println(err)
    return
}

req.Header.Set("Authorization", apiKey)
req.Header.Set("x-trustcloud-api-version", "1")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    fmt.Println(err)
    return
}
defer resp.Body.Close()

var data []interface{}
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
    fmt.Println(err)
    return
}

fmt.Printf("%+v\n", data)

				
			
Bash
				
					GET /controls?limit=10&page=1 HTTP/1.1
Host: API.trustcloud.ai
Authorization: <your_api_key_here>
x-trustcloud-api-version: 1
				
			

To retrieve the next set of controls, you can obtain the next URL from the link response header,  or manually increment the page number.  If link is null, that means there are no more pages.

Javascript
				
					import axios from 'axios';

const headers = {
  'Authorization': '<your_api_key_here>',
  'x-trustcloud-api-version': '1'
};

const limit = 10; // The number of Controls to retrieve per page
const page = 1; // The page number to retrieve (starts at 1)

axios.get('https://api.trustcloud.ai/controls', {
  headers,
  params: {
    limit,
    page,
  }
})
  .then(response => {
    console.log(response.data);
    console.log(response.headers.link); // log link header
  })
  .catch(error => {
    console.log(error);
  });

				
			
Java
				
					String linkHeader = response.getFirstHeader("link").getValue();
String nextPageUrl = linkHeader.split(";")[0].replace("<", "").replace(">", "");
HttpGet nextPageRequest = new HttpGet(nextPageUrl);
nextPageRequest.setHeader("Authorization", "<your_api_key_here>");
nextPageRequest.setHeader("x-trustcloud-api-version", "1");

				
			
Csharp
				
					using System;
using System.Collections.Generic;

string apiKey = "<your_api_key_here>";
string apiVersion = "1";
string baseUrl = "https://api.trustcloud.ai";

var client = new RestClient(baseUrl);
var request = new RestRequest("/controls", Method.GET);
request.AddHeader("Authorization", apiKey);
request.AddHeader("x-trustcloud-api-version", apiVersion);
request.AddParameter("limit", 50);
request.AddParameter("page", 1);

IRestResponse response = client.Execute(request);

if (response.IsSuccessful)
{
    Console.WriteLine(response.Content);

    // retrieve next page
    var nextPageUrl = response.Headers.FirstOrDefault(x => x.Name == "Link")?.Value?.Split(';')[0]?.Trim('<', '>');

    if (!string.IsNullOrEmpty(nextPageUrl))
    {
        var nextPageRequest = new RestRequest(nextPageUrl, Method.GET);
        nextPageRequest.AddHeader("Authorization", apiKey);
        nextPageRequest.AddHeader("x-trustcloud-api-version", apiVersion);

        IRestResponse nextPageResponse = client.Execute(nextPageRequest);

        if (nextPageResponse.IsSuccessful)
        {
            Console.WriteLine(nextPageResponse.Content);
        }
        else
        {
            Console.WriteLine("Error retrieving next page: " + nextPageResponse.Content);

				
			
Python
				
					import requests
import re

headers = {
   'Authorization': '<your_api_key_here>',
   'x-trustcloud-api-version': '1'
}

response = requests.get('https://api.trustcloud.ai/controls?limit=10&page=1', headers=headers)
if response.status_code == 200:
   controls = response.json()
   print(controls)
   link_header = response.headers.get('link')
   if link_header:
      nextPage = re.search('<(.+)>', link_header)
else:
   print('Error retrieving Controls:', response.text)

				
			
Go
				
					package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"strings"
)

func main() {
	apiKey := "<your_api_key_here>"
	url := "https://api.trustcloud.ai/controls"

	// Create a new HTTP client
	client := &http.Client{}

	// Create a new HTTP request
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		log.Fatal(err)
	}

	// Add the API key and version headers
	req.Header.Set("Authorization", apiKey)
	req.Header.Set("x-trustcloud-api-version", "1")

	// Add the page and limit parameters
	q := req.URL.Query()
	q.Add("page", "1")
	q.Add("limit", "10")
	req.URL.RawQuery = q.Encode()

	// Make the API call
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	// Check the response status code
	if resp.StatusCode != http.StatusOK {
		log.Fatal(resp.Status)
	}

	// Parse the link header to get the URL for the next page
	linkHeader := resp.Header.Get("Link")
	nextPageURL := ""
	if linkHeader != "" {
		links := strings.Split(linkHeader, ",")
		for _, link := range links {
			if strings.Contains(link, "rel=\"next\"") {
				parts := strings.Split(link, ";")
				if len(parts) > 0 {
					nextPageURL = strings.Trim(parts[0], "<>")
				}
			}
		}
	}

	// Read the response body
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}

	// Print the response body
	fmt.Println(string(body))

	// Make the API call for the next page if it exists
	if nextPageURL != "" {
		// Create a new HTTP request for the next page
		nextPageReq, err := http.NewRequest("GET", nextPageURL, nil)
		if err != nil {
			log.Fatal(err)
		}

		// Add the API key and version headers to the next page request
		nextPageReq.Header.Set("Authorization", apiKey)
		nextPageReq.Header.Set("x-trustcloud-api-version", "1")

		// Make the next page API call
		nextPageResp, err := client.Do(nextPageReq)
		if err != nil {
			log.Fatal(err)
		}
		defer nextPageResp.Body.Close()

		// Check the response status code for the next page
		if nextPageResp.StatusCode != http.StatusOK {
			log.Fatal(nextPageResp.Status)
		}

		// Read the response body for the next page
		nextPageBody, err := ioutil.ReadAll(nextPageResp.Body)
		if err != nil {
			log.Fatal(err)
		}

		// Print the response body for the next page
		fmt.Println(string(nextPageBody))
	}
}

				
			
Bash
				
					HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 234
link: <http://api.trustcloud.ai/controls?page=2&limit=10>; rel="next"

GET /controls?pag2&limit=10 HTTP/1.1
Host: API.trustcloud.ai
Authorization: <your_api_key_here>
x-trustcloud-api-version: 1
				
			

API Reference

Join the conversation

ON THIS PAGE
SHARE THIS PAGE

SUBSCRIBE
FlightSchool
OR