Get started with the API

API concepts, authentication, webhooks, examples and more

Get started

The Billecta API was created to enable partners to integrate their systems directly into Billecta.

To integrate with Billecta you need to start with a test account. A test account is free. Within the test environment you can perform all operations without the concern of your customers getting any test invoice. Please note that the credentials for the test environment logon will not work in the production environment and vice versa.

If you have any questions regarding our API or the integration itself you are welcome to contact us by either sending an email or calling our support. Logs of all requests and possible errors are stored and we're happy to assist with reviewing and troubleshooting.

Once the integration is built and the testing is done you are ready to move to the production environment. Contact Billecta support for planning and creating an account in the production environment.

 Create a free test account

Environments

The following environments are available for integrations.

Environment API Portal
Production https://api.billecta.com https://app.billecta.com
Testing https://apitest.billecta.com https://apptest.billecta.com

Differences between Production and Testing environments

  • We use weaker machines and databases compared to the production environment. Performance is not the same. If you want to do performance test in production like environment, please contact us
  • We release to test without any warning. The environment can sometimes be unresponsive for a few seconds. Releases are made on a average every second day
  • We might release not fully tested code. We do try to test it as much as possible before releasing it to test. If you encounter unexplained error that you are sure are not caused by any change on your side, please contact us
  • No charging is made for using test. It is completely free
  • No mails is sent to the postal offices at all
  • E-mails and SMS are only sent to whitelisted receivers. Please contact us to add emails/phone numbers to the whitelist
  • The test environment is restored from production and cleaned from sensitive data from time to time.

TLS/SSL

All connections to the API must be in the HTTPS protocol with TLS 1.2 or above.

Throttling

By default, Billecta API imposes a rate limit on incorrect API calls. Users are allowed to make up to 50 incorrect calls (response codes ranging from 400 and above except 404) within a 60-second window. If a user exceeds this limit, they will encounter a delay before their next call is accepted. For example, if a user receives an error response within three seconds into the 60-second window, followed by 49 more mistakes within the next 30 seconds, they will need to wait for 27 seconds before they can make another call. The system resets the timer for the next call once the time window after the last incorrect attempt has passed.

The endpoints specified below imposes a rate limit on all requests regardless of response codes.

  • POST /v1/search/actions - 100 per minute and 30 per 10 seconds are allowed.
  • GET /v1/invoice/action/{id} - 600 per minute and 100 per 10 seconds are allowed.
  • GET /v1/invoice/actionbyinvoicenumber/{id}?invoiceNumber={invoiceNumber} - 600 per minute and 100 per 10 seconds are allowed.

The Billecta API will return HTTP 429 if the limit is reached.

XSD

You may automatically generate code and models based on our XSD.

For .NET (Core or Framework) applications you may want to use our SDK instead.

Concepts

You may want to familiarize with some of our concepts in order to get a full understanding and to know how models in your application map to models in the Billecta API.

Domains

All users are part of a 'domain'. Within a domain you can have multiple users and most important multiple companies (called creditors in the API). A company is the legal entity that for instance sends the invoices and receive payments from their customers (called debtors in the API). Users with the same domain can have read/write/attest/etc rights on each creditor.

Companies/Creditors

In the Billecta services, a company is referred to as a 'creditor'. A company/creditor is the legal entity (not private person) that you as an API integrator perform operations on. Almost all requests of the API require that you specify which creditor the request is made for. That is because one user can handle multiple creditors, and data can't be shared between creditors. Each creditor has their own set of debtors, products, cost centers etc that may not be shared between creditors. For instance, creating a product, we need to know which of the creditors in the domain this should be added to. Another example is when making BankID authentications, since the BankID certificate is a contract between the Bank and the company/creditor.

Customers/Debtors

The customers of a creditor are referred to as 'debtors'. Debtors are the entities that receive the invoices and the one paying to the creditor. A debtor can be an individual or a company. In the API the property OrgNo is used regardless wether it is a personal number (social security number) or an organizational number.

Invoices

Billecta has four different invoice types. This table lists the differences between the types.

Type API ActionTypes (See ActionTypeView) Features
Invoice InvoiceAction, DebentureAction, PaymentAdviceAction, CreditInvoiceAction
  • Distribution (all methods)
  • Reconciliation (bankgiro, autogiro, swish, credit card)
  • Bookkeeping
  • Creditation
  • Billecta invoice template
  • Custom invoice template
  • Note: PaymentAdviceAction require that information is sent to Socialnämnden (Social Welfare) before sent to Kronfogden (Bailiff)
Reconciliation invoice ReconciliationInvoiceAction
  • Distribution (all methods)
  • Reconciliation (bankgiro, autogiro, swish, credit card)
  • Custom invoice template
Verification invoice VerificationInvoiceAction
  • Bookkeeping
  • Billecta invoice template
Self invoice SelfInvoiceInvoiceAction

A reconciliation invoice is a subset of an invoice. It requires much less data to be sent to the API and is a faster and slimmer invoice. If a invoice PDF is attached to the invoice distribution (through for instance email, mail, e-invoice, etc) is possible. If no PDF is attached, only reconciliation on incoming payment are made. The loss when using reconciliation invoice is that no bookkeeping can be made since the data sent to the API is not complete. The advantage however is a faster and easier integration and features like swish, credit card payments and autogiro withdrawals are supported just like an ordinary invoice.

