Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

Requests for TestTrail

#1

Hello

I am trying to receive “id” for my milestone in Test Trial

I am doing request:

public String getMilestoneID(String milestoneID) throws Exception {
    String new_milestone_ID  = new URIBuilder()
            .setScheme(SCHEME)
            .setHost(HOST + "/" + Requests.isMilestoneID + "/" + milestoneID)
            .build().toString();
    String ID = parsingJSON(TestHTTPUtils.executeGetRequest(String.valueOf(new_milestone_ID)));
    return ID;

My request: https://testrail.a1qa.com/index.php?/api/v2/get_milestone/1

Parsing:
public static String parsingJSON(byte[] json) throws ParseException {
String input = new String(json);
JsonParser parser = new JsonParser();
JsonObject mainObject = (JsonObject) parser.parse(input);
JsonObject pItem = (JsonObject) mainObject.get(“id”);
return pItem.get(“id”).toString();

And for input - i have: {“error”:“Content-Type header missing (use Content-Type: application/json)”}

Could you help me, please

#2

Hey, did you manage to solve this problem?

#3

It looks like the OP did not have the Header Type defined in the call “Content-Type header missing” and it tell them to use the following Content Type " Content-Type: application/json" for the header.

#4

True, but if you’re relying on testrail’s api then you don’t get to specify any of it. Here’s how I did it just now.

  1. Create Milestone class (im using lombok):

     @AllArgsConstructor
     @NoArgsConstructor
     @Builder
     @Data
     public class Milestone {
        	private int id;
        	private String name;
        	private String description;
        	private int projectId;
        	private Date dueOn;
        	private Boolean isCompleted;
        	private Date completedOn;
        	private String url;
     }
    
  2. Now the method:

pubilc void getMilestoneId() throws IOException, APIException {
JSONArray response = (JSONArray) client.sendGet(“get_milestones/2”);
response.stream().map(x -> {
try {
return mapper.readValue(x.toString(), Milestone.class);
} catch (IOException e) {
e.printStackTrace();
}
return Milestone.builder().build();
}).map(x -> ((Milestone) x).getId()).forEach(System.err::println);
System.out.println("BEHOLD ZIE ID: " + response);
}

Please note: this is a quick solution, I’m still trying to figure out a proper way of doing it myself. but the one above works. Hope it will help you and others. If you get better ideas, please share :slight_smile: