Menu

Bilagscan API dokumentation

You can read more about Dynaccount Bilagscan API and it's features under Automatisk/OCR bogføring.

Introduction

Dynaccount's Bilagscan API allows external use of Bilagscan where you can send invoices and receipts via standard HTTP requests, and get a scan result as response. The current API version is v1.

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

You can download a PHP library under Download to handle the communicationen between your own application and Dynaccount.

Keep-Alive connection

To acheive best performance always re-use the TCP connection for all requests to avoid the DNS lookup and SSL handshake round trip at each request. Both are expensive performance wise.

Encoding

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

Authentication

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

API_ID Unique integer identification
API_KEY 40 digit SHA-1 random calculated key
API_SECRET  40 digit SHA-1 secret random calculated key
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}' );

PHP library

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

Below is an example on how to scan an invoice or receipt.

PHP:
try{
	require_once 'Dynaccount_API_scan.php';
	$Dyn = new \Dynaccount\Scan_API($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($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" : 13.459967851638794
	}
}