C#
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
var baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";
// set app_key header
var appKey = "your_app_key";
// set app_id header
var appId = "your_app_id";
// set accept header: "application/xml", "application/json"
var acceptHeader = "application/json";
// set resource
var resource = "regulatory_lists";
// set query parameters:q,limit,offset
var q = String.Empty;
var limit = 10;
var offset = 0;
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(baseAddress);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader));
client.DefaultRequestHeaders.Add("app_key", appKey);
client.DefaultRequestHeaders.Add("app_id", appId);
var response = await client.GetAsync(string.Format("{0}?q={1}&limit={2}&offset={3}", resource, q, limit, offset));
if (response.IsSuccessStatusCode)
{
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
else
{
Console.WriteLine(response.StatusCode);
}
Console.ReadLine();
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
var baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";
// set app_key header
var appKey = "your_app_key";
// set app_id header
var appId = "your_app_id";
// set accept header: "application/xml", "application/json"
var acceptHeader = "application/json";
// set resource
var resource = "tags";
// set query parameters:q,limit,offset
var q = String.Empty;
var limit = 10;
var offset = 0;
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(baseAddress);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader));
client.DefaultRequestHeaders.Add("app_key", appKey);
client.DefaultRequestHeaders.Add("app_id", appId);
var response = await client.GetAsync(string.Format("{0}?q={1}&limit={2}&offset={3}", resource, q, limit, offset));
if (response.IsSuccessStatusCode)
{
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
else
{
Console.WriteLine(response.StatusCode);
}
Console.ReadLine();
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
var baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";
// set app_key header
var appKey = "your_app_key";
// set app_id header
var appId = "your_app_id";
// set accept header: "application/xml", "application/json"
var acceptHeader = "application/json";
// set resource
var resource = "substances";
// set query parameters: q, limit, offset
var q = Uri.EscapeUriString("{\"identifiers.identifier.value\":\"50-00-0\"}");
var limit = 10;
var offset = 0;
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(baseAddress);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader));
client.DefaultRequestHeaders.Add("app_key", appKey);
client.DefaultRequestHeaders.Add("app_id", appId);
var response = await client.GetAsync(string.Format("{0}?q={1}&limit={2}&offset={3}", resource, q, limit, offset));
if (response.IsSuccessStatusCode)
{
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
else
{
Console.WriteLine(response.StatusCode);
}
Console.ReadLine();
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
var baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";
// set app_key header
var appKey = "your_app_key";
// set app_id header
var appId = "your_app_id";
// set accept header: "application/xml", "application/json"
var acceptHeader = "application/json";
// set resource
var resource = "regulatory_lists";
// set query parameters: q, limit, offset
var q = Uri.EscapeUriString("{$and: [{\"tags.tag.name\": \"OEL\"}, {\"tags.tag.name\": \"Canada\"}]}");
var limit = 10;
var offset = 0;
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(baseAddress);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader));
client.DefaultRequestHeaders.Add("app_key", appKey);
client.DefaultRequestHeaders.Add("app_id", appId);
var response = await client.GetAsync(string.Format("{0}?q={1}&limit={2}&offset={3}", resource, q, limit, offset));
if (response.IsSuccessStatusCode)
{
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
else
{
Console.WriteLine(response.StatusCode);
}
Console.ReadLine();