Thanks to everyone who answered my "where are the api dox" question, and thanks for the very helpful examples, both of which work fine for me.
But there seems to be the following potential glitch. For this explanation, let us append "print(r.status_code)" and "print(r.json())" to the example code.
First, calling the example with valid arguments, the output is 200 and {'ok': 'created'}.
All well and good. The 'email addresses' panel in the control panel looks good, and making a requests.post call to /api/v0/mail/list/ produces the expected results.
Now ... just to check what happens, let us call the example code again, with the same valid arguments.
Again, the output is 200 and {'ok': 'created'}. No indication of anything strange.
But if we then look at the 'email addresses' panel in the control panel, we now find two lines reflecting our two calls to the example code, one of which looks correct and the other of which has an empty field in the left hand column (where the source email address should appear).
Worse, making a requests.post call to /api/v0/mail/list/ now produces a status code of 400, and a json() result of {'error': 'error'}.
This cannot be a good state of affairs surely? Naturally, I quickly manually deleted the extra line in the control panel, and after doing that, /api/v0/mail/list/ works properly again.
But, two questions:
(1) during the couple of minutes when /api/v0/mail/list/ was returning {'error': 'error'}, was email in my account still working properly or at all? (I have read that you use the api for lots of things internally).
(2) how should we make sure that we do not call /api/v0/mail/add/ twice with the same source address?