A verification invoice is a pure bookkeeping event. You create the verification to write to the bookkeeping and have a 'receipt' on the invoice for tracking.

Invoice stages

An invoice can be in one of the following stages (InvoiceActionStageType)
  • Created - Created as draft. The only stage an invoice is removeable
  • Attested - Attested/Approved and bookkept. Invoice is from now on not removeable.
  • InvoiceSent - Invoice has been sent using the preferred delivery method.
  • ReminderInvoiceSent - Invoice has due and a reminder invoice has been sent.
  • SentToDebtCollection - Invoice has due and has been sent to debt collection.
  • SalesRequested - The invoice is sent to financier for sales (no response received yet)
  • SalesRequestedDenied - The invoice sale request was denied
  • Sold - The invoice sale request was approved and invoice is sold
  • SalesRequestedCancelled - The invoice sale request was approved and then the purchase was cancelled by financier
  • Completed - Invoice has been paid/credited and closed. No more actions can be taken on invoice.

Verification invoice stages

An invoice can be in on one of the following stages (InvoiceActionStageType)
  • Created - Created as draft. The only stage an invoice is removeable.
  • Attested - Attested/Approved and bookkept. Invoice is from now on not removeable.
  • Completed - Invoice has been paid/credited and closed. No more actions can be taken on invoice.

Reconciliation invoice stages

An invoice can be in on one of the following stages (ReconciliationInvoiceActionStageType)
  • InvoiceSent - Invoice has been created and marked as sent.
  • SentToDebtCollection - Invoice has due and has been sent to debt collection.
  • Completed - Invoice has been paid/credited and closed. No more actions can be taken on invoice.

Self invoices

Self invoices are supplier invoices that you create for your supplier to yourself. That is, you are invoicing yourself on behalf of your supplier. Self invoices are widely used when invoice for your customer on their behalf (where payment is made to your account) to their customer. To automatize the payment flow you need to further promote the payment from your account to your customer. In a sense a supplier invoice to you that you create yourself.

Self invoice stages

A self invoice can be in on one of the following stages (SelfInvoiceActionStageType)
  • Created - Created as draft. The only stage a self invoice is removeable.
  • Attested - Attested/Approved and bookkept. Invoice is from now on not removeable.
  • InvoiceSent - Invoice has been sent using the preferred delivery method.
  • PaymentSent - Payment has been sent. Successful payment status from payment system (Bank) has not yet been received.
  • PaymentCancelled - Payment was cancelled either by user or bank.
  • Completed - Payment was successfully made. No more actions can be taken on self invoice.
  • Cancelled - Self invoice has been cancelled and fully credited. No more actions can be taken on self invoice.

Amounts

