Skip to main content

Upload attachments

Understand how to upload attachments to records in Codat's supported accounting software

Codat offers the ability to upload attachment to records in the supported accounting software. You can write an attachment for the following accounting data types:

Data typeUploadAttachment
billCreditNotes
bills
directCosts
directIncomes
invoices
transfers

Attachment upload process

An attachment upload process at Codat consists of the following steps:

  1. Make a write request

    Once completed, you will receive a write request ID. Use it to track the status of the request.

  2. Consume the relevant write webhook

    Subscribe to the relevant {dataType}.write.{successful|unsuccessful} webhook to receive notifications of the success or failure of the write request.

Make a write request

To upload an attachment to a record, include the company ID, relevant connection ID, the record ID for the data type, and the attachment file itself in your API call.

In the example below, we are uploading an attachment for our bills data type.

const uploadAttachmentResponse = await sdk.bills.uploadAttachment({
companyId: companyId,
connectionId: connectionId,
billId: billId,
attachmentUpload: {
file: {
content: new TextEncoder().encode(fileContent),
fileName: fileName,
},
},
});

Consume the write webhook

Subscribe to our data type-specific webhooks to track the outcome of a completed write request:

  • {dataType}.write.successful
  • {dataType}.write.unsuccessful

To create a webhook consumer for these event types, navigate to Settings > Webhooks > Events > Configure consumer in the Codat Portal and click Add endpoint. See Build webhook consumers to subscribe to events for detailed instructions.

The webhook's payload includes information about the company ID and record ID the attachment upload was attempted for. If the write operation is successful, the payload also includes the attachment ID. We provided an example webhook payload for a successful write operation uploading an attachment to a bill.

Example webhook 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"
}
}

Was this page useful?
👏
👍
🤔
👎
😭