2
votes

I am trying to create defects using Rally REST API in java.

My code to insert the defect looks something like this:

    JsonObject newDefect = new JsonObject();

    newDefect.addProperty("Workspace", workspaceRef);
    newDefect.addProperty("Project", projectRef);

    newDefect.addProperty("Name", d.name);
    newDefect.addProperty("Description", d.description);
    newDefect.addProperty("Notes", d.notes);
    newDefect.addProperty("Owner", getUserReference(restApi, d.owner));

    System.out.println("Creating defect: " + d.qcid + " - " + d.name);
    CreateRequest createRequest = new CreateRequest("defect", newDefect);
    CreateResponse createResponse = restApi.create(createRequest);

getUserReference is implemented as follows:

private String getUserReference(RallyRestApi restApi, String name) throws Exception
{
    // Read User
    QueryRequest userRequest = new QueryRequest("User");
    userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName"));
    userRequest.setQueryFilter(new QueryFilter("UserName", "=", name));
    QueryResponse userQueryResponse = restApi.query(userRequest);
    JsonArray userQueryResults = userQueryResponse.getResults();
    JsonElement userQueryElement = userQueryResults.get(0);
    JsonObject userQueryObject = userQueryElement.getAsJsonObject();
    String userRef = userQueryObject.get("_ref").toString();
    return userRef;
}

The problem: I get error 'Cannot parse object reference' on the user. I get it when I use the actual name ([email protected]) or the user reference as depicted above.

the current error i get is: Cannot parse object reference from ""https://rally1.rallydev.com/slm/webservice/v2.0/user/14659049875""

what am i doing wrong?

thanks Asaf

2

2 Answers

1
votes

Please use getAsString methods instead of toString.

Try:

String userRef = userQueryObject.get("_ref").getAsString();

instead of

String userRef = userQueryObject.get("_ref").toString();
0
votes

faced similar problem, setting older version of WSAPI helped me as a workaround

restApi = new RallyRestApi(new URI(rallyUrl), rallyUser, rallyPassword);
restApi.setWsapiVersion("1.36");