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.

 ZIP Link to download code

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).


headers = {
”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).


headers = {
”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
)