Skip to content

Instantly share code, notes, and snippets.

@kanafghan
Last active June 23, 2024 14:05
Show Gist options
  • Save kanafghan/2fee17f767105893a41bd6390b909996 to your computer and use it in GitHub Desktop.
Save kanafghan/2fee17f767105893a41bd6390b909996 to your computer and use it in GitHub Desktop.
Billy API Integration - Bill creation

1) Upload attachment file

const axios = require('axios');

let data = '<file contents here>';

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.billysbilling.com/v2/files',
  headers: {
    'X-Access-Token': process.env.ACCESS_TOKEN,
    'X-Filename': '<filename>', 
    'Content-Type': 'text/plain'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

The format of the content of the file in the data variable is not known as of yet. Through Postman the "Body" of the request was set to "binary" and a file was selected from the filesystem.

Example Response

{
    "meta": {
        "statusCode": 200,
        "success": true,
        "time": 0.43650507926941
    },
    "files": [
        {
            "id": "kvT68MQ9QkmmMDOYHJWRkQdx44IS4CMHBpEQU7HGmEVPykkfCdv5C0A2YMk3Ykn8",
            "createdTime": "2024-03-28T11:09:23",
            "fileName": "20240303_132634.jpg",
            "fileSize": 1207822,
            "fileType": "jpg",
            "thumbnailOfId": null,
            "isImage": true,
            "isPdf": false,
            "imageWidth": 1800,
            "imageHeight": 4000,
            "downloadUrl": "https://billysbilling-eu.s3.eu-north-1.amazonaws.com/billy/billy_production/File/k/v/T/6/8/M/Q/9/Q/k/m/m/M/D/O/Y/H/J/W/R/k/Q/d/x/4/4/I/S/4/C/M/H/B/p/E/Q/U/7/H/G/m/E/V/P/y/k/k/f/C/d/v/5/C/0/A/2/Y/M/k/3/Y/k/n/8/kvT68MQ9QkmmMDOYHJWRkQdx44IS4CMHBpEQU7HGmEVPykkfCdv5C0A2YMk3Ykn8/1/20240303_132634.jpg?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAI3UB2NGNBMJU3Y4A%2F20240328%2Feu-north-1%2Fs3%2Faws4_request&X-Amz-Date=20240328T110923Z&X-Amz-SignedHeaders=host&X-Amz-Expires=604800&X-Amz-Signature=6f3dc7d32d100724ae2ee17e20e28782eda6cedd966182096d7c7dbbe1ec55ba",
            "originalUrl": "https://billysbilling-eu.s3.amazonaws.com/billy/billy_production/File/k/v/T/6/8/M/Q/9/Q/k/m/m/M/D/O/Y/H/J/W/R/k/Q/d/x/4/4/I/S/4/C/M/H/B/p/E/Q/U/7/H/G/m/E/V/P/y/k/k/f/C/d/v/5/C/0/A/2/Y/M/k/3/Y/k/n/8/kvT68MQ9QkmmMDOYHJWRkQdx44IS4CMHBpEQU7HGmEVPykkfCdv5C0A2YMk3Ykn8/1/20240303_132634.jpg",
            "dataJson": null
        }
    ]
}

2) Create bill

const axios = require('axios');

let data = JSON.stringify({
  "bill": {
    "organizationId": "qPSnjuT5QtWuv4sGkGOrBQ",
    "contactId": "WsuqoGmbTUSWkHlyry1bNg",
    "entryDate": "2024-03-03",
    "dueDate": "2024-03-03",
    "paymentAccountId": "nRplmS2jSNyN1IcgUYJmVw",
    "paymentDate": "2024-03-03",
    "lines": [
      {
        "accountId": "2GYweu3wSrAk89QnZMQCYQ",
        "description": "Udlæg af indkøb til forplejning",
        "amount": 67.96
      }
    ],
    "attachments": [
      {
        "organizationId": "qPSnjuT5QtWuv4sGkGOrBQ",
        "fileId": "kvT68MQ9QkmmMDOYHJWRkQdx44IS4CMHBpEQU7HGmEVPykkfCdv5C0A2YMk3Ykn8"
      }
    ]
  }
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.billysbilling.com/v2/bills',
  headers: { 
    'X-Access-Token': process.env.ACCESS_TOKEN, 
    'Content-Type': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

organizationId

The ID of the company the bill will be created under, e.g. "Appudvikleren ApS".

contactId

The ID of the vendor/supplier the bill is from, e.g. "ABC LAVPRIS, Fredericia ApS". Can be found under https://mit.billy.dk/{organization-slug}/contacts/{contactId}/supplier.

paymentAccountId and accountId

The ID of the payment account, e.g. "7301 - Udlæg IF", and the accounting account to register the bill under, e.g. "1430 - Forplejning". Can be found under https://mit.billy.dk/{organization-slug}/accounts#/{accountId}.

fileId

The ID of the file (image/PDF) which was uploaded above.

Example Response

{
    "meta": {
        "statusCode": 200,
        "success": true,
        "time": 0.16824507713318
    },
    "bills": [
        {
            "id": "xQn1pMXNSvuNRAjC0FGZuA",
            "organizationId": "qPSnjuT5QtWuv4sGkGOrBQ",
            "type": "bill",
            "createdTime": "2024-03-28T12:12:59",
            "approvedTime": null,
            "externalId": null,
            "contactId": "WsuqoGmbTUSWkHlyry1bNg",
            "contactName": null,
            "entryDate": "2024-03-03",
            "paymentAccountId": "nRplmS2jSNyN1IcgUYJmVw",
            "paymentDate": "2024-03-03",
            "dueDate": "2024-03-03",
            "isBare": false,
            "state": "draft",
            "suppliersInvoiceNo": null,
            "taxMode": "excl",
            "voucherNo": "",
            "scanType": "none",
            "scannedState": null,
            "origin": "api",
            "scannedCode": null,
            "scannedValidation": false,
            "amount": 67.96,
            "tax": 0,
            "grossAmount": 67.96,
            "currencyId": "DKK",
            "exchangeRate": 1,
            "balance": 67.96,
            "isPaid": false,
            "lineDescription": "Udlæg af indkøb til forplejning",
            "creditedBillId": null,
            "source": null,
            "subject": null
        }
    ],
    "billLines": [
        {
            "id": "ttgeUpoxTXKH1MwN2PpfRg",
            "billId": "xQn1pMXNSvuNRAjC0FGZuA",
            "accountId": "2GYweu3wSrAk89QnZMQCYQ",
            "taxRateId": null,
            "productId": null,
            "description": "Udlæg af indkøb til forplejning",
            "bookkeepingTag": null,
            "quantity": 1,
            "amount": 67.96,
            "tax": 0,
            "priority": 0
        }
    ],
    "attachments": [
        {
            "id": "JqwMGSzMSTO3CosHyKtEOA",
            "organizationId": "qPSnjuT5QtWuv4sGkGOrBQ",
            "createdTime": "2024-03-28T12:12:59",
            "ownerReference": "bill:xQn1pMXNSvuNRAjC0FGZuA",
            "ownerId": "xQn1pMXNSvuNRAjC0FGZuA",
            "fileId": "kvT68MQ9QkmmMDOYHJWRkQdx44IS4CMHBpEQU7HGmEVPykkfCdv5C0A2YMk3Ykn8",
            "priority": 1,
            "amount": null,
            "supplier": null,
            "documentDate": null,
            "comment": null,
            "type": null
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment