Skip to main content

Rest API - Keys

The Reporter provides you with a Rest API that gives you direct access to the test data and statistics. In this page, you will find out how to manage keys (get, create, remove)

Concept​

  • Key **-**Key and value construct a tag. Each test has a subset of available tags with various values that describe the test specifics. Example: {device.os : Android}

info

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 Keys​

Get the information on all the keys the user has access to.

  • This API is available for all user roles.

GET /reporter/api/keys

Response Status: 200 OK

[
  {
    "id": 13,
    "name": "browserName",
    "index": 11,
    "dataType": "STRING",
    "valueCount": 0,
    "protected": true
  },        

...
]

Create a New Key​

Create a new key in the cloud.

This API is available for a Cloud Administrator only.

POST /reporter/api/keys

JSON parameter

NameTypeMandatoryDescription
nameStringYesName of the new key
typeStringYesType of the new key
Response Status: 200 OK

{
  "id": 40,
  "name": "new_key2",
  "index": 19,
  "dataType": "STRING",
  "valueCount": 0,
  "protected": false
}

Remove Key​

Deletes the key identified by ID.

  • This API is available for the Cloud Administrator only.

DELETE /reporter/api/keys/<id>

ID - One or more ids can be provided, separated by a comma.

         Example: /reporter/api/keys/3,4,23

You can retrieve the key ID using the Get Keys Rest API.

Code Example​

This example uses the Unirest HTTP library.  To compile and run it, 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.IOException;
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 getKeys() {
String url = urlBase + "/api/keys";

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 setKey() {
String url = urlBase + "/api/keys";
try {
responseString = Unirest.post(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.body("{ \"name\": \"newKey\", \"type\": \"STRING\" }")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}

@Test
public void deleteKey() {
String url = urlBase + String.format("/api/keys/%d","<keyId>"); //TODO: modify key ID
try {
responseString = Unirest.delete(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
}