Created
December 30, 2016 21:21
-
-
Save alexjeen/6211c363c4efd4c3034cb3f81f7520bf to your computer and use it in GitHub Desktop.
Exact Online API XML read + write
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\exact; | |
use GuzzleHttp\Client; | |
class RawConnection extends \Picqer\Financials\Exact\Connection | |
{ | |
/** | |
* Gets XML for an division. | |
* | |
* @param string $division division code | |
* @param string $topic the topic | |
* | |
* @return false on failure or SimpleXMLElement | |
*/ | |
public function getXml($division, $topic) | |
{ | |
$headers = ['Authorization' => 'Bearer '.$this->getAccessToken()]; | |
$client = new Client([ | |
'base_uri' => 'https://start.exactonline.nl/docs/', | |
]); | |
try { | |
$response = $client->request('GET', 'XMLDownload.aspx', [ | |
'query' => ['Topic' => $topic, '_Division_' => $division], | |
'headers' => $headers, | |
]); | |
return new \SimpleXMLElement((string) $response->getBody()); | |
} catch (\Exception $e) { | |
} | |
return false; | |
} | |
/** | |
* Gets XML for an division. | |
* | |
* @param string $division division code | |
* @param string $topic the topic | |
* | |
* @return false on failure or SimpleXMLElement | |
*/ | |
public function postXml($division, $topic, $body) | |
{ | |
$headers = ['Authorization' => 'Bearer '.$this->getAccessToken()]; | |
$client = new Client([ | |
'base_uri' => 'https://start.exactonline.nl/docs/', | |
]); | |
try { | |
$response = $client->request('POST', 'XMLUpload.aspx', [ | |
'query' => ['Topic' => $topic, '_Division_' => $division], | |
'headers' => $headers, | |
'body' => $body, | |
]); | |
return new \SimpleXMLElement((string) $response->getBody()); | |
} catch (\Exception $e) { | |
var_dump($e->getMessage()); | |
} | |
return false; | |
} | |
} |
@LexKoomen There's a mistake in your code:
$tspaging = strval($string->Topics->Topic->attributes()->{'ts_d'});
$array[$i]=$string;
You should check whether or not the Topic
value exists before calling the attributes
function.
if(isset($string->Topics->Topic)){
$tspaging = strval($string->Topics->Topic->attributes()->{'ts_d'});
$array[$i]=$string;
}
@justijndepover @LexKoomen How can we add filter and change limit from 100 to 1000 ????
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I updated your getXml function because you would only get the first 100 records.
This will get the paging value out of the response and loop it into an array so you would loop through all items in your Exact Online database.