i trying post invoice xero. here function
<?php function callapi($url, $method, $parameters, $options, &$response) { if (!isset($options['resource'])) $options['resource'] = 'api call'; if (!isset($options['convertobjects'])) $options['convertobjects'] = false; $version = intval($this->oauth_version); $two_legged = ($version === 1 && isset($options['2legged']) && $options['2legged']); if (strlen($this->access_token) === 0 && !$two_legged) { if (!$this->retrievetoken($valid)) return false; if (!$valid) return $this->seterror('the access token not set valid value'); } switch ($version) { case 1: if (!$two_legged && strlen($this->access_token_expiry) && strcmp($this->access_token_expiry, gmstrftime('%y-%m-%d %h:%m:%s')) <= 0) { if (strlen($this->refresh_token) === 0) return ($this->seterror('the access token expired , no refresh token available')); if ($this->debug) $this->outputdebug('refreshing oauth access token expired on ' . $this->access_token_expiry); $oauth = array( 'oauth_token' => $this->access_token, 'oauth_session_handle' => $this->refresh_token ); if (!$this->processtoken1($oauth, $access_token)) return false; if (isset($options['failonaccesserror']) && $options['failonaccesserror'] && strlen($this->authorization_error)) { $this->error = $this->authorization_error; return false; } if (!isset($access_token['authorized']) || !$access_token['authorized']) return ($this->seterror('failed obtain renewed expired access token')); $this->access_token = $access_token['value']; $this->access_token_secret = $access_token['secret']; if (isset($access_token['refresh'])) $this->refresh_token = $access_token['refresh']; } $oauth = array(); if (!$two_legged) $oauth[strlen($this->access_token_parameter) ? $this->access_token_parameter : 'oauth_token'] = $this->access_token; break; case 2: if (strlen($this->access_token_expiry) && strcmp($this->access_token_expiry, gmstrftime('%y-%m-%d %h:%m:%s')) <= 0) { if (strlen($this->refresh_token) === 0) return ($this->seterror('the access token expired , no refresh token available')); if ($this->debug) $this->outputdebug('refreshing oauth access token expired on ' . $this->access_token_expiry); if (!$this->processtoken2(null, true)) return false; if (isset($options['failonaccesserror']) && $options['failonaccesserror'] && strlen($this->authorization_error)) { $this->error = $this->authorization_error; return false; } } $oauth = null; if (strcasecmp($this->access_token_type, 'bearer')) $url.= (strcspn($url, '?') < strlen($url) ? '&' : '?') . (strlen($this->access_token_parameter) ? $this->access_token_parameter : 'access_token') . '=' . urlencode($this->access_token); break; default: return ($this->seterror($this->oauth_version . ' not supported version of oauth protocol')); } return ($this->sendapirequest($url, $method, $parameters, $oauth, $options, $response)); }
and keep getting error
i connected xero api, stuck post invoice using xml.
<?php $url = 'xml/invoice.xml'; $xml = simplexml_load_file($url); $success3 = $client->callapi('https://api.xero.com/api.xro/2.0/invoices', 'post', array( 'format' => 'text/xml', 'file' => $xml ) , array( 'failonaccesserror' => true, 'decodexmlresponse' => 'simplexml' ) , $user3);
this code have, not sure if works way. error response.
simplexmlelement object ( [errornumber] => 17 [type] => nodataprocessedexception [message] => no data has been processed endpoint. endpoint expecting invoice data specifed in request body. )
here code using
<?php /* * login_with_xero.php * * @(#) $id: login_with_xero.php,v 1.2 2014/03/16 12:41:48 mlemos exp $ * */ /* * http.php file http://www.phpclasses.org/httpclient */ require ('http.php'); require ('oauth_client.php'); $client = new oauth_client_class; $client->debug = false; $client->debug_http = true; $client->server = 'xero'; $client->redirect_uri = 'http://' . $_server['http_host'] . dirname(strtok($_server['request_uri'], '?')) . '/login_with_xero.php'; $client->client_id = '3tbw9ei6kffd6gdekedstkzxhfvolk'; $application_line = __line__; $client->client_secret = 'oqzjtydzqh0cteknh1mwcty3ajftu0'; if (strlen($client->client_id) == 0 || strlen($client->client_secret) == 0) die('please go xero applications page https://api.xero.com/application/add , ' . 'create application, , in line ' . $application_line . ' set client_id consumer key , client_secret consumer secret. ' . 'the callback url must ' . $client->redirect_uri . ' if want post ' . 'the user timeline, make sure application create has write permissions'); if (($success = $client->initialize())) { if (($success = $client->process())) { if (strlen($client->access_token)) { $success = $client->callapi('https://api.xero.com/api.xro/2.0/users', 'get', array() , array( 'failonaccesserror' => true, 'decodexmlresponse' => 'simplexml' ) , $user); $success2 = $client->callapi('https://api.xero.com/api.xro/2.0/invoices', 'get', array() , array( 'failonaccesserror' => true, 'decodexmlresponse' => 'simplexml' ) , $user2); $url = 'xml/invoice.xml'; $xml = simplexml_load_file($url); echo $xml; $success3 = $client->callapi('https://api.xero.com/api.xro/2.0/invoices', 'post', array( 'format' => 'text/xml', 'file' => $xml ) , array( 'failonaccesserror' => true, 'decodexmlresponse' => 'simplexml' ) , $user3); } } $success = $client->finalize($success); } if ($client->exit) exit; if ($success) { ?> <!doctype html public "-//w3c//dtd html 4.01 transitional//en"> <html> <head> <title>xero oauth client results</title> </head> <body> <?php echo '<h1>', htmlspecialchars($user->users->user->firstname) , ' have logged in xero!</h1>'; echo '<pre>', htmlspecialchars(print_r($user, 1)) , '</pre>'; echo '<pre>', htmlspecialchars(print_r($user2, 1)) , '</pre>'; echo '<pre>', htmlspecialchars(print_r($user3, 1)) , '</pre>'; ?> </body> </html> <?php } else { ?> <!doctype html public "-//w3c//dtd html 4.01 transitional//en"> <html> <head> <title>oauth client error</title> </head> <body> <h1>oauth client error</h1> <pre>error: <?php echo htmlspecialchars($client->error); ?></pre> </body> </html> <?php } ?>
change 'format' => 'text/xml'
format' => 'xml'
.
Comments
Post a Comment