Can I use the webservices using curl?

Submitted by ehu on

I'm writing this script in bash that I want to use to invoke functionality in LedgerSMB. Can I use curl and the webservices API to do that?

Yes you can. In order to do so, you must first create a valid session for your follow-up requests by authenticating:

$ curl -c cookie-jar.txt -H 'Content-Type: application/json' \
    -d '{"login": "<your-user>", "password": "<your-password>", "company": "<your-company>"}' \
    https://example.org/login.pl?action=authenticate

The request above creates a file called "cookie-jar.txt" in the current directory which - after successful authentication - contains the authentication cookie to be used for follow-up requests. To use it, use curl's -b parameter:

$ curl -b cookie-jar.txt -c cookie-jar.txt -H 'Content-Type: application/json' \
    -d @request-body.json https://example.org/erp/api/v0/invoices/

Note that the use of curl's "-d" parameter implies that a POST request is issued. The presence of the at-sign in "@request-body.json" tells curl to read the request body from the file 'request-body.json'. When you decide not to use 'curl', but issue these requests from programming language, please make sure to issue POST requests.

OpenAPI documentation of the LedgerSMB API by version is available at https://docs.ledgersmb.org/openapi

Component
Base
Release
FAQ Category