Przewodnik wdrożeniowca > Pobierz dane dokumentu

Odczytanie danych dokumentu

Definicja parametrów:

<?php

/**
 *  Zwraca dane dokumentu o przekazanym w parametrze identyfikatorze
 *   
 *  @param doc_id Int - identyfikator dokumentu (documents.doc_id)
 *  @param return_json Boolean - określa postać w jakiej zostanie zwrócony wynik (false - tablica; true - JSON), domyślnie false
 *   
 *  @return Array - tablica asocjacyjna z danymi dokumentu, SoapFault w razie niepowodzenia
 *   
 *  @throws Exception - SoapFault
 */
Array getDocument(Int doc_id, Boolean return_json = false)

?>

Przykłady wywołań:


// Plik MyService.php umieszczony w apps/edokumenty.
// MyService.php
<?php

define('EDOK_API_LOGIN', 'developer');
define('EDOK_API_PASSWORD', 'developer');
define('DEFAULT_ENTITY_SYMBOL', 'demo');

require_once('./classes/eDokumentyApi/EDokApiClient.inc');

$options = array(
    'location' => 'http://{host}:{port}/eDokumentyApi.php',
    "uri" => "eDokumentyAPI",
    'encoding'=>'UTF-8'
);
        
$client = new EDokApiClient(NULL, $options);
$client->setUser(EDOK_API_LOGIN);
$client->setPass(md5(EDOK_API_PASSWORD));
$header = new SoapHeader('eDokumentyAPI', 'entity_symbol', DEFAULT_ENTITY_SYMBOL);
$client->__setSoapHeaders($header);


$document = null;
$doc_id = 123;

try {
    
    $document = $client->getDocument($doc_id, false);
    var_dump($document);

} catch(SoapFault $fault) {
    
    var_dump($fault);
    
    if ($fault->faultcode < 100) {
        trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
    }
}

?>