Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Javascript client library for the lexoffice Public API. Fully typed, promise based and non throwing.

License

NotificationsYou must be signed in to change notification settings

elbstack/lexoffice-client-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Javascript client library for thelexoffice Public API.

fully typed

promise based

❌ non throwing


GitHub Starsnpm (latest)npm (next)
ActivityContributorsMIT license

📦 Contents


⚙️ Installation

npm install @elbstack/lexoffice-client-js

or

yarn add @elbstack/lexoffice-client-js

📚 Documentation

You can find the official lexoffice API documentationhere.

🔑 Usage

To get your API Key, you must already be a lexoffice user. Get ithere.

import{Client}from'@elbstack/lexoffice-client-js';constclient=newClient(YOUR_LEXOFFICE_API_KEY);

💡 Examples

All functions are promise based. These promises are formatted by thets-results package, for extended error handling seeError handling.

Retrieve an invoice

constinvoiceResult=awaitclient.retrieveInvoice('caf4e0c3-c3e8-4a06-bcfe-346bc7190b2');if(invoiceResult.ok){constinvoice=invoiceResult.val;}else{console.error('An error occured');}

Create an invoice

constinvoice={voucherDate:'2017-02-22T00:00:00.000+01:00',address:{name:'Bike & Ride GmbH & Co. KG',supplement:'Gebäude 10',street:'Musterstraße 42',city:'Freiburg',zip:'79112',countryCode:'DE',},lineItems:[{type:'custom',name:'Energieriegel Testpaket',quantity:1,unitName:'Stück',unitPrice:{currency:'EUR',netAmount:5,taxRatePercentage:0,},discountPercentage:0,},{type:'text',name:'Strukturieren Sie Ihre Belege durch Text-Elemente.',description:'Das hilft beim Verständnis',},],totalPrice:{currency:'EUR',},taxConditions:{taxType:'net',},shippingConditions:{shippingDate:'2017-04-22T00:00:00.000+02:00',shippingType:'delivery',},title:'Rechnung',introduction:'Ihre bestellten Positionen stellen wir Ihnen hiermit in Rechnung',remark:'Vielen Dank für Ihren Einkauf',};constcreatedInvoiceResult=awaitclient.createInvoice(invoice,{finalize:true});if(createdInvoiceResult.ok){constinvoice=createdInvoiceResult.val;}else{console.error('An error occured');}

Upload File

letfs=require('fs');letFormData=require('form-data');letdata=newFormData();data.append('file',fs.createReadStream(__dirname+'/yourFolder/yourFile'));data.append('type','voucher');constuploadedFileResult=awaitclient.uploadFile(data);if(uploadedFileResult.ok){constinvoice=uploadedFileResult.val;}else{console.error('An error occured');}

❌ Error handling

As mentioned above, the returned promises are formatted by ts-results which is a typescript implementation of Rust'sResult andOption objects. It brings compile-time error checking and optional values to typescript.All errors are instances of type RequestError.If you want to use the advantages of ts-results, all client responses should be processed similar to the following:

