Henrik Rasmussen wrote:
I am using Docker-mailman (GNU Mailman 3.2.0a1), but from the host I am trying to create a list using the REST API in the (yet, no offense) lack of a template for new list configurations.
I get a nice dictionary when getting data out of Mailman, but using this exact dictionary (for debug) as payload to Mailman (my mmapiwrite), and with reference to https://mailman.readthedocs.io/en/latest/src/mailman/rest/docs/lists.html..., I get a response "A server error occurred. Please contact the administrator.".
You should check the logs for the precise error, it will be more helpful for us to help you debug the problem.
I don't understand the dump_json and I find the docs above hard to follow. How should I create the list using REST?
dump_json
is merely a helper function in documentation to make the HTTP Call and the json response that comes back.
<code> restapiversion = '3.1'
def getlistdefaultsx(): # Exact output from Mailman, see below. listdefaultsx = { 'acceptable_aliases': [], 'admin_immed_notify': True, 'admin_notify_mchanges': False, 'administrivia': True, [SNIP] 'subscription_policy': 'confirm_then_moderate', 'volume': 1}
return(listdefaultsx)
Note that not _all_ of these values are writable, so just POST'ing all of these values would error out with 400 Bad Request. (The reason for your 500 Server might be something else).
def get_all_list_names(): all_list_fqdn = [] response = mmapi('lists?count=10&page=1') output = response.json() for entry in output.get('entries'): all_list_fqdn.append(entry.get('fqdn_listname')) return(all_list_fqdn)
This looks fine to me.
def addlist(): list_setup = getlistdefaultsx() go_create_list('abc', list_setup)
def go_create_list(list_name_fqdn, list_setup): #pprint(list_setup) print('Creating list %s ...' % list_name_fqdn) response = mmapiwrite('lists', list_setup)
These two functions won't work. You can't POST _all_ the list's settings in one single call.
To create a new list, you need to POST at: 'http://<mailman-api:8001>/3.1/lists' with only {'fqdn_listname': 'bee@example.com',} as parameters.
This will create a new list with default settings, these default settings that are called "styles" in Core. Today, styles are Read-only in Core and you can specify the list you want to create with {'style_name': 'legacy-announce'}. You can get a list of all the styles at /3.1/styles
with a GET request.
Next step, to configure the list with your settings, you need to send a PATCH request at '/3.1/lists/bee@example.com/config' with the key-values you want to change. You can also use PUT request, but then you'd have to include _all_ the keys and update the whole config object. You can find all the available keys and some more documentation about it here:
https://mailman.readthedocs.io/en/latest/src/mailman/rest/docs/listconf.html
You can also use our Python client to interact with the API, instead of directly talking to the API. See 1 on how to create a new list and 2 to see how to update the configuration using MailmanClient.
thanks, Abhilash
def mmapi(apicommand): response = requests.get('http://172.19.199.2:8001/%s/%s' % (restapiversion, apicommand), auth=('restadmin', 'restpass'))
def mmapiwrite(apicommand,payload): response = requests.post('http://172.19.199.2:8001/%s/%s' % (restapiversion, apicommand), data=payload, auth=('restadmin', 'restpass'))
getlistdefaultsx is an actual dictionary with real output from Mailman using my mmapi from an existing test list (though domain names are masked. Of course I can't create an existing list, but when changing the list name I get the same error message.
{'acceptable_aliases': [], 'admin_immed_notify': True, 'admin_notify_mchanges': False, 'administrivia': True, 'advertised': True, 'allow_list_posts': True, 'anonymous_list': False, 'archive_policy': 'never', 'autorespond_owner': 'none', 'autorespond_postings': 'none', 'autorespond_requests': 'none', 'autoresponse_grace_period': '90d', 'autoresponse_owner_text': '', 'autoresponse_postings_text': '', 'autoresponse_request_text': '', 'bounces_address': 'hertest2-bounces(a)example.ku.dk', 'collapse_alternatives': True, 'convert_html_to_plaintext': False, 'created_at': '2018-03-19T14:19:49.018252', 'default_member_action': 'defer', 'default_nonmember_action': 'hold', 'description': 'Test-domæne for Mailman 3-testlister', 'digest_last_sent_at': None, 'digest_send_periodic': True, 'digest_size_threshold': 30.0, 'digest_volume_frequency': 'monthly', 'digests_enabled': True, 'display_name': 'Hertest2', 'dmarc_mitigate_action': 'no_mitigation', 'dmarc_mitigate_unconditionally': False, 'dmarc_moderation_notice': '', 'dmarc_wrapped_message_text': '', 'filter_content': False, 'first_strip_reply_to': False, 'fqdn_listname': 'hertest2(a)example.ku.dk', 'http_etag': '"987dfgf8g569fvfd6v7"', 'include_rfc2369_headers': True, 'info': '', 'join_address': 'hertest2-join(a)example.ku.dk', 'last_post_at': None, 'leave_address': 'hertest2-leave(a)example.ku.dk', 'list_name': 'hertest2', 'mail_host': 'example.ku.dk', 'max_message_size': 40, 'moderator_password': None, 'next_digest_number': 1, 'no_reply_address': 'noreply(a)example.ku.dk', 'owner_address': 'hertest2-owner(a)example.ku.dk', 'post_id': 1, 'posting_address': 'hertest2(a)example.ku.dk', 'posting_pipeline': 'default-posting-pipeline', 'reply_goes_to_list': 'no_munging', 'reply_to_address': '', 'request_address': 'hertest2-request(a)example.ku.dk', 'send_welcome_message': True, 'subject_prefix': '[Hertest2] ', 'subscription_policy': 'confirm_then_moderate', 'volume': 1} </code>