Amounts in the Billecta API are handled by the Amount/AmountView models. The class contains a Value and a CurrencyCode property. The Value is specified in cents within that currency and is of data type long. For instance, a value of 500.34 SEK should be specified as 50034 in the Value property since SEK currency has 2 cent digits. The first two numbers (from the right are the decimals/cents. The number of decimals can differ from currency to currency. A call to the Currency API will return a list of all currencies and for each currency information on how many numbers in the value that should be decimals.

Ignore ValueForView
ValueForView in the Amount/AmountView structure shall be omitted when calling the API. It is a read only value.

Files

Getting PDFs, ZIPs or other files from Billecta API always returns a FileView object. The FileView object is a reference to a file with meta data. For performance reasons, the file contents are never returned in the property FileView.Data. To download the actual contents a separate call must be made. Please view GET FILE CONTENT/STREAM in the File API for more information.

Basics

Requests & responses

The Billecta API supports both XML and JSON data formations for both request and response calls.

  • By sending application/xml in the Accept header the Billecta API will return XML formatted text.
  • By sending application/xml in the Content-Type header the Billecta API interpret request data as XML.

Same applies for JSON. Sending application/json will interpret requests as JSON and write responses in JSON.

The API responses may have the following HTTP response codes

  • 200 - Everything has passed OK.
  • 400 - Something when wrong. Please refer to the error message in the Header or Response content stream
  • 401 - You are unauthorized to the requested data or the API. Verify that you have specified the correct CreditorPublicId, DebtorPublicId, etc, or contact @brand.TechnicalSupportEmail if everything looks fine in the data.
  • 500 - Some other internal error. Please contact Billecta.Docs.Services.Brand.support@billecta.com.
Default value
The default value is XML if no header is specified, however, JSON is adviced.

Transactional calls

Internet connections are not always stable. Occasions might occur that a successful HTTP 200 response from Billecta API to your system might be interrupted somewhere in the line between Billecta API and your system. In that case your application will assume that the call was never processed and redo the request. In those scenarios duplicate data will be inserted into Billecta API. To handle this, we have a method of handling unique calls.

To ensure unique API requests without duplicate calls, requests to Billecta API can include a request header named 'UniqueApiCallId'. The header value should be of type string and contain between one and fifty characters. The UniqueApiCallId value will be kept in the Billecta for three months before new calls can be made with old UniqueApiCallId values. Requests made to Billecta API with UniqueApiCallId containing a duplicate or invalid value will not be processed and a response with status code 403 (Forbidden) including a status description will be returned.

The UniqueApiCallId can be hash or similar that is calculated in your application and passed in request to Billecta API.

UniqueApiCallId is optional
Note that the UniqueApiCallId is optional. It can also be used in only a subset of calls. For instance payment reqistrations that you might want higher transactional security on.

Errors

All data passed to the Billecta API is validated and upon errors the following codes will be returned

  • 400 - Data is wrong
  • 401 - You are unauthorized to the requested data or the API. Verify that you have specified the correct CreditorPublicId, DebtorPublicId, etc, or contact @brand.TechnicalSupportEmail if everything looks fine in the data.
  • 500 - Some other internal error. Verify that Json/XML is parsable and that Enums are correctly spelled. Please contact @brand.TechnicalSupportEmail in other cases.

401

When requesting data without specifying the correct id:s the API will regardless of if the referenced data exists or not respond with access denied. For instance, when creating a debtor and no creditor is specified (it will be interpreted as the empty guid in that case) the api will respond access denied even though the id reference was empty.

400

Data sent to the Billecta API is always validated against rules and regulations for the expected type of data. For instance, when saving a debtor and setting EInvoiceBank to a non-empty value the organization/person number must be specified. A validation is made in that case and if no organization/person number is specified the API will respond with a 400 error code. To view the error message, you can either read the error message in the header "ErrorMessage" or read the response body content (either Json or XML depending on the "Accept" header value. The error message in the header is encoded in ISO-8859-1 while the content stream is in UTF-8.

Localized errors
Note that errors in the test environment can be localized to English instead of standard language Swedish. To change to English, sign in to the portal in test environment and change the language of the API user.

Authentication

All communications between your system and Billecta is secured and encrypted with SSL. Authentication towards Billecta API can be done in two ways:

  • Basic Authentication with a username and password
  • SecureToken - equal to so called API-key
The methods are described below

Basic Authentication

In order to authenticate a call with Basic Authentication you use the Authorization header. The header should be created accordingly:

  1. Username and password is combined into a string "username:password"
  2. The string should be coded in Base64
  3. The authentication method Basic a space should be preceding the coded string

For example, if the user has "Alladin" as a username and "Sesame, open" as a password, the header should have the following structure:

Authorization: Basic QWxsYWRpbjpTZXNhbWUsIG9wZW4=

You can use Basic authentication in all calls to the Billecta API.

An example using CURL

curl -X "POST" https://api.billecta.com/v1/authentication/apiauthenticate -H "Content-Length:0" -H "Authorization: Basic QWxsYWRpbjpTZXNhbWUsIG9wZW4=" -H "Accept: application/json"

SecureToken authentication

An alternative way where you don't need to use your username and password, is to generate a SecureToken and use it in communication to the Billecta API. To create a SecureToken you need to logon a first time using your username and password, and create a SecureToken. A SecureToken is valid until a new one is generated. When a new SecureToken is created, the old one is revoked and can not be used when authenticating towards the Billecta API. To generate a new SecureToken you make a Basic authentication request with username and password to:

/v1/authentication/apiauthenticate

You find more information about this call in the API reference, see the Authentication section

To authenticate with SecureToken you use the Authorization header. The header should be created accordingly:

  1. Encode the SecureToken in Base64
  2. The authentication method, SecureToken and a space is preceded by the encoded SecureToken

For example if the request to generate a SecureToken returned: 5Uis54EmQ/9jJtGhQoS8K9xHRsMXQhZg== the requests to the Billecta API should contain the following header

Authorization: SecureToken NVVpczU0RW1RLzlqSnRHaFFvUzhLOXhIUnNNWFFoWmc9PQ==

An example using CURL

curl -X "POST" https://api.billecta.com/v1/authentication/apiauthenticate -H "Content-Length:0" -H "Authorization: SecureToken NVVpczU0RW1RLzlqSnRHaFFvUzhLOXhIUnNNWFFoWmc9PQ==" -H "Accept: application/json"
Creating a new SecureToken
Note that if the SecureToken is changed, the user will receive an email regarding the updated SecureToken as a security measurement.

Webhooks

Webhooks can be used for subscribing to a range of events in the Billecta system. When an event is triggered in the Billecta system a POST request to your predefined URL is made. POST data is located in the request content stream. Creating event webhooks is made in the Billecta Portal and requires that you are an administrator when setting up. It is located under settings, then click on the integration tab. Note that the event webhook settings are applied on all your creditors. If the post request from Billecta fails, Billecta will retry 4 times with the interval of:

  • 5 minutes for the first retry
  • 60 minutes for second
  • 3 hours for third
  • 24 hours for the last retry

If the request still fails after 5 tries, an email is sent to the administrator users with the post data included as a json-file.

Data posted in the webhook request

The property 'Data' will contain different types of data depending on the event type. Here is an example.

{ "CreditorPublicId": "00000000-0000-0000-0000-000000000000", "InvoiceNumber": "123", "ActionPublicId": "1234567890", "ActionType": 2, "DebtorPublicId": "0f24721d-4441-421b-bdc4-fcf36eb6193d", "DebtorName": "Jenny Doe", "Amount": { "CurrencyCode": "SEK", "Value": 10000, "ValueForView": 100 }, "CreatedDate": "0001-01-01T00:00:00", "PaymentDate": "2024-11-21T08:33:20.2587824+01:00", "PaymentMeanCode": "BG", "File": { "FilePublicId": "00000000-0000-0000-0000-000000000000", "ContentType": "application/pdf", "Data": "VGVzdA==", "FileName": "File.pdf" }, "PaymentReferenceId": "40edb631-bce9-45c5-94a3-a476ba9d08cc", "ExternalReference": null, "OCR": "115456843215", "CreatedBy": null, "IsReminderPayment": false }

The property 'AdditionalData' will contain different types of data, if it has data, depending on the event type. In most events it will not be included.

Events

Event descriptionEvent typeData typeAdditional Data type
Invoice created InvoiceActionCreatedInvoiceActionView[Nothing]
Invoice updated InvoiceActionUpdatedInvoiceActionView[Nothing]
Invoice deleted InvoiceActionDeletedstring (ActionPublicId)string (DebtorPublicId)
Invoice fully paid InvoiceActionPaidInvoiceActionView[Nothing]
Invoice sale acceptedInvoiceSaleWasAcceptedInvoiceActionView[Nothing]
Invoice sale denied InvoiceSaleWasDeniedInvoiceActionView[Nothing]
Invoice state has changed InvoiceActionStateChangedInvoiceActionView[Nothing]
Invoice has been viewed on 'mypages'InvoiceActionViewedInvoiceActionView[Nothing]
Invoice has been commentedInvoiceCommentedInvoiceActionCommentedView[Nothing]
Invoice email has been openedInvoiceActionOpenedInvoiceActionView[Nothing]
Invoice email or SMS has been receivedInvoiceActionReceivedInvoiceActionView[Nothing]
Invoice attested InvoiceActionAttested InvoiceActionView[Nothing]
Received payment for invoice/reconciliation invoiceInvoicePaymentReceivedIncomingPaymentView[Nothing]
Amount credited on invoice/reconciliation invoiceAmountCreditedOnInvoiceIncomingPaymentView[Nothing]
Amount written off on invoice/reconciliation invoiceAmountWrittenOffOnInvoiceIncomingPaymentView[Nothing]
Reconciliation invoice created ReconciliationInvoiceActionCreatedReconciliationInvoiceActionView[Nothing]
Invoice/Self invoice/Reconciliation invoice/Einvoice email or SMS could not be deliveredUndeliveredInvoiceInvoiceDeliveryStatusView[Nothing]
Successful self invoice payment SelfInvoiceOutgoingPaymentSucceededOutgoingPaymentStatusView[Nothing]
Successful supplier invoice payment SupplierInvoiceOutgoingPaymentSucceededOutgoingPaymentStatusView[Nothing]
Successful payment through the api OutgoingPaymentSucceededOutgoingPaymentStatusView[Nothing]
Failed self invoice payment SelfInvoiceOutgoingPaymentFailedOutgoingPaymentStatusView[Nothing]
Failed supplier invoice payment SupplierInvoiceOutgoingPaymentFailedOutgoingPaymentStatusView[Nothing]
Failed payment through the api OutgoingPaymentFailedOutgoingPaymentStatusView[Nothing]
Unmatched payment UnmatchedPaymentUnhandledPaymentView[Nothing]
Overpayment OverpaymentUnhandledPaymentView[Nothing]
Payment has been received to Billecta client funds account PaymentReceivedToBillectaClientFundsInvoiceActionView[Nothing]
Self invoice created SelfInvoiceActionCreatedSelfInvoiceActionView[Nothing]
Self invoice updated SelfInvoiceActionUpdatedSelfInvoiceActionView[Nothing]
Self invoice attested SelfInvoiceActionAttested SelfInvoiceActionView[Nothing]
Self invoice deleted SelfInvoiceActionDeletedstring (ActionPublicId)string (DebtorPublicId)
Self invoice fully paid SelfInvoiceActionPaidSelfInvoiceActionView[Nothing]
Reminder invoice created ReminderInvoiceActionCreatedReminderInvoiceActionView[Nothing]
Debtor createdDebtorCreatedDebtorView[Nothing]
Debtor updatedDebtorUpdatedDebtorView[Nothing]
Debtor deletedDebtorDeletedstring[Nothing]
Debtor has requested change of stored customer information DebtorInformationCorrectionRequestedDebtorInformationCorrectionRequestView[Nothing]
Unknown e-invoice registration (B2C)UnknownEInvoiceRegistrationEInvoiceRegistrationView[Nothing]
Debtor E-Invoice information updatedEInvoiceInfoOnDebtorChangedDebtorView[Nothing]
Creditor shared CreditorSharedWebhookCreditorShareView[Nothing]
Creditor shared removedCreditorUnshared[Nothing][Nothing]
Creditor created CreditorCreatedCreditorView[Nothing]
Creditor updated CreditorUpdatedCreditorView[Nothing]
Creditor deleted CreditorDeletedstring[Nothing]
Creditor KYC updated CreditorKYCUpdatedCreditorKycView[Nothing]
Autogiro approval failed to register AutogiroApprovalFailedDebtorViewAutogiroApprovalCommentCodeView
Autogiro approval has changed (added, changed or deleted)AutogiroApprovalChangedDebtorViewAutogiroApprovalCommentCodeView
Autogiro withdrawal failed on invoice AutogiroWithdrawalFailedOnInvoiceInvoiceActionViewAutogiroWithdrawalCommentCodeView
Autogiro withdrawal failed on reconciliation invoice AutogiroWithdrawalFailedOnReconciliationInvoiceReconciliationInvoiceActionViewAutogiroWithdrawalCommentCodeView
Autogiro withdrawal failed but new retry will be made tomorrow on invoice AutogiroWithdrawalRenewedOnInvoiceInvoiceActionView[Nothing]
Autogiro withdrawal failed but new retry will be made tomorrow on reconciliation invoice AutogiroWithdrawalRenewedOnReconciliationInvoiceReconciliationInvoiceActionView[Nothing]
Credit card withdrawal failed on invoice CreditCardWithdrawalFailedOnInvoiceInvoiceActionView[Nothing]
Credit card withdrawal failed on reconciliation invoice CreditCardWithdrawalFailedOnReconciliationInvoiceReconciliationInvoiceActionView[Nothing]
Product createdProductCreatedProductView[Nothing]
Product updatedProductUpdatedProductView[Nothing]
Contract invoice createdContractInvoiceActionCreatedContractInvoiceActionView[Nothing]
Contract invoice updatedContractInvoiceActionUpdatedContractInvoiceActionView[Nothing]
Debt collection claim state has changed DebtCollectionActionStateChangedDebtCollectionActionView[Nothing]
Debtor contract createdDebtorContractCreatedDebtorContractView[Nothing]
Debtor contract signedDebtorContractSignedDebtorContractView[Nothing]
Debtor contract cancelledDebtorContractCancelledDebtorContractView[Nothing]
Debtor contract archivedDebtorContractArchivedDebtorContractView[Nothing]
Missing a web hook?
If you are missing a webhook, please send a request to us and we'll add it to the API.

Dates and time zones

The Billecta API server run on Stockholm time zone, ie +01:00 from GMT. All dates passed to Billecta without time zone information are considered as in Stockholm time. Likewise, all dates returned from Billecta API without any time zone information are in Stockholm time. The API should however always return dates with time zone information. When using the SDKs this is managed automatically by the SDK library.

Dates must always be specified in ISO 8601. The standard defines dates in the following format

  • 2017-03-15T06:35:06+00:00
  • 2017-03-15T06:35:06+01:00
  • 2017-03-15T06:35:06Z
  • 20170315T063506Z
  • 2017-03-15

Dates in invoice rows

All invoice rows, products and contract invoice rows that has a description property where the description of the sold entity supports programming of dates in each row. If you want to have, for instance, contract invoices that foreach time a new invoice is created from a certain row should have the current, future or past date certain codes can be put in the invoice rows. The following codes can be inserted in product descriptions and contract invoice row descriptions (if the current date is 2017-03-07):

Pattern Example
{YY} or {ÅÅ} 24 Prints out the current year in short
{YYYY} or {ÅÅÅÅ} 2024 Prints out the current year
{MM}, {MMM} resp. {MMMM} 11, Nov resp. November Prints out the current month as number, short and long formats
{DD} 21 Prints out the current day in the month

All the formats above can have the suffix +/- followed by an integer number. For instance

  • {YYYY+1Y} prints 2025
  • {MMM-2M} prints Sep

The codes above only print parts of a day (year, month or day). When calculating on complete dates the following formats must be used

Pattern Example
{YYMMDD} or {ÅÅMMDD} 241121
{YY-MM-DD} or {ÅÅ-MM-DD} 24-11-21
{YYYYMMDD} or {ÅÅÅÅMMDD} 20241121
{YYYY-MM-DD} or {ÅÅÅÅ-MM-DD} 2024-11-21
{MMM YYYY} or {MMM ÅÅÅÅ} Nov 2024
{MMMM YYYY} or {MMMM ÅÅÅÅ} November 2024

Also, complete dates have support for suffixes using +/- and an integer number. However complete number must also specify which part of the date is added/decreased. You can select amount

  • Y for year. For example {YY-MM-DD+1Y} prints 25-11-21
  • M for month. For example {YY-MM-DD+18M} prints 26-05-21
  • D for day. For example {YY-MM-DD+30D} prints 24-12-21
  • D for day, M for month. For example {YY-MM-DD-30D+2M} prints 24-12-22

Certificates

Test

In production, API features dealing with BankID and Swish require authentic passphrase protected SSL certificates. However, in the test environment certificates are not used and are merely there to simulate production like requirements. You may selfsign or use these in our test environment:

Swish

This is a guide on how to obtain and activate a production Swish certificate with Billecta.

1. Download a PFX file from the Swish portal

Go to the Swish Portal (sv: "Företagsportal") and log in. Download a .pfx file (not PEM) from the portal.

2. Upload the .pfx file in the Billecta portal

BankID

This is a guide on how to create and activate a production BankID certificate with Billecta. This type of BankID certificate is referred to as a "relaying party certificate" or, in Swedish, something like "BankID förlitande part". Either you do most of the steps in the guide yourself, or Billecta may do it for you.

Prerequisites

  • You must have signed a BankID agreement with your organization's bank, regardless.

Assistance

Billecta offers to handle the certificate generation and configuring the addon in case you are not able to do it yourself. For this, Billecta will charge two hours work. Contact for more information.

Assisted scenario

Billecta will give you a certificate signing request file (CSR) which you hand over to your bank. Hand over the resulting certificate returned from the bank to Billecta and we will take care of the rest.

Do it yourself scenario (OpenSSL examples)

Prerequisites

Use a keygen software issued by the bank, by Finansiell ID-teknik BID AB or OpenSSL's tool to create a CSR. Not all keygens expose the private key. If the keygen has support for creating a PFX (by signing with private key and passphrase) from the certificate file from the bank, you may do that. Otherwise, the keygen is not usable for this scenario. If you have a PFX you may upload the PFX and enter the passphrase yourself into the Billecta Mobile BankID addon in the portal. This guide uses OpenSSL.

1. Open the terminal

Windows: press the Windows key, type "cmd" and open it.
Mac/OSX: click search, type "terminal" and open it.

2. Create a private key
openssl genrsa -out my.key 4096

You might need to specify the complete path to openssl.

3. Create a certificate signing request (CSR)

Create a .csr file using your newly created private key.

openssl req -new -key my.key -out my.csr

Fill in the requested information:

Country Name (2 letter code) [AU]: SE State or Province Name (full name) [Some-State]: [Your state, province, municipality or region] Locality Name (eg, city) []: [Your city] Organization Name (eg, company) [Internet Widgits Pty Ltd]:[Your company name] Organizational Unit Name (eg, section) []: IT Common Name (e.g. server FQDN or YOUR name) []: [Your domain (ex: wwww.domain.com)] Email Address []: [Your email address] Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: [A strong password, which you'll note down] An optional company name []: [Leave empty]

Please use a strong passphrase such as 20 random letters and digits.

View my.csr and copy the contents.

Mac: cat my.csr
Windows: notepad my.csr

4. Hand the CSR to your bank

Hand in pasted text or a file. They will answer with a resulting certificate file.

5. Create a .pfx file

You have

  • your selected passphrase (what you typed in to the keygen tool),
  • your private key (generated by the keygen tool) and
  • the certificate file from the bank.

With these, do this:

openssl pkcs12 -export -out my.pfx -inkey my.key -in my.pem

2. Upload the certificate file to the Billecta portal

  • Go to addons (sv: tillägg).
  • Click he pencil () in the mobile BankID addon.
  • Select your certificate file and enter your previous decided passphrase.

3. Verify (optional)

Wait about one minute before pressing the button to verify your certificate.

Use cases

This page and the subsections below describe specific workflows and usages of Billecta API features.

Basic invoicing

This section will describe the most basic operation of sending an invoice using the Billecta API, and it's associated bare necessities.

In order to send and invoice, you need to create products which will go onto the records of the invoice. You also need to create debtors, meaning the recipients of invoices.

  1. Create debtor

    Call POST /v1/debtors/debtor with a DebtorView body.

    Take note of the id in the CreatedView response.

    Debtors are the recipients of invoices, meaning they are the end customers. There is also a plural POST to create several at a time, and a PUT which would update a preexisting entry. Alternatively, you could create the debtors in the portal if you are always invoicing the same small set of customers.

  2. Create product

    Call POST /v1/products/product with a ProductView body.

    Take note of the id in the CreatedView response.

    Product go onto the invoice records. If you are selling furniture, a sofa may be a product. As with debtors, there's also a plural POST to create several at a time, and a PUT (create/update). Alternatively, you could also create products in the portal using your web browser - in case you're going to keep re-using the same small set of already defined products.

  3. Create invoice

    Call POST /v1/invoice/action with an InvoiceActionEntryView body.

    Take note of the id in the CreatedView response.

  4. Attest the invoice

    Call PUT /v1/invoice/attest/{id} with the id returned in the previous step.

    This will deliver the invoice, provided a means of distibution has been set.

That's it — as the most basic invoicing use case. Certainly creating and attesting an invoice could also be done in the portal, but if you're an API user you should get familiar with these fundamenal steps through the API. If you are on a Microsoft .NET platform, we recommend you to try our SDK, which encapsulates the actual requests described here into methods of our .NET NuGet library.

Get bank accounts

The Billecta API has the feature to retrieve bank account numbers for private persons (no support for companies yet and not available in the Billecta portal). Supported banks are defined in the API reference. By specifying a Swedish person number (12 digits) and a bank code the Billecta system may extract the IBAN, clearing code and account numbers from the person's bank. This is mostly useful in the autogiro approval flow but also for other cases.

The flow for getting bank accounts

User mobile/browser Your system Billecta API
1. Your user in your system wants to extract their account number.

2. Your application makes a request to initiate retrieval of bank account numbers in the Billecta API at endpoint /bank/accounts/[...].

3. The Billecta API initiates a mobile BankID authentication to the selected bank and returns a PublicId to reference the initiated request.
5.1 The user opens the app and authenticates themself. 4. Your system receives the PublicId to the initiated requests and instructs the user to open their mobile BankID app (or automatically open their mobile BankID app). Information on how to open BankID app on cell phone is covered in the following link.
5.2 While the user authenticates themself your application polls the Billecta API (each second is sufficient) by making a request to Get bank account numbers in Billecta API. Use the PublicId received when initiating the account number retrieval. 5.3 The Billecta API checks status of authentication and if accounts have been retrieved.
  • If authenticated and accounts retreived: The response will be a BankAccountRequestView with status Success.
  • If not authenticated yet (might take some time): The response will be a BankAccountRequestView with status Waiting. Poll again according to 5.2 after 1 second.
  • If aborted or other error: The response will be a BankAccountRequestView with status Failed.
While polling, you may each time check BankAccountRequestView.QR to see if there is a QR code image to display for the user, and present it to the user if you so wish.
7. User selected one of the accounts.
6. When receiving BankAccountRequestView a response with status Success, present the found accounts to the user.

This means that you first initiate a 'retrieval job' that will get the process going in the background. Then we wait for the users (can take some time). Meanwhile you continuously check the status if the customer has authenticated themselves and if the 'retrieval job' is completed. Once the 'retrieval job' you will get all data collected.

Note that the information is only stored at most 24 hours before the collected data is removed in accordance to GDPR.

BankID authentication/sign

Authentication and sign with mobile BankID are supported as a standalone feature in Billecta API. Detailed information about each call can be found at API reference. By specifying a Swedish person number (12 digits) you can trigger an authentication or sign in your users mobile phones. This can be used for various purposes in your application.

Prerequisites to use the mobile BankID features are

  • A creditor exists in Billecta Portal
  • A mobile BankID certificate has been issued by your bank and uploaded in the Billecta Portal (see instructions)

A mobile BankID certificate must be issued by your bank. Please contact your bank if you don't have one already.

Once you have the mobile BankID certificate, convert it to .pfx certificate with a password (required for security reason) and upload it in Billecta. Sign in to Billecta Portal, open settings and press on Addons. Press on Add Addon and select Mobile BankID. Upload your certificate with your password and press save.

The flow for mobile authentication

The sign process is similiar, but to a different endpoint.

User mobile/browser Your system Billecta API

1. Start by making a request to Create Mobile BankID authentication/sign request in Billecta API (see API reference).

2. Billecta API initiates a mobile BankID authentication with the bank and returns a BankIdAuthenticationStatusView containing a ReferenceToken.
4.1 User open app and authenticates him/her self. 3. Your system receives the BankIdAuthenticationStatusView to the initiated requests and inform the customer to open their mobile BankID app (or automatically open their mobile BankID app). Information on how to open BankID app on cell phone is covered in the following link.
4.2 While user authenticates them self your application polls the Billecta API (each second is sufficient) by making a request to Get Mobile BankID authentication status in Billecta API. Use the ReferenceToken received when initiating the mobile BankID authentication. 4.3 Billecta API checks status of user authentication.
  • If authenticated: The response will be a BankIdAuthenticationStatusView with status Complete.
  • If not authenticated yet (might take som time): The response will be a BankIdAuthenticationStatusView with status Started or OutstandingTransaction. Poll again according to 4.2 after 1 second.
  • If aborted or other error: The response will be a BankIdAuthenticationStatusView with status NoClient or Error.
7. User is authenticated or has signed.
6. When receiving BankIdAuthenticationStatusView a response with status Complete, present to the user that they are authenticated.

This means that you first initiate a 'authenticate job' that will get the process going in the background. Then we wait for the users (can take some time). Meanwhile you continuously check the status if the customer has authenticated themselves and if the 'authenticate job' is completed. Once the 'authenticate job' you will get all data collected (IP-number, etc).

Note that the information is only stored at most 24 hours before the collected data is removed in accordance to GDPR.

Kivra

Kivra Setup

To get started, go to Addons under Settings in the app and enable the Kivra addon. Once Kivra has been enabled, the only remaining task is to update the delivery method for your debtor or select Kivra as the delivery method when creating an invoice through our API. After completing these steps, you're good to go.

Please note that, to send content through Kivra, the following requirements must be fulfilled:

  • The debtor must have an active account with Kivra.
  • The debtor must have a Swedish SSN.
  • The debtor must not have opted out of receiving content from your company.

To check which of your debtors can receive content through Kivra, you can use our endpoint: Check if debtor has enabled Kivra.

Kivra in Test

In our test environment, you can test your Kivra connection. The setup is identical to production. However, to add a user to Kivra in test, you can do any of the following:

  • If you have access to Test BankId, follow these steps: Test Kivra's app with BankID.
  • Send an email to avsandare.support@kivra.com with the following information:
    • Company name
    • Company registration number
  • Contact us, and we will provide you with an SSN that is active in Kivra's Sandbox environment.

Payments with Swish

To get started with allowing payments with Swish within your application the following configuration must be made and flow implemented. By integrating Swish in Billecta API invoices will be automatically processed as paid and bookkept once payment is completed. Swish requires that a Swish certificated is issued by Swish (https://www.getswish.se/). Instructions on how to retrieve a Swish certificate can be read at https://developer.getswish.se/. Please note that you are applying for 'Swish for Merchants'. Also contact your Bank to activate required bank services and more information on how to get started.

Prerequisites to use the Swish features are

  • A creditor exists in Billecta Portal
  • A Swish certificate has been issued and uploaded in the Billecta Portal (see instructions)

The flow for Swish payments

User mobile/browser Your system Billecta API
2. Present the Swish payment form for the user where they should have the possibility to specify their registered phone number for Swish payments.
1. Start by creating an invoice or retrieve the action public id of an existing invoice.
3. User enters phone number and presses 'Pay' (or other button to initiate the payment flow)
4. Your system makes a request to Create Swish payment request in Billecta API (see API reference) with the ActionPublicId and the users phone number.
5. Billecta API initiates a swish payment at Swish and returns a token/public id that identifies the initiated payment.
7.1. User opens the Swish app. The app is prepopulated with you company name and amount to pay.
6.1. Your system receives the token/public to the initiated request and inform the customer to open their Swish app (or automatically open it if user is on a cell phone).
7.2. User approves the payment. If user is on cell phone he/she switches app back to your website and waits for updated status. 6.2. While user approves the payment your application polls Billecta API (each second is sufficient) by making a request to Get Swish payment status in Billecta API. Use the token/public id received when initiating the swish payment. Your system receives the SwishPaymentStatusView to the payment request. If status is 'Created' then keep polling. All other states move down to step 8.
6.3. Billecta contacts Swish and checks status on payment request and returns a SwishPaymentStatusView.
9. Information about the payment status is shown
8. Payment has at this stage either been paid or cancelled depending on the status. If paid, the invoice is marked as paid and payment is registered automatically in Billecta API. If cancelled then no payment has been made. User is informed about the payment status.

This means that you first initiate a 'payment job' that will get the process going in the background. Then we wait for the user to approve the payment in their app (can take some time). Meanwhile you continuously check the status if the payment and if the 'payment job' is completed. Once the 'payment job' is completed then show the user the result.

E-invoice intermediators

The intermediator is the wan carrier that your customers use to receive e-invoices. Intermediator is used for B2B.

These are the intermediators that exists in the system

Enum name Description
ITELLA OpusCapita
TIETOSE Tieto
LOGICA CGI
PROCEEDO Visma Proceedo AB
HUSERA Palette
BASWARE Basware
EDB Evry
STRALFORS1 Strålfors Svenska AB
LIAISON_FI Liaison Technologies
EXPERT Readsoft/Lexmark
ESSESESS SEB
HANDSESS Handelsbanken
DABASESS Danske bank
SWEDSESS Swedbank
NDEASESS Nordea
INEXCHANGE InExchange
SCANCLOUD Scancloud
PAGERO Pagero
CREDIFLOW Crediflow
PEPPOL PEPPOL
COMPELLO Compello
LOGIQ Logiq AS
APIX Apix Messaging AB
AKSESSPUNKT Aksesspunkt Norge AS
FININVOICE Finvoice

E-invoice banks

The bank type is the receiving bank for e-invoices. Bank type is used for B2C and B2B.

These are the banks that exists in the system

Enum name Description
OEB Danske Bank
SEB SEB
SHB Handelsbanken
SKB SkandiaBanken
FSPA Swedbank och övriga Sparbanker
NB Nordea
LFB Länsförsäkringar
FINN Sparbanken Finn
ICA ICA Banken
SYD Sparbanken Syd
DNB DnB Nor
SBF Swedbank (företag)
AAB Ålandsbanken
DBF Danske Bank (företag)
SEBF SEB (företag)
SHBF Handelsbanken (företag)
NBF Nordea (företag)
FRX Forex Bank
MARG Marginalen Bank

Donor organizations with Autogiro

This is an implementation guide for donor a organization (sv: givarorganisation) basic setup with Autogiro.

In order to send and invoice, you need to create products which will go onto the records of the invoice. You also need to create debtors, meaning the recipients of invoices.

  1. Create a product

    One single product needs to be created in Billecta, to be used further on in all billing. Manually create the product in the portal. It is also possible to create products using the API if needed.

  2. Collect donor information

    Use a web form or equivalent to get the donor’s personal number, period (monthly, quarterly, yearly) and the recurring amount.

  3. Collect an Autogiro approval

    If there is no preexisting Autogiro approval for the donor, present the donor with information that they are asked to confirm a bank account for Autogiro withdrawals from your organization. Please see our guide for bank account lookups.

    Documentation: Bank accounts

    As this involves a BankId signing, this is regarded as a proper approval, provided you are giving clear information to the donor. Save the bank account and use it later when creating a contract invoice.

  4. Create a debtor

    Create a debtor. The debtor represents the donor.

    Endpoint: POST /v1/debtors/debtor

    Documentation: Create a debtor

    Intro to lingo and concepts: Concepts

    When creating a debtor, the DebtorView model is populated with Autogiro approval information along with all the other information on the person.

  5. Create a contract invoice

    A contract invoice is a container for recurring billing. In this API call, set AutogiroWithdrawalEnabled in the ContractInvoiceActionView, reference the debtor by DebtorPublicId, among other things.

    Endpoint: POST /v1/contractinvoice/action

    Documentation: Create a contract invoice