如何使用 REST 将带有附件的文档上传到 Exact Online API

How to upload a document with attachments into Exact Online using REST API

我想将文件作为附件上传到 Exact Online 中的文档。

以下SQL已用于创建文档:

insert into exactonlinerest..documents
( salesinvoicenumber
, type
, subject
, account
)
select 16700001
,      10
,      'subject 3'
,      id 
from   Accounts 
where  code like '%24274514'

这会创建一个与 Exact 的销售发票 16700001 相关的文档,并将其与帐户(客户)24274514 相关联。

当我通过Exact Online的REST APIs执行如下插入语句时:

insert into exactonlinerest..DocumentAttachments 
( attachment
, document
, filename
)
select attachment
,      'ea2d9221-31b0-4217-a82f-f29c5d517b41'
,      filename 
from   exactonlinerest..documentattachments
where  filename like 'Loonstrook%'

我得到一个错误:

itgenoda001: Verplicht: Bijlage (https://start.exactonline.nl/api/v1/102673/documents/DocumentAttachments)

如何将 Exact Online 中包含的这些现有工资单作为附件上传到新文档?

PS。 GUID ea2d9221... 是在插入文档后通过查询文档找到的。

REST API table documentattachmentsattachment 列在检索时始终为空。

您可以使用伪列 attachmentfromurl,如下所示:

insert into exactonlinerest..DocumentAttachments 
( attachment
, document
, filename
)
select attachmentfromurl
,      'ea2d9221-31b0-4217-a82f-f29c5d517b41'
,      filename 
from   exactonlinerest..documentattachments
where  filename like 'Loonstrook%'

attachmentfromurl 列不能被 Invantive SQL 的 http_get table 函数或类似的普通 SQL 函数替换,因为 OAuth2 令牌不会自动添加到 HTTP 请求中,因为 Exact 使用 URL,例如:

https://start.exactonline.nl/docs/SysAttachment.aspx?ID=f28fd698-756f-4052-bea9-fc2130fe9ab1&Division=102673

当文档附件来自 Exact 本身时。

对于 http://www.cnn.com 这样的外部资源,这会起作用。

结果:

编辑:

您还可以使用以下查询从文件系统上传文件:

insert into exactonlinerest..DocumentAttachments
( attachment
, document
, filename
)
select file_contents
,      dct.some_guid
,      file_path
from   ( select min(id) some_guid from exactonlinerest..documents ) dct
join   files('c:\windows\system32', '*.png', false)@os
join   read_file(file_path)@os
union all
select file_contents
,      dct.some_guid
,      file_path
from   ( select min(id) some_guid from exactonlinerest..documents ) dct
join   files('c:\windows\system32', '*.exe', false)@os
join   read_file(file_path)@os

请注意,每个文件似乎有 22 MB 的限制。