PHP

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

<?php

// set base address
$baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";

// set resource
$resource = "regulatory_lists";

// set limit,offset
$limit  = 10;
$offset = 0;

$getdata = http_build_query(array(
    'limit' => $limit,
    'offset' => $offset
));

$opts = array(
    'http' => array(
        'method' => "GET",
        'header' => 
        // set app_key header
            "app_key:your_app_key\r\n" . 
		// set app_id header
            "app_id:your_app_id\r\n" . 
        // set accept header
            "accept:application/json\r\n"
    )
);

$context = stream_context_create($opts);
$file = file_get_contents($baseAddress . $resource . '?' . $getdata, false, $context);
print_r($file);
?>





What Tags are used on Lists within the chem api?

Use this example to retrieve the set of Tags within the chem api

<?php

// set base address
$baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";

// set resource
$resource = "tags";

// set limit,offset
$limit  = 10;
$offset = 0;

$getdata = http_build_query(array(
    'limit' => $limit,
    'offset' => $offset
));

$opts = array(
    'http' => array(
        'method' => "GET",
        'header' => 
        // set app_key header
            "app_key:your_app_key\r\n" . 
		// set app_id header
            "app_id:your_app_id\r\n" . 
        // set accept header
            "accept:application/json\r\n"
    )
);

$context = stream_context_create($opts);
$file = file_get_contents($baseAddress . $resource . '?' . $getdata, false, $context);
print_r($file);
?>





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

<?php

// set base address
$baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";

// set resource
$resource = "substances";

// set query parameters:q,limit,offset
$q      = '{"identifiers.identifier.value": "50-00-0"}';
$limit  = 10;
$offset = 0;

$getdata = http_build_query(array(
    'q' => $q,
    'limit' => $limit,
    'offset' => $offset
));

$opts = array(
    'http' => array(
        'method' => "GET",
        'header' => 
        // set app_key header
            "app_key:your_app_key\r\n" . 
		// set app_id header
            "app_id:your_app_id\r\n" . 
        // set accept header
            "accept:application/json\r\n"
    )
);

$context = stream_context_create($opts);
$file = file_get_contents($baseAddress . $resource . '?' . $getdata, false, $context);
print_r($file);
?>





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

<?php

// set base address
$baseAddress = "https://sandbox.chemadvisor.io/chem/rest/v2/";

// set resource
$resource = "regulatory_lists";

// set query parameters:q,limit,offset
$q      = '{$and: [{"tags.tag.name": "OEL"}, {"tags.tag.name": "Canada"}]}';
$limit  = 10;
$offset = 0;

$getdata = http_build_query(array(
    'q' => $q,
    'limit' => $limit,
    'offset' => $offset
));

$opts = array(
    'http' => array(
        'method' => "GET",
        'header' => 
        // set app_key header
            "app_key:your_app_key\r\n" . 
		// set app_id header
            "app_id:your_app_id\r\n" . 
        // set accept header
            "accept:application/json\r\n"
    )
);

$context = stream_context_create($opts);
$file = file_get_contents($baseAddress . $resource . '?' . $getdata, false, $context);
print_r($file);
?>