Creating a Session for REST API
The following is an example of how to create a session to retrieve contract fields using REST API.
package example;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class APISessionExample {
static final Logger LOG = LoggerFactory.getLogger(APISessionExample.class);
static final String USERNAME = "username";
static final String PASSWORD = "password";
static final String APIBASE = "https://app1.congacontracts.com/Contracts/rest/v1";
static final String SESSION_ENDPOINT = APIBASE + "/session";
static final String CONTRACT_ENDPOINT = APIBASE + "/contract/?q=&pageSize=1&page=0";
public static void main(final String[] args) throws Exception {
final String sessionId = Unirest.post(SESSION_ENDPOINT).field("username", USERNAME).field("password", PASSWORD).asString().getBody();
final JsonNode contract = Unirest.get(CONTRACT_ENDPOINT).header("Cookie", "NOVATUSSID=" + sessionId).asJson().getBody();
LOG.info("Retrieved data: " + contract.toString());
}
}For more information, see the Session section of REST API Version 2.0 or REST API Version 1.0.
