Upload attachments
Understand how to upload attachments to records in Codat's supported accounting softwares
Supported accounting data types
dataType | UploadAttachment |
---|---|
billCreditNotes | ✅ |
bills | ✅ |
directCosts | ✅ |
directIncomes | ✅ |
invoices | ✅ |
transfers | ✅ |
View the full details of Codat's support for uploading attachments for each accounting software in our Data Coverage Explorer.
Process
To perform an attachment upload request, follow these steps:
-
Make a write request: Once completed, you will receive a write request ID, which can be used to track the status of the request.
-
Consume the relevant
{dataType}.write.{successful|unsuccessful}
webhook: Subscribe to this webhook to receive notifications on the success or failure of the write request.
Make a write request
To upload an attachment to a record, you’ll need the company ID, relevant connection ID, the record ID for the data type, and the file itself.
- TypeScript
- Python
- C#
- Go
- Java
const uploadAttachmentResponse = await sdk.bills.uploadAttachment({
companyId: companyId,
connectionId: connectionId,
billId: billId,
attachmentUpload: {
file: {
content: new TextEncoder().encode(fileContent),
fileName: fileName,
},
},
});
upload_attachment_response = sdk.bills.upload_attachment(operations.UploadBillAttachmentRequest(
company_id=company_id,
connection_id=connection_id,
bill_id=bill_id,
attachment_upload=shared.AttachmentUpload(
file=shared.CodatFile(
content=file_content.encode(),
file_name=file_name,
)
)
))
var uploadAttachmentResponse = await skd.Bills.UploadAsync(new UploadBillAttachmentRequest() {
CompanyId = companyId,
ConnectionId = connectionId,
BillId = billId,
File = new CodatFile(){
Content = fileContent,
FileName = fileName
}
});
ctx := context.Background()
uploadAttachmentResponse, err := sdk.Bills.UploadAttachment(ctx, operations.UploadBillAttachmentRequest{
CompanyID: companyID,
ConnectionID: connectionID,
BillID: billID,
AttachmentUpload: &shared.AttachmentUpload{
File: shared.CodatFile{
Content: []byte(fileContent),
FileName: fileName,
},
},
})
UploadBillAttachmentRequest uploadAttachmentRequest = UploadBillAttachmentRequest.builder()
.companyId(companyId)
.connectionId(connectionId)
.billId(billId)
.attachmentUpload(AttachmentUpload.builder()
.file(CodatFile.builder()
.content(fileContent.getBytes())
.fileName(fileName)
.build())
.build())
.build();
UploadBillAttachmentResponse uploadAttachmentResponse = sdk.bills().uploadAttachment()
.request(uploadAttachmentRequest)
.call();
Consume the data type's write webhook
Subscribe to the {dataType}.write.{successful|unsuccessful}
webhook to track the outcome of a completed write request.
The payload includes information about the company, record ID to upload the attachment to and, on success, the attachment ID.
In the Settings > Webhooks > Events > Configure consumer view of the Codat Portal, click Add endpoint to create a webhook consumer that listens for the {dataType}.write.{successful|unsuccessful}
event types. You can review detailed instructions in our documentation for consuming webhook messages.
Example payload
{
"id": "bae71d36-ff47-420a-b4a6-f8c9ddf41140",
"eventType": "bills.write.successful",
"generatedDate": "2023-05-03T10:00:23.000Z",
"payload": {
"id": "a9367074-b5c3-42c4-9be4-be129f43577e",
"type": "Create",
"referenceCompany": {
"id": "70af3071-65d9-4ec3-b3cb-5283e8d55dac",
"name": "Toft stores"
},
"connectionId": "12571faf-0898-47e7-afdd-0fe9eb0a9bf5",
"requestedOnDate": "2023-05-03T10:00:00.000Z",
"completedOnDate": "2023-05-03T10:00:23.000Z",
"status": "Success",
"record": {
"id": "bil_1Nispe2eZvKYlo2Cd31jOCgZ"
},
"attachmentId": "att_2Ksoie6eDvErJo249lsieqpD9"
}
}