if(YOUR_RESULT.ok){constYOUR_VARIABLE=YOUR_RESULT.val;// Work with your result}else{// Your request returned an errorconsterror=YOUR_RESULT.val;console.log('error:',error);// Further error checking is possible byif(errorinstanceofRequestError){console.log('Hello instance of RequestError!');if(errorinstanceofRequestNotFoundError){console.log('Wow, it looks like you have many instances!');}if(errorinstanceofRequestMethodNotAcceptableLegacyError){console.log('Seems, that you take care of your legacy!');}}}

Error codes and types

Regular errors
❌ Error code Error type❌ Server error code Error type
400RequestBadRequestError500RequestInternalServerError
401RequestUnauthorizedError503RequestServiceUnavailableError
402RequestPaymentRequiredError504RequestGatewayTimeoutError
403RequestForbiddenError
404RequestNotFoundError
405RequestMethodNotAllowedError
406RequestMethodNotAcceptableError
409RequestConflictError
415RequestUnsupportedMediaTypeError
429RequestTooManyRequestsError
Legacy errors (used by the endpoints files, profiles and contacts)
400RequestBadRequestLegacyError500RequestInternalServerLegacyError
406RequestMethodNotAcceptableLegacyError

🛠 Provided methods grouped by endpoint

Contact

createContact(contact:ContactCreatePerson|ContactCreateCompany):Promise<Result<ContactCreateResponse,RequestError>>retrieveContact(id:string):Promise<Result<ContactRetrieveResponse,RequestError>>updateContact(id:string,contact:ContactUpdatePerson|ContactUpdateCompany):Promise<Result<ContactUpdateResponse,RequestError>>filterContact(filter?:OptionalFilters&Partial<PagingParameters>):Promise<Result<ContactFilterRetrieveResponse,RequestError>>

Country

retrieveListOfCountries():Promise<Result<Country[],RequestError>>

Credit note

createCreditNote(creditNote:CreditNoteCreate,optionalFinalized?:OptionalFinalized):Promise<Result<CreditNoteCreateResponse,RequestError>>retrieveCreditNote(id:string):Promise<Result<CreditNoteRetrieveResponse,RequestError>>renderCreditNoteDocumentFileId(id:string):Promise<Result<DocumentFileId,RequestError>>

Down payment invoice

retrieveDownPaymentInvoice(id:string):Promise<Result<DownPaymentInvoice,RequestError>>

Event subscription

createEventSubscription(eventSubscription:EventSubscriptionCreate):Promise<Result<EventSubscription,RequestError>>retrieveEventSubscription(id:string):Promise<Result<EventSubscription,RequestError>>retrieveAllEventSubscriptions():Promise<Result<EventSubscriptions,RequestError>>deleteEventSubscription(id:string):Promise<Result<unknown,RequestError>>

File

uploadFile(data:FormData):Promise<Result<FileResponse,RequestError>>downloadFile(documentFileId: string,optionalParameter?:RenderType):Promise<Result<unknown,RequestError>>

Invoice

createInvoice(invoice:InvoiceCreate|XRechnung,optionalFinalized?:OptionalFinalized):Promise<Result<InvoiceCreateResponse,RequestError>>retrieveInvoice(id:string):Promise<Result<InvoiceRetrieveResponse,RequestError>>renderInvoiceDocumentFileId(id:string):Promise<Result<DocumentFileId,RequestError>>

Order confirmation

createOrderConfirmation(orderConfirmation:OrderConfirmation):Promise<Result<OrderConfirmationResponse,RequestError>>retrieveOrderConfirmation(id:string):Promise<Result<OrderConfirmationRetrieveResponse,RequestError>>renderOrderConfirmationDocumentFileId(id:string):Promise<Result<DocumentFileId,RequestError>>

Payment

retrievePayment(id:string):Promise<Result<Payment,RequestError>>

Payment condition

retrievePaymentConditionList():Promise<Result<PaymentCondition,RequestError>>

Posting category

retrieveListPostingCategories():Promise<Result<PostingCategory[],RequestError>>

Profile

retrieveProfile():Promise<Result<Profile,RequestError>>

Quotation

createQuotation(quotation:QuotationCreate,optionalFilter?:OptionalFinalized):Promise<Result<QuotationCreate,RequestError>>retrieveQuotation(id:string):Promise<Result<Partial<Quotation>,RequestError>>renderQuotationDocumentFileId(id:string):Promise<Result<DocumentFileId,RequestError>>

Recurring template

retrieveRecurringTemplate(id:string):Promise<Result<Partial<RecurringTemplate>,RequestError>>retrieveAllRecurringTemplates(optionalFilter?:PagingParameters):Promise<Result<RecurringTemplates,RequestError>>

Voucher

createVoucher(voucher:CreateVoucher):Promise<Result<VoucherCreateResponse,RequestError>>retrieveVoucher(id:string):Promise<Result<Partial<Voucher>,RequestError>>updateVoucher(id:string,voucher:CreateVoucher):Promise<Result<VoucherCreateResponse,RequestError>>filterVoucher(voucherNumber:VoucherNumber):Promise<Result<Partial<Vouchers>,RequestError>>uploadFileToVoucher(data:FormData,id:string):Promise<Result<FileResponse,RequestError>>

Voucherlist

retrieveVoucherlist(filterParameter:FilterParameter):Promise<Result<Voucherlist,RequestError>>

🔖 Side notes

Updating

For updating any type of vouchers where the "version" property is required, you first need to retrieve it and use the current "version" value to properly update.

Rendering Document File Id

Only possible for any type of vouchers that are not in "draft" mode.

Download File

The required id is not the id itself, it is the documentFileId, which can be required with the matching method and the vouchers id:

renderCreditNoteDocumentFileId(id);renderInvoiceDocumentFileId(id);renderOrderConfirmationDocumentFileId(id);renderQuotationDocumentFileId(id);

This package has been brought to you by elbstack!

elbstack is a software engineering & design company. We question, we advise, and we're excited to help your next project to succeed.
We offer software development and design as service. That's how we support you with the realisation of your projects - with individual employees or with a whole team. We love to work remotely, but we will work at your place, too.

👩🏻‍💻👨🏽‍💻 We are hiring!

We are more than a classic software agency, rather like a highly self organized company with our own start-up incubator. You can choose how much, for whom and what you want to work for. Acquire your own customers and projects, simply make your sideproject become reality or even a proper start-up.

Sounds like a scam?

➡️ Go and check kununu.com
➡️ elbstack.com

About

Javascript client library for the lexoffice Public API. Fully typed, promise based and non throwing.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp