Laravel Sevdesk API - Integration of the Accounting Software
Hi everyone,
Today we’re dealing with Laravel and how to integrate the Sevdesk API. What helps us with this is the Laravel Sevdesk package that I started developing at some point. Originally, the package was created to make writing code easier for me and to simplify development. The package is still far from perfect, so if you have suggestions or find errors, please let me know.
What Is Laravel?
Laravel is a popular PHP web framework that helps developers quickly and easily create modern web applications. It offers a variety of functions and tools that allow developers to create robust and scalable applications without having to develop from scratch. Laravel comes with an MVC architecture and supports various databases like MySQL, PostgreSQL, and SQLite. It’s known for its ease of use and comprehensive documentation, which makes it easy for beginners to quickly become familiar with it.
And What Is Sevdesk?
Sevdesk primarily sees itself as an accounting program that also allows you to manage your invoices. The software also includes contact management, templates for texts and layouts, as well as analysis tools. With the “Inventory Management” plan, you can also use SevDesk as an inventory management system.
Laravel Installation
To use the package in our Laravel project, we first need to ensure that Laravel is properly installed and set up. The installation and configuration of Laravel is not our main topic for today, as there are already many other people and bloggers who have described this in more detail. Here I’ll only show the standard installation using Composer. At the time of publication, Laravel 9 is the latest version.
composer create-project --prefer-dist laravel/laravel laravel-sevdesk
Laravel Sevdesk Package Installation
The Sevdesk package is also installed via Composer.
composer require exlo89/laravel-sevdesk-api
Configuration
To use the sevDesk API in Laravel, you first need to create a sevDesk account and generate an API token. You add the generated API token to the .ENV file.
SEVDESK_API_TOKEN=secret_token
That Was Actually Almost It…
… now you can get started. What’s still missing is implementing your own instance for the package and then you can create, view, or delete invoices using the helpful functions. Let’s look at a few examples.
$sevdeskApi = SevdeskApi::make();
$sevdeskApi->contact()->createSupplier('Supplier Organisation', $parameters);
$sevdeskApi->contact()->createCustomer('Customer Organisation', $parameters);
$sevdeskApi->contact()->createPartner('Partner Organisation', $parameters);
$sevdeskApi->contact()->createProspectCustomer('Prospect Customer Organisation', $parameters);
Through SevdeskApi::make() we first create a new instance. Then we can create different contacts as in the example here. Retrieving contacts looks like this.
$sevdeskApi->contact()->all();
$sevdeskApi->contact()->allSupplier();
$sevdeskApi->contact()->allCustomer();
$sevdeskApi->contact()->allPartner();
$sevdeskApi->contact()->allProspectCustomer();
There are already some functions for invoices. Unfortunately, some are still missing. I’m still working on improving that. What works well is retrieving invoices and downloading. And creating invoices is now also possible. Check out my blog post about it.
$sevdeskApi->invoice()->all();
$sevdeskApi->invoice()->allDraft();
$sevdeskApi->invoice()->allOpen();
$sevdeskApi->invoice()->allPayed();
$sevdeskApi->invoice()->allByContact($contactId);
$sevdeskApi->invoice()->allAfter($timestamp);
$sevdeskApi->invoice()->allBefore($timestamp);
$sevdeskApi->invoice()->download($invoiceId);
$sevdeskApi->invoice()->sendPerMail($invoiceId, $email, $subject, $text);
The package I created is still in the development process. Nevertheless, some people are already using it, which motivates me to continue working on it and expand it with new functions and improvements. For me, it’s also a great opportunity to deepen my knowledge about the collaboration of packages and Laravel. I hope that in the future it will help me identify and fix errors early.
I’m also considering whether I should record a video about it. Maybe in the video I can explain more details and receive suggestions and improvement proposals from you. If you’re interested in me recording a video about it, feel free to write it in the comments. If you have ideas yourself on how the package can be improved, I’d also be happy to hear your suggestions.
That’s it for now folks, thanks for your attention and see you next time.