public function api($subdomain, $resource, array $parameters = array(), $version = 'v2') {
        $ch = $this->getCurl();
        $url = sprintf($this->domain, $subdomain, $version, $resource);
        
        if (!empty($parameters))
            $url .= "?" . http_build_query($parameters);

        curl_setopt_array($ch, array(
            CURLOPT_URL  => $url,
            CURLOPT_HTTPHEADER => array(
                'Accept: application/xml',
                'Authorization: ' . $this->api_key,
            )
        ));

        $body = curl_exec($ch);

        $errno = curl_errno($ch);
        if ($errno !== 0) {
            throw new Exception(sprintf("Error connecting to CommissionJunction: [%s] %s", $errno, curl_error($ch)), $errno);
        }
        
        $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($http_status >= 400) {
            throw new Exception(sprintf("CommissionJunction Error [%s] %s", $http_status, strip_tags($body)), $http_status);
        }

        $body = preg_replace("/'/", "&#39;", $body);
        $body = preg_replace("/&#11/", "&amp;#11", $body);
        
        return json_decode(json_encode((array)simplexml_load_string($body)), true);
    }