Java
Use our client library on Github »
Try it yourself
Hover over the top right of the code block to copy the code
What Lists are in the chem api?
Use this example to retrieve the set of lists within the chem api
// set base address
String baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";
// set accept header: MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML
String mediaType = MediaType.APPLICATION_JSON;
// set app_key header
String appKey = "your_app_key";
// set app_id header
String appId = "your_app_id";
// set resource
String resource = "regulatory_lists";
// set query parameters:q, limit, offset
String q = "";
Integer limit = 10;
Integer offset = 0;
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(UriBuilder.fromUri(baseAddress).path(resource).queryParam("q", q).queryParam("limit", limit).queryParam("offset", offset).build());
WebResource.Builder builder = service.header("app_key", appKey).header("app_id", appId);
String response = builder.accept(mediaType).get(String.class);
System.out.println(response);
What Tags are used on Lists within the chem api?
Use this example to retrieve the set of Tags within the chem api
// set base address
String baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";
// set accept header: MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML
String mediaType = MediaType.APPLICATION_JSON;
// set app_key header
String appKey = "your_app_key";
// set app_id header
String appId = "your_app_id";
// set resource
String resource = "tags";
// set query parameters:q, limit, offset
String q = "";
Integer limit = 10;
Integer offset = 0;
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(UriBuilder.fromUri(baseAddress).path(resource).queryParam("q", q).queryParam("limit", limit).queryParam("offset", offset).build());
WebResource.Builder builder = service.header("app_key", appKey).header("app_id", appId);
String response = builder.accept(mediaType).get(String.class);
System.out.println(response);
The power of the 'q'
The 'q' query parameter can be used within a supporting call to search any field within the resource. 'q' supports most of the syntax used by MongoDB db.find()
How do I find the Substance Id (_id) for CAS 50-00-0?
You can use 'q' to lookup a Substance Id (_id) by any Identifier that we support. Some of the Identifiers we support, but are not limited to, are CAS, EC, Annex, ENCS, and Formula
// set base address
String baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";
// set accept header: MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML
String mediaType = MediaType.APPLICATION_JSON;
// set app_key header
String appKey = "your_app_key";
// set app_id header
String appId = "your_app_id";
// set resource
String resource = "substances";
// set query parameters:q, limit, offset
String q = URLEncoder.encode("{\"identifiers.identifier.value\":\"50-00-0\"}", "UTF-8");
Integer limit = 10;
Integer offset = 0;
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(UriBuilder.fromUri(baseAddress).path(resource).queryParam("q", q).queryParam("limit", limit).queryParam("offset", offset).build());
WebResource.Builder builder = service.header("app_key", appKey).header("app_id", appId);
String response = builder.accept(mediaType).get(String.class);
System.out.println(response);
How do I find all of the Canada OEL Lists in the chem api?
Using 'q' to get a set of lists by a Tag or Tags
// set base address
String baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";
// set accept header: MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML
String mediaType = MediaType.APPLICATION_JSON;
// set app_key header
String appKey = "your_app_key";
// set app_id header
String appId = "your_app_id";
// set resource
String resource = "regulatory_lists";
// set query parameters:q, limit, offset
String q = URLEncoder.encode("{$and: [{\"tags.tag.name\": \"OEL\"}, {\"tags.tag.name\": \"Canada\"}]}", "UTF-8");
Integer limit = 10;
Integer offset = 0;
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(UriBuilder.fromUri(baseAddress).path(resource).queryParam("q", q).queryParam("limit", limit).queryParam("offset", offset).build());
WebResource.Builder builder = service.header("app_key", appKey).header("app_id", appId);
String response = builder.accept(mediaType).get(String.class);
System.out.println(response);