My Products
Help
bergli84
CONTRIBUTOR **

Upload invoice document to voucher

by bergli84

Hi, 

 

Is there a simple way to upload an supplier invoice to a voucher using the api? Also, fetching an existing attachment that is manually uploaded trough GUI using the API

 

Been experimenting with incomingDocument and incomingDocumentAttachment, but can't seem to figure it out

4 REPLIES 4
bergli84
CONTRIBUTOR **

by bergli84

Thank you Øyvind!

 

I will try this and note the temporary storage functionallity

by Øyvind Årseth (Updated ‎10-03-2023 17:39 by Øyvind Årseth VISMA )

Hi Bergli🙂
Try something like the example below. Be aware that the current solution with the Accounting Document Attachment table is temporary, we will switch to a new solution where the files will reside in Azure Blob Storage, so you will have to change your solution a bit later. Plan is to support both file locations in the document viewer though.
Normally, you would increment the incomingDocumentAccountingNo per voucher I suppose. There can be several attachments to the same incomingDocumentAccountingNo, which will be viewed as separate attachments to the same voucher. 

mutation create_batch_and_voucher_with_attachment($cid: Int, $batchId: Int = 0) {
useCompany(no: $cid)
{ batch_create(
            values: [
                {voucherSeriesNo: 300,
                    valueDate: 20230310
                    description: "Test from Postman"}
                    ]
            )
        {
            affectedRows
            items {
                batchNo @export(as: "batchId")}
        }
        voucher_create(
            values: [
                {
                    batchNo: $batchId
                    voucherType: 1
                    creditAccountNo: 1920
                    amountDomestic: 6783.00
                    text: "first voucherline"},
                {
                    batchNo: $batchId
                    voucherType: 1
                    debitAccountNo: 50000
                    amountDomestic: 6783.00
                    text: "second voucherline"},
            ],
            suggest: {
                voucherNo: true
                voucherDate: true
            }
        )
        {affectedRows
        items{
            batchNo
            voucherNo
            voucherDate
        }
        }
        incomingAccountingDocumentAttachment_create(
            values :[
                {
            incomingAccountingDocumentNo: 1,
            attachmentNo: 1,
            attachmentType: 2, # 1=xml, 2=pdf
            fileName:"your.pdf",
            fileData:"valid Base-64 string" #you need to convert pdf to Base-64
                }
        ]
        )
    {
      affectedRows
      items
      {      	
        incomingAccountingDocumentNo
        attachmentNo
        fileNo
      }
    }
    }
}

 

 

 

kashyap
PARTNER

by kashyap

Is it necessary to create batch? Can we create voucher directly?

 

How to attach PDF file to specific voucher? I cannot see any linking of attachment in above given example.

by Øyvind Årseth

Hi, 
Yes, it is necessary. 
The attachment is linked via 

incomingAccountingDocumentAttachment_create

Be aware we are working on a new service to handle attachments, so the API for uploading attachments will change as well. ETA autumn/winter. 
Also nota that the example above uses a deprecated method for suggesting values. The new is found here