Can I use the webservices using curl?

Submitted by ehu on Sun, 06/13/2021 - 13:35

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>"}' \

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

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.

FAQ Category