Java and Java-based languages will use the API binding for Java to access Reqtest’s API. It has the fundamental features of reading and writing requests, as well as for JSON encoding and decoding.
Here are few examples of how to use the API binding:
The provided code sample below is a web-application written in Java (Spring Boot) and demonstrates basic functionality for fetching and updating bugs from ReQtest using the REST version of the API.
Setup & installation
Extract the ZIP file from the above location to a directory of your choice. The Java binding can be found in the “java” subdirectory after active download/extraction. Add the included kit to your project or program. In your preferred IDE, you can create or import a new project (e.g. in Eclipse).
File -> Import -> Existing Maven Project -> Next -> Browse -> Select the project -> Finish
The java binding uses the spring framework’s RestTemplate, HttpHeaders, HttpEntity, ResponseEntity to make external HTTP calls and curate the response.
Example: GET request
Read-only API methods use GET requests, which can be used to read from ReQtest.
For example- the code below demonstrates how to use the “get bugs” API method to get a list of existing bugs in the system.
HttpHeaders headers = new HttpHeaders();
headers.set(“accept”, “application/json”);
headers.set(“reqtest-pat”, 0s4h9fjrjj…);
HttpEntity entity = new HttpEntity(headers);
return restTemplate.exchange(
url = “https://” + putYourProjectId + “/bugs”,
HttpMethod.GET, entity, String.class).getBody();
For GET requests, the API binding provides a single method called “getData,” which expects the user’s PAT as well as any possible query parameters (in this case the ID of the project). The return value is a simple object (an instance of JSONObject or JSONArray).
In the event of an error (connection problems, failed authentication, missed API arguments, etc. ), an exception will be thrown. Your code should be prepared to handle the exception.
Example: POST request
Write-based API methods use POST requests, which can be used to add or modify data in ReQtest.
For example- the code below demonstrates how to use the “create bugs” API method to create bugs in the system.
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(“accept”, “application/json”);
headers.set(“reqtest-pat”, 0s4h9fjrjj…);
HttpEntity entity = new HttpEntity(reqBody, headers);
ResponseEntity result = restTemplate.exchange(
“https://” + putYourProjectId + “/bugs”,
HttpMethod.POST, entity, String.class);
return ResponseEntity.ok().body(result.getBody().toString());
For POST requests, the API binding provides a single method called “postData,” which expects the user’s PAT as well as any possible query parameters (in this case the ID of the project) and also request body (in this case bug details). The return value is a simple object (an instance of JSONObject or JSONArray).
In the event of an error (connection problems, failed authentication, missed API arguments, etc. ), an exception will be thrown, and your code should be prepared to handle it.
Example: Attachment Request
Upload and download API bindings can be used for adding an attachment to ReQtest or retrieving an attachment from ReQtest respectively.
For example- the code below demonstrates how to use the “download and upload” attachment API endpoints for Bugs module.
For download requests, the API binding provides single methods called “downloadData” for retrieving an attachment from ReQtest. This method expects the user’s PAT as well as any possible query parameters (in this case Project ID, Bug ID, and Attachment ID in a specific order in the URL). The file will be downloaded to the provided “downloadPath” in the code snippet below.
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.set(“accept”, “application/json”);
headers.set(“reqtest-pat”, 0s4h9fjrjj…);
HttpEntity entity = new HttpEntity(headers);
ResponseEntity<byte[]> response = restTemplate
.exchange(
“https://” + putYourProjectId + “/bugs/attachments/” + attachmentId + “/download”,
HttpMethod.POST, entity, byte[].class, “1”);
String encodedStr = Base64.getEncoder().encodeToString(response.getBody());
String downloadPath = “D:/download/fileName.jpg”; // download path followed by file name
if (response.getStatusCode() == HttpStatus.OK) {
Files.write(Paths.get(downloadPath), response.getBody());
}
For upload requests, the API binding provides single methods called “uploadData” for uploading an attachment from ReQtest. This method expects the user’s PAT as well as any possible query parameters (in this case Project ID and Bug ID in a specific order in the URL). This is a POST API with content media-type as multipart/form-data which is standard industry format for upload APIs. The file to upload shall be picked from the provided “uploadFile” path with file name.
String uploadFile = “D:/upload/fileToUpload.jpg”; // upload path followed by file name
HttpHeaders headers = new HttpHeaders();
headers.set(“Content-Type”, “multipart/form-data”);
headers.set(“Accept”, “text/plain”);
headers.set(“reqtest-pat”, 0s4h9fjrjj…);
MultiValueMap<String, Object> bodyMap = new LinkedMultiValueMap<>();
API Binding: Net
.Net and .Net-based languages will use the API binding for .Net to access ReQtest’s API. It has the fundamental features of reading and writing requests, as well as for JSON encoding and decoding.
Here are few examples of how to use the API binding:
The provided code sample below is a console application written in C# and demonstrates basic functionality for fetching and updating bugs from ReQtest using the REST version of the API.
Setup & installation
Extract the ZIP file from the above location to a directory of your choice. The .Net binding can be found in the “.Net” subdirectory after active download/extraction. Add the included kit to your project or program. In your preferred IDE, you can create or open a new project (e.g. in Visual studio).
File -> Open-> Project/Solution… -> Browse -> Select the project -> Open
Binding uses the .Net framework’s HttpClient, HttpResponseMessage to make external HTTP calls and curate the response.
Example: GET request
Use GET requests to read data from ReQtest.
For example- the code below demonstrates how to use the “get bugs” API method to get a list of existing bugs in the system.
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(”application/json”));
client.DefaultRequestHeaders.Add(”reqtest-pat”, patToken);
//GET Method
HttpResponseMessage response = client.GetAsync(url).GetAwaiter().GetResult();
Console.WriteLine(”GET Bug API Executed”);
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(”Success”);
Console.WriteLine(result);
}
else
{
var result = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(”Failed”);
Console.WriteLine(result);
}
}
Read-based API methods use GET requests, the API binding provides a single method called “GetBugs,” which expects the user’s PAT as well as any possible query parameters (in this case the ID of the project). The return value is a simple object (an instance of JSONObject or JSONArray).
In the event of an error (connection problems, failed authentication, missed API arguments, etc. ), an exception will be thrown. Your code should be prepared to handle the exception.
Example: POST request
Write-based API methods use POST requests, which can be used to add or modify data in ReQtest.
For example- the code below demonstrates how to use the “create bugs” API method to create bugs in the system.
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(”application/json”));
client.DefaultRequestHeaders.Add(”reqtest-pat”, patToken);
//Sample Json for Create a bug
var model = @”{
””fields””:{
””Heading””:{””name”” : ””Heading””, ””value”” : ””Title of Bug””},
””ErrorDescription””:{””name”” : ””ErrorDescription””, ””value”” : ””Error Description of Bug””}
}
}”;StringContent content = new StringContent(model, System.Text.Encoding.UTF8, ”application/json”);
var response = client.PostAsync(url, content).GetAwaiter().GetResult();
Console.WriteLine(”POST Bug API Executed”);
if (response.IsSuccessStatusCode)
{
Console.WriteLine(”Success”);
var result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
Console.WriteLine(result);
}
else
{
Console.WriteLine(”Failed”);
var result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
Console.WriteLine(result);
}
}
For POST requests, the API binding provides a single method called “CreateBug” which expects the user’s PAT as well as any possible query parameters (in this case the ID of the project) and also request body (in this case bug details). The return value is a simple object (an instance of JSONObject or JSONArray).
In the event of an error (connection problems, failed authentication, missed API arguments, etc. ), an exception will be thrown, and your code should be prepared to handle it.
Example: Attachment Request
Upload and download API bindings can be used for adding an attachment to ReQtest or retrieving an attachment from ReQtest respectively.
For example- the code below demonstrates how to use the “download and upload” attachment API endpoints for Bugs module.
For download requests, the API binding provides single methods called “DownloadBugAttachment” for retrieving an attachment from ReQtest. This method expects the user’s PAT as well as any possible query parameters (in this case Project ID, Bug ID, and Attachment ID in a specific order in the URL). The file will be downloaded to the provided “downloadPath” in the code snippet below.
string url = string.Format(”{0}/api/v3/projects/{1}/bugs/{2}/attachments/{3}/download”, hostName, projectId, bugId, attachmentId);using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
//Set Content Type
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(”application/json”));//Set Header Value
client.DefaultRequestHeaders.Add(”reqtest-pat”, patToken);
//Set File Object
using (var response = client.GetAsync(url).GetAwaiter().GetResult())
{
Console.WriteLine(”Download Bug attachment API Executed”);
if (response.IsSuccessStatusCode)
{
Console.WriteLine(”Success”);
using (var result = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult())
{
using (var fileStream = File.Create(dowloadPath))
{
using (var reader = new StreamReader(result))
{
result.CopyTo(fileStream);
fileStream.Flush();
Console.WriteLine(”File Download Successfully”);
}
}
}
}
else
{
Console.WriteLine(”Failed”);
var result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
Console.WriteLine(result);
}
}
}
For upload requests, the API binding provides single methods called “UploadBugAttachment” for uploading an attachment from ReQtest. This method expects the user’s PAT as well as any possible query parameters (in this case Project ID and Bug ID in a specific order in the URL). This is a POST API with content media-type as multipart/form-data which is the standard industry format for upload APIs. The file to upload shall be picked from the provided “uploadPath” path with the filenamefile name.
string url = string.Format(”{0}/api/v3/projects/{1}/bugs/{2}/attachments”, hostName, projectId, bugId);FileStream fileStreamObject = File.OpenRead(uploadPath);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
//Set Content Type
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(”multipart/form-data”));//Set Header Value
client.DefaultRequestHeaders.Add(”reqtest-pat”, patToken);
//Initialize the form
using (var form = new MultipartFormDataContent())
{
//Set File Object
form.Add(content: new StreamContent(fileStreamObject), name: Path.GetFileName(uploadPath), fileName: Path.GetFileName(uploadPath));
using (var response = client.PostAsync(url, form).GetAwaiter().GetResult())
{
Console.WriteLine(”Upload Bug Attachment API Executed”);
if (response.IsSuccessStatusCode)
{
Console.WriteLine(”Success”);
var result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
Console.WriteLine(result);
}
else
{
Console.WriteLine(”Failed”);
var result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
Console.WriteLine(result);
}
}
}
}
API binding: Python
Python-based frameworks will use the API binding for Python to access ReQtest’s API. It has the fundamental features of reading and writing requests, as well as smooth JSON encoding and decoding. Several examples of how to use the API binding can be found below.
The provided code sample below is a web-application written in Python (flask) and demonstrates basic functionality for fetching and updating bugs from ReQtest using the REST version of the API.
Setup & installation
Extract the ZIP file from the above location to a directory of your choice. The Python binding can be found in the “python” subdirectory after active download/extraction. Add the included kit to your project or program. In your preferred IDE, you can create or import a new project. The python binding uses flask and requests modules to make external HTTP calls and curate the response.
Example: GET request
Read-only API methods use GET requests, which can be used to read from ReQtest. For example- the code below demonstrates how to use the “get bugs” API method to get a list of existing bugs in the system (it will be a link to bugs with get bugs expanded).
”Content-Type” : ”application/json”,
”accept”: ”application/json”,
”reqtest-pat”: 0s4h9fjrjj…,
”User-Agent”: ”Custom”
}
result = requests.get(
url = ”https://” + putYourProjectId + ”/bugs”,
headers = headers)
For GET requests, the API binding provides a single method called ”getData,” which expects the user’s PAT as well as any possible query parameters (in this case the ID of the project). The return value is a simple object (an instance of JSONObject or JSONArray).
In the event of an error (connection problems, failed authentication, missed API arguments, etc. ), an exception can be thrown. Your code should be prepared to handle the exception.
Example: POST request
Write-based API methods use POST requests, which can be used to add or modify data into ReQtest. For example- the code below demonstrates how to use the “create bugs” API method to create bugs in the system (this will be linked to bugs with ’create bugs’ expanded).
”Content-Type” : ”application/json”,
”accept”: ”application/json”,
”reqtest-pat”: 0s4h9fjrjj…,
”User-Agent”: ”Custom”
}
result = requests.post(
url = ”https://” + putYourProjectId + ”/bugs”,
headers = headers,
json = request.json)
For POST requests, the API binding provides a single method called ”postData,” which expects the user’s PAT as well as any possible query parameters (in this case the ID of the project) and also request body (in this case bug details).
The return value is a simple object (an instance of JSONObject or JSONArray).
In the event of an error (connection problems, failed authentication, missed API arguments, etc. ), an exception can be thrown. Your code should be prepared to handle the exception.
Example: Attachment Request
Upload and download API bindings can be used for adding an attachment to ReQtest or retrieving an attachment from ReQtest respectively.
For example- the code below demonstrates how to use the “download and upload” attachment API endpoints for Bugs module.
For download requests, the API binding provides single methods called downloadData for retrieving an attachment from ReQtest. Which expects the user’s PAT as well as any possible query parameters (in this case Project ID, Bug ID, and Attachment ID in a specific order in the URL).
headers = {
”Content-Type” : ”application/json”,
”User-Agent”: ”Custom”,
”reqtest-pat”: 0s4h9fjrjj…,
}
r = requests.get(
url = ”https://” + putYourProjectId + ”/bugs/attachments/” + attachmentId + ”/download”,
headers = headers,
allow_redirects=True)
base64data = base64.b64encode(r.content).decode(”utf-8”)
downloadPath = ”D:/download/fileName.jpg”; // download path followed by file name
if r.status_code == 200:
with open(downloadPath, ’wb’) as f:
f.write(r.content)
For upload requests, the API binding provides single methods called uploadData for uploading an attachment from ReQtest. This method expects the user’s PAT as well as any possible query parameters (in this case Project ID and Bug ID in a specific order in the URL). This is a POST API with content media-type as multipart/form-data which is standard industry format for upload APIs.
headers = {
”accept”: ”application/json”,
”User-Agent”: ”Custom”,
”reqtest-pat”: 0s4h9fjrjj…
}
uploadFile = ”D:/upload/fileToUpload.jpg”; // upload path followed by file name
result = requests.post(
url = ”https://” + putYourProjectId + ”/bugs/attachments/” + attachmentId,
files = { ”file”: open(uploadFilePath, ”rb”) },
headers = headers
)