Systems

Estimated reading: 4 minutes 715 views

A system is a piece of software, either built by the organization or purchased from a third party.  For example, cloud-based tools that employees use on a daily basis typically qualify as systems. For example, Salesforce, Slack, JIRA, Miro, AWS S3, Gusto, etc. are all systems. Alternatively, customer applications written by your product team, like a front-end, a back-end, or a mobile app, are also systems. 

In this guide, we will learn how to retrieve systems from the TrustCloud API using REST calls, and then retrieve tests associated with a specific system. 

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 headers = {
  'Authorization': '<your_api_key_here>',
  'x-trustcloud-api-version': '1'
};

				
			
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/systems");
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/systems"

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 /systems HTTP/1.1
Host: api.trustcloud.ai
Authorization: Bearer <your_api_key_here>
x-trustcloud-api-version: 1

				
			

Retrieving All Systems

To retrieve a list of all systems, make a GET request to the /systems 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/systems, { 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/systems");
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("/systems", 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/systems, headers=headers)
if response.status_code == 200:
   systems = response.json()
   print(systems)
else:
   print('Error retrieving Systems:', response.text)

				
			
Go
				
					package main

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

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

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 /systems 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": "e0dc34af-dc10-4be0-9466-f6eeb95df7ee",
    "name": "1Password",
    "systemId": "1password",
    "purpose": "Password Management",
    "riskScore": "80.00",
    "_metadata": {
      "createdBy": "46556398-3e4b-4385-a085-9e24e44a9bbd",
      "createdDate": "2021-05-19 16:05:18.574+00",
      "lastModifiedBy": "46556398-3e4b-4385-a085-9e24e44a9bbd",
      "lastModifiedDate": "2021-05-19 16:05:18.574+00"
    },
    "owner": {
      "name": null,
      "id": null
    },
    "group": {
      "id": "8ef530f1-fa7d-40a2-ac33-fffb765c7f21",
      "name": "IT"
    },
    "provider": {
      "id": "e5c39e8b-aec8-41b3-990e-5cbba0e91931",
      "name": "1Password"
    }
  },...
]

				
			

Retrieving a Single System

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

e0dc34af-dc10-4be0-9466-f6eeb95df7ee:

Javascript
				
					import axios from 'axios';

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

const id = 'e0dc34af-dc10-4be0-9466-f6eeb95df7ee'; // Replace with the ID of the system you want to retrieve

axios.get(`https://api.trustcloud.ai/systems/${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/systems/e0dc34af-dc10-4be0-9466-f6eeb95df7ee");
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("/systems/{id}", Method.GET);
request.AddHeader("Authorization", apiKey);
request.AddHeader("x-trustcloud-api-version", apiVersion);
request.AddUrlSegment("id", "e0dc34af-dc10-4be0-9466-f6eeb95df7ee");

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/systems/e0dc34af-dc10-4be0-9466-f6eeb95df7ee', headers=headers)
if response.status_code == 200:
   system = response.json()
   print(system)
else:
   print('Error retrieving System:', response.text)

				
			
Go
				
					package main

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

apiKey := "<your_api_key_here>"
url := "https://api.trustcloud.ai/systems/e0dc34af-dc10-4be0-9466-f6eeb95df7ee"

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 /systems/e0dc34af-dc10-4be0-9466-f6eeb95df7ee 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": "e0dc34af-dc10-4be0-9466-f6eeb95df7ee",
  "name": "1Password",
  "systemId": "1password",
  "purpose": "Password Management",
  "riskScore": "80.00",
  "_metadata": {
    "createdBy": "46556398-3e4b-4385-a085-9e24e44a9bbd",
    "createdDate": "2021-05-19 16:05:18.574+00",
    "lastModifiedBy": "46556398-3e4b-4385-a085-9e24e44a9bbd",
    "lastModifiedDate": "2021-05-19 16:05:18.574+00"
  },
  "owner": {
    "name": null,
    "id": null
  },
  "group": {
    "id": "8ef530f1-fa7d-40a2-ac33-fffb765c7f21",
    "name": "IT"
  },
  "provider": {
    "id": "e5c39e8b-aec8-41b3-990e-5cbba0e91931",
    "name": "1Password"
  }
}

				
			

Retrieving tests associated with a system

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

e0dc34af-dc10-4be0-9466-f6eeb95df7ee:

Javascript
				
					import axios from 'axios';

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

const id = 'e0dc34af-dc10-4be0-9466-f6eeb95df7ee'; // Replace with the ID of the System you want to retrieve

axios.get(`https://api.trustcloud.ai/systems/${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/systems/e0dc34af-dc10-4be0-9466-f6eeb95df7ee/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("/systems/{id}/tests", Method.GET);
request.AddHeader("Authorization", apiKey);
request.AddHeader("x-trustcloud-api-version", apiVersion);
request.AddUrlSegment("id", "e0dc34af-dc10-4be0-9466-f6eeb95df7ee");

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/systems/e0dc34af-dc10-4be0-9466-f6eeb95df7ee/tests', headers=headers)
if response.status_code == 200:
   system = response.json()
   print(system)
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/systems/e0dc34af-dc10-4be0-9466-f6eeb95df7ee/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 /systems/e0dc34af-dc10-4be0-9466-f6eeb95df7ee/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": "e0dc34af-dc10-4be0-9466-f6eeb95df7ee",
    "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 systems 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 systems:

Javascript
				
					import axios from 'axios';

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

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

axios.get('https://api.trustcloud.ai/systems, {
  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/systems?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("/systems", 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/systems?limit=10&page=1', headers=headers', headers=headers)
if response.status_code == 200:
   system = response.json()
   print(system)
else:
   print('Error retrieving systems:', response.text)

				
			
Go
				
					package main

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

apiKey := "<your_api_key_here>"
url := "https://api.trustcloud.ai/systems?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 /systems?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 systems, 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 Systems to retrieve per page
const page = 1; // The page number to retrieve (starts at 1)

axios.get('https://api.trustcloud.ai/systems, {
  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("/systems", 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/systems?limit=10&page=1', headers=headers)
if response.status_code == 200:
   systems = response.json()
   print(systems)
   link_header = response.headers.get('link')
   if link_header:
      nextPage = re.search('<(.+)>', link_header)
else:
   print('Error retrieving Systems:', 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/systems"

	// 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/systems?page=2&limit=10>; rel="next"

GET /systems?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