Rest API - Projects
The Reporter provides you with a Rest API that gives you direct access to the test data and statistics on a project basis. For more information, see Project Management.
The role of the user performing the Rest Operation is specified by the 'Authorization' header. For more information see How To Execute Rest API.
Get All Projects
List all projects.
This API is available for all user roles.
GET /reporter/api/projects
Response Status: 200 OK
[
{
"id": 1,
"name": "Default",
"created": 1578229200152,
"attachmentsCurrentTotalSize": 0,
"attachmentsMaxAllowedSize": 1000,
"usagePct": 0.0,
"allowNewKeysFromCode": true,
"allowUsersDeteleTests": false,
"showInAdminDashboard": false
},
{
"id": 20,
"name": "someOldProject",
"created": 1578229209981,
"attachmentsCurrentTotalSize": 0,
"attachmentsMaxAllowedSize": 1000,
"usagePct": 0.0,
"allowNewKeysFromCode": true,
"allowUsersDeteleTests": false,
"showInAdminDashboard": false
}
...
]
Change Project Name
Change the project name.
This API is available for Cloud Administrators only.
PUT /reporter/api/projects/<oldName>/<newName>
Download Test's Attachments by Project ID
Download all the attachments of a given test under a specific project as a zip file.
Note that projectId
is the Reporter's project ID, not the Cloud's.
The filename of the exported attachments is test_id_<testId>_attachments.zip
This API is available for all user roles.
GET /reporter/api/<projectId>/<testId>/attachments
- projectId - ID of the reporter's project.
- testId - ID of the test.
Download Test's Attachments by Project Name
Download all the attachments of a given test under a specific project as a zip file.
The filename of the exported attachments is test_id_<testid>_attachments.zip
This API is available for all user roles.
GET /reporter/api/<projectName>/<testId>/attachments-name
-
projectName - Name of the project.
-
testId - ID of the test.
Code Example
The examples use the Unirest HTTP library. To compile and run them, use the following Maven dependency:
Maven dependency
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
Java Code Example Expand source
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.apache.http.HttpHeaders;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
public class APIConfluence {
private HttpResponse<String> responseString;
private HttpResponse<InputStream> responseInputStream;
private String urlBase = "http://hostname:port/"; //TODO: modify hostname and port of your Reporter
private String user = "user"; //TODO: user name
private String password = "....."; //TODO: user password
private String accessKey= "....."; //TODO: user access key
String projectName = "projectName";//TODO: project name is here
String projectID = "projectID";//TODO: project ID is here
private String testID = "test ID";//TODO: test ID is here
@Test
public void getAllProjects() {
String url = urlBase + "/api/projects";
try {
responseString = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void changeProjectName() {
String oldName = "oldName";//TODO project old name
String newName = "newName";//TODO project new name
String url = urlBase + "/api/projects/" + oldName + "/" + newName + "/";
try {
responseString= Unirest.put(url)
.basicAuth(user, password)
.header("Content-Type", "application/json")
.asString();
System.out.println(responseString.getBody());
} catch (UnirestException e) {
e.printStackTrace();
}
}
@Test
public void getAttachmentsByProjectID() {
try {
String url = urlBase + "/api/" + projectID + "/" + testID + "/attachments";
responseInputStream = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asBinary();
String destination = "destination";//TODO: Path to save the file - zip file
writeToFile(destination);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void getAttachmentsByProjectName() {
String url = urlBase + "/api/" + projectName + "/" + testID + "/attachments-name";
try {
responseInputStream = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asBinary();
String destination = "destination";//TODO: Path to save the file - zip file
writeToFile(destination);
} catch (Exception e) {
e.printStackTrace();
}
}
private void writeToFile(String destination) {
InputStream inputStream = responseInputStream.getRawBody();
try {
FileOutputStream fileOutputStream = new FileOutputStream(destination);
int bytesRead = -1;
byte[] buffer = new byte[4096];
while ((bytesRead = inputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, bytesRead);
}
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}