i trying use vend api have no clue how pass parameters doing various things. found set of codes in api doc can't through it. below been to.
<?php /** * * class made utility methods around vend's api * * */ class vendapiutils { /** * simple static method call vend api urls * * @param string $url * @param string $username * @param string $password * @param array $params <optional> */ public static function requestvendapiurl($url, $username, $password, $params = array()) { // curl installed? if (!function_exists('curl_init')) { throw new exception('curl not installed!'); } // create new curl instance $ch = curl_init(); $opts = array( curlopt_url => $url, curlopt_returntransfer => 1, curlopt_post => 1, curlopt_postfields => array('data' => json_encode($params)), curlopt_timeout => 120, curlopt_failonerror => 1, curlopt_httpauth => curlauth_any, curlopt_userpwd => "$username:$password" ); // assign curl options curl_setopt_array($ch, $opts); // response $response = curl_exec($ch); print_r($response); // close curl curl_close($ch); // execute request & response echo $response; } } $your_domain='https://mydomain.vendhq.com'; $your_username='myuser'; $your_password='mypass'; $params = array('get'=>'/api/stock_movements'); $response = vendapiutils::requestvendapiurl($your_domain, $your_username,$your_password, $params); //echo $response; ?>
any highly appreicated.
regards, abnab
i'm not sure why think url needs go $params
array; looks me place for, well, params. think function intended used more this:
// fixed parts, same request $domain='https://mydomain.vendhq.com'; $username='myuser'; $password='mypass'; // variable parts, depending on want $url = '/api/stock_movements'; $params = array('some_key' => 'some_value'); $response = vendapiutils::requestvendapiurl($domain . $url, $username, $password, $params);
Comments
Post a Comment