Making the first API Call
Prerequisites
A pair of API key ID and API key secret, like, for example:
key ID: 68b99121-ab14-4c50-ae32-483fd81ed5bdkey secret: yADmXL6z#3cVn-YDO6blMi2lf40JM0GTpZKT~~R75yCD7vYTe6~bSu2D9Fp4qDV9xEhmVdYKSome credits for any of the workflows. For the sake of simplicity, we will assume that you have bought credits for the Document Simple Forensics API.
If one of the previous steps is missing, then go to First Steps.
Setting up the authentication
WT uses BASIC authentication via the HTTP Authorization request header. As per the documentation, to set up the content of this header, we have to concatenate the key ID and the key secret in the following manner:
<key id>:<key secret>Using the values we already have, the resulting concatenation should be
68b99121-ab14-4c50-ae32-483fd81ed5bd:yADmXL6z#3cVn-YDO6blMi2lf40JM0GTpZKT~~R75yCD7vYTe6~bSu2D9Fp4qDV9xEhmVdYKNow, last but not least, this string has to be encoded using Base64:
NjhiOTkxMjEtYWIxNC00YzUwLWFlMzItNDgzZmQ4MWVkNWJkOnlBRG1YTDZ6IzNjVm4tWURPNmJsTWkybGY0MEpNMEdUcFpLVH5+Ujc1eUNEN3ZZVGU2fmJTdTJEOUZwNHFEVjl4RWhtVmRZSw==Using this base64-encoded string, we can finally build the header
Authorization: Basic NjhiOTkxMjEtYWIxNC00YzUwLWFlMzItNDgzZmQ4MWVkNWJkOnlBRG1YTDZ6IzNjVm4tWURPNmJsTWkybGY0MEpNMEdUcFpLVH5+Ujc1eUNEN3ZZVGU2fmJTdTJEOUZwNHFEVjl4RWhtVmRZSw==Making the call
Let us make one of the most common calls, the GET /signatures. Since we haven’t created any signatures so far, it should respond with an empty array.
There are other headers that we must specify, like:
Content-Type: application/json
Accept: application/jsonNow let us build our first API request:
curl https://api.webtrust.kopjra.com/v1/signatures
-H "Content-type: application/json"
-H "Accept: application/json"
-H "Authorization: Basic NjhiOTkxMjEtYWIxNC00YzUwLWFlMzItNDgzZmQ4MWVkNWJkOnlBRG1YTDZ6IzNjVm4tWURPNmJsTWkybGY0MEpNMEdUcFpLVH5+Ujc1eUNEN3ZZVGU2fmJTdTJEOUZwNHFEVjl4RWhtVmRZSw=="
const res = await fetch("https://api.webtrust.kopjra.com/v1/signatures", {
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Basic NjhiOTkxMjEtYWIxNC00YzUwLWFlMzItNDgzZmQ4MWVkNWJkOnlBRG1YTDZ6IzNjVm4tWURPNmJsTWkybGY0MEpNMEdUcFpLVH5+Ujc1eUNEN3ZZVGU2fmJTdTJEOUZwNHFEVjl4RWhtVmRZSw==",
},
});
console.log(await res.json());using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
using (HttpClient client = new HttpClient())
{
// Set the base URL
string url = "https://api.webtrust.kopjra.com/v1/signatures";
// Add headers
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("Authorization", "Basic NjhiOTkxMjEtYWIxNC00YzUwLWFlMzItNDgzZmQ4MWVkNWJkOnlBRG1YTDZ6IzNjVm4tWURPNmJsTWkybGY0MEpNMEdUcFpLVH5+Ujc1eUNEN3ZZVGU2fmJTdTJEOUZwNHFEVjl4RWhtVmRZSw==");
client.DefaultRequestHeaders.Add("Content-Type", "application/json");
// Make the HTTP GET request
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
// Parse the JSON response
string jsonResponse = await response.Content.ReadAsStringAsync();
Console.WriteLine(jsonResponse);
}
else
{
Console.WriteLine($"Error: {response.StatusCode}");
}
}
}
}import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
// Define the URL
String urlString = "https://api.webtrust.kopjra.com/v1/signatures";
URL url = new URL(urlString);
// Open a connection to the URL
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
// Set headers
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Authorization", "Basic NjhiOTkxMjEtYWIxNC00YzUwLWFlMzItNDgzZmQ4MWVkNWJkOnlBRG1YTDZ6IzNjVm4tWURPNmJsTWkybGY0MEpNMEdUcFpLVH5+Ujc1eUNEN3ZZVGU2fmJTdTJEOUZwNHFEVjl4RWhtVmRZSw==");
// Get the response code
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) { // Success
// Read the response
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// Print the JSON response
System.out.println(response.toString());
} else {
System.out.println("Error: HTTP response code " + responseCode);
}
// Disconnect the connection
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
import requests
def main():
# Define the URL
url = "https://api.webtrust.kopjra.com/v1/signatures"
# Set headers
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Basic NjhiOTkxMjEtYWIxNC00YzUwLWFlMzItNDgzZmQ4MWVkNWJkOnlBRG1YTDZ6IzNjVm4tWURPNmJsTWkybGY0MEpNMEdUcFpLVH5+Ujc1eUNEN3ZZVGU2fmJTdTJEOUZwNHFEVjl4RWhtVmRZSw=="
}
try:
# Make the GET request
response = requests.get(url, headers=headers)
# Check if the request was successful
if response.status_code == 200:
# Print the JSON response
print(response.json())
else:
print(f"Error: HTTP response code {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
main()
As a response, you should receive the following json
{
items: [],
total: 0
}Ok, now you are all set for creating a signature.
Was this helpful?
More in Getting started
What is Web Trust?The company behind Web Trust?Status Workflow DiagramSignature Field Selection CriteriaStill need help? Share an idea