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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@LexKoomen There's a mistake in your code:
You should check whether or not the
Topic
value exists before calling theattributes
function.