Voucher data extraction API documentation

Dynaccount's voucher data extraction API allows external use of the implemented invoice data extration in Dynaccount. It extracts structured data from invoices and vouchers, via standard HTTP requests and returns the result. The current API version is v1, and you can download a PHP library to handle the communication between your own application and Dynaccount.

If you want access to this API, please send us a mail.

Introduction


Keep-Alive connection

For best performance with the API (or any API in general), you must re-use the same TCP connection for all requests, so TLS handshake and DNS lookup are only performed once. TLS handshake and DNS lookup are expensive in terms of performance.

Encoding

All text strings you send via HTTP requests must be UTF-8 encoded.

Authentication (X-Hash header)


To access the API you need to contact us to get your credentials.

Credentials
API_ID Unique integer identification
API_KEY 40 digit SHA-1 string
API_SECRET 40 digit SHA-1 secret string
HTTP request:
POST /v1/{API_ID}/{API_KEY}/scan HTTP/2
Host: api-scan.dynaccount.com
Content-Type: multipart/form-data; boundary=aLongUniqueRandomGeneratedTextString
Content-Length: 7555
Accept-encoding: gzip
X-Hash: 58ea269911777b0ac911a9e74f510018c7a37877

--aLongUniqueRandomGeneratedTextString
Content-Disposition: form-data; name="json"
Content-Length: 65

{"document":{"type":"INVOICE","country":"dk","vatno":"34223475"}}
--aLongUniqueRandomGeneratedTextString
Content-Disposition: form-data; name="file"; filename="file.pdf"
Content-Type: application/gzip
Content-Length: 7487

[content of file]
--aLongUniqueRandomGeneratedTextString--

X-Hash header is a SHA-1 hash of URL, POST data and API_SECRET.

Generate X-Hash with PHP:
$url = 'api-scan.dynaccount.com/v1/{API_ID}/{API_KEY}/scan';

$file = gzencode( file_get_contents( 'file.pdf' ) );

// 	The company which is the recipient of the invoice
$company_country = 'DK';
$company_vatno = '34223475';

$json = '{"document":{"type":"INVOICE","country":"' . $company_country . '","vatno":"' . $company_vatno . '"}}';

$hash_base = $json . $file;

//	X-Hash header: SHA-1 hash of URL, POST data and API_SECRET
$header_x_hash = sha1( $url . $hash_base . '{API_SECRET}' );

HTTP codes


Code Message Description
200 OK The request was processed with success.
400 Bad request Unspecified error occurred.
401 Unauthorized The X-hash header has failed verification.
402 Payment required The subscription has expired.
403 Forbidden Your IP has been temporary blocked due to too many unauthorized requests.
404 Not found Resource not found.
405 Method not allowed Method not allowed.
408 Request timeout 180 seconds processing time allowed for each file.
415 Unsupported media type Unsupported file type uploaded.
422 Unprocessable entity Could not process the input data. Invalid fields, required fields are missing or invalid data.
503 Service unavailable Service is unavailable due to maintenance.

PHP library


You can download a PHP library to handle all requests to the API.

Below is an example on how to extract data from an invoice or receipt.

PHP:
try{
	require_once 'Scan.php';
	$Dyn = new \Dynaccount_API\Scan($api_id, $api_key, $api_secret);
	$Dyn->connect();
	
	//	The company which is the recipient of the invoice/receipt
	$company_country = 'DK';
	$company_vatno = '34223475';
	
	$result = $Dyn->scan_invoice($company_country, $company_vatno, file_get_contents('file.pdf'));
	print_r($result);
	
	$Dyn->disconnect();
}
catch(\Dynaccount\Error $e){
	echo 'Error: '.$e->getMessage();
}
HTTP request:
POST /v1/{API_ID}/{API_KEY}/scan HTTP/2
Host: api-scan.dynaccount.com
Content-Type: multipart/form-data; boundary=aLongUniqueRandomGeneratedTextString
Content-Length: 7555
Accept-encoding: gzip
X-Hash: 58ea269911777b0ac911a9e74f510018c7a37877

--aLongUniqueRandomGeneratedTextString
Content-Disposition: form-data; name="json"
Content-Length: 65

{"document":{"type":"INVOICE","country":"dk","vatno":"34223475"}}
--aLongUniqueRandomGeneratedTextString
Content-Disposition: form-data; name="file"; filename="file.pdf"
Content-Type: application/gzip
Content-Length: 7487

[content of file]
--aLongUniqueRandomGeneratedTextString--
HTTP response:
HTTP/2 200 OK
Date: Mon, 03 Dec 2018 17:00:56 GMT
Server: nginx
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Content-Encoding: gzip

{
	"result" : {
		"source_file" : {
			"url" : "http:\/\/public-scan.dynaccount.com\/public\/2018-12-03_1_3c4840cf1e3a9541b48135f0467d4846df6e2781.pdf",
			"url_expires" : 3600,
			"type" : "PDF_SCAN",
			"method" : "OCR",
			"resolution" : "300 DPI",
			"file_size_reduction" : "-54.3 %"
		},
		"output" : {
			"num_ocr_results" : 12,
			"lang" : "DA",
			"document_type" : "INVOICE",
			"vatno" : 34223475,
			"vatno_country" : "DK",
			"vatno_name" : "Dynaccount ApS",
			"is_vatno_verified" : 1,
			"reference_id_" : "",
			"order_id_" : 13847,
			"invoice_id_" : 11718,
			"invoice_time" : 1542672000,
			"invoice_time_due" : 1543363200,
			"fi_payment" : "+71<000000001171800+85714821<",
			"is_fi_payment_verified" : 1,
			"bank_code" : "7837",
			"bank_name" : "Jyske Bank",
			"bank_address" : "Nytorv 1",
			"bank_city" : "Aalborg",
			"is_bank_code_verified" : 1,
			"bank_account" : "1202090",
			"is_bank_account_verified" : 1,
			"bank_iban" : "DK5878370001202090",
			"is_bank_iban_verified" : 1,
			"bank_swift" : "JYBADKKK",
			"bank_swift_name" : "Jyske Bank",
			"bank_swift_address" : "Nytorv 1",
			"bank_swift_city" : "Aalborg",
			"is_bank_swift_verified" : 1,
			"total" : "-199700",
			"is_total_verified" : 1,
			"vat" : "-39900",
			"currency" : "DKK",
			"products_pattern" : "AMOUNT_QTY",
			"products" : [
				[
					"product_id_",
					"product_name",
					"amount",
					"qty",
					"total"
				], [
					"SUB12",
					"12 måneders abonnement",
					"13300",
					"1200",
					"159600"
				], [
					"TRNFE",
					"Transaktionsgebyr",
					"200",
					"100",
					"200"
				]
			]
		}
	},
	"metadata" : {
		"request_time" : 6.459967851638794
	}
}