How can I programmatically change the Confluence "Site title" or "mail server".

I know how do change the Site Title via the GUI on the "Site Logo and Favicon" page, and also change the SMTP Server on the "View Mail Servers" page.

 

How do I update these programmatically? EIther API or database updates are fine.

 

Thanks!
Jeff

1 answer

How did you manage doing this ?

Here is how to change the mail server same to some dummy name:

psql docsdb -c "update BANDANA
set BANDANAVALUE = regexp_replace(BANDANAVALUE, ''<hostname>.*<\/hostname>'' ,''<hostname>dummy-smtp-email-hostname</hostname>'')
where BANDANAKEY = ''atlassian.confluence.smtp.mail.accounts''

Never figured out how to change the site title. 

I was able to delete a smtp server mail via Python.

To "update" it - it should be very similar. 



def get_authenticated_admin_session_and_token():
payload = {'password':'myPassword','authenticate':'Confirm','destination':''}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
url = confluence_base_url+'doauthenticate.action'
session = requests.Session()
session.post(confluence_base_url+'doauthenticate.action?destination=/admin/mail/viewmailservers.action',headers=headers,data=payload)
# the session instance holds the cookie. So use it to get/post later.
# Do another post to retrieve the atlassian-token
r = session.post(url,
auth=('admin', 'myPassword'),
headers=headers,
data=payload )
soup = BeautifulSoup(r.text, "lxml")
atlassian_token = soup.find("meta", {"id": "atlassian-token"})["content"]


def update_mailserver_config(session,atl_token):
# import requests
payload = {'password':'myPassword','authenticate':'Confirm','destination':''}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
url = confluence_base_url+'admin/mail/viewmailservers.action'
r = session.get(url,
auth=('admin', 'myPassword'),
headers=headers)

if r.text:
mail_servers = re.findall('<a href="removemailserver.*?>', r.text)
print(mail_servers)
#It will capture something like -> <a href="removemailserver.action?id=1520106736789&atl_token=5d199fff330bbc8ccb3be03c4af313f9a0102b74" onClick="javascript&colon;if (confirm(\'Remove mail server?\')) return true; else return false;">
for mail_server in mail_servers:
url_param_start_index = mail_server.find("?")
url_param_end_index = mail_server.find('"',url_param_start_index)

tokens = mail_server[url_param_start_index+1:url_param_end_index]
key_value_server_id = tokens.split("&")[0]
id_mail_server = key_value_server_id[key_value_server_id.find("=")+1:]
print(id_mail_server)
# key_value_alt_token = tokens.split("&")[1]
# alt_token = key_value_alt_token[key_value_alt_token.find("=")+1:]
url_remove_mail_server = confluence_base_url+"admin/mail/removemailserver.action?id=%s&atl_token=%s"%(id_mail_server,atl_token)
print (url_remove_mail_server)
if id_mail_server == '1520116056861':
r = session.get(url_remove_mail_server,
auth=('admin', 'myPassword'))


confluence_base_url = "localhost/confluence"
(session,atlassian_token) = get_authenticated_admin_session_and_token(target_environment)
update_mailserver_config(session,atlassian_token)

def get_authenticated_admin_session_and_token():
payload = {'password':'myPassword','authenticate':'Confirm','destination':''}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
url = confluence_base_url+'doauthenticate.action'
session = requests.Session()
session.post(confluence_base_url+'doauthenticate.action?destination=/admin/mail/viewmailservers.action',headers=headers,data=payload)
# the session instance holds the cookie. So use it to get/post later.
# Do another post to retrieve the atlassian-token
r = session.post(url,
auth=('admin', 'myPassword'),
headers=headers,
data=payload )
soup = BeautifulSoup(r.text, "lxml")
atlassian_token = soup.find("meta", {"id": "atlassian-token"})["content"]


def update_mailserver_config(session,atl_token):
# import requests
payload = {'password':'myPassword','authenticate':'Confirm','destination':''}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
url = confluence_base_url+'admin/mail/viewmailservers.action'
r = session.get(url,
auth=('admin', 'myPassword'),
headers=headers)

if r.text:
mail_servers = re.findall('<a href="removemailserver.*?>', r.text)
print(mail_servers)
#It will capture something like -> <a href="removemailserver.action?id=1520106736789&atl_token=5d199fff330bbc8ccb3be03c4af313f9a0102b74" onClick="javascript&colon;if (confirm(\'Remove mail server?\')) return true; else return false;">
for mail_server in mail_servers:
url_param_start_index = mail_server.find("?")
url_param_end_index = mail_server.find('"',url_param_start_index)

tokens = mail_server[url_param_start_index+1:url_param_end_index]
key_value_server_id = tokens.split("&")[0]
id_mail_server = key_value_server_id[key_value_server_id.find("=")+1:]
print(id_mail_server)
# key_value_alt_token = tokens.split("&")[1]
# alt_token = key_value_alt_token[key_value_alt_token.find("=")+1:]
url_remove_mail_server = confluence_base_url+"admin/mail/removemailserver.action?id=%s&atl_token=%s"%(id_mail_server,atl_token)
print (url_remove_mail_server)
r = session.get(url_remove_mail_server,
auth=('admin', 'myPassword'))


confluence_base_url = "localhost/confluence"
(session,atlassian_token) = get_authenticated_admin_session_and_token(target_environment)
update_mailserver_config(session,atlassian_token)

Here is what I did to delete the mail server ( update should be similar)

 



def get_authenticated_admin_session_and_token():
payload = {'password':'myPassword','authenticate':'Confirm','destination':''}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
url = confluence_base_url+'doauthenticate.action'
session = requests.Session()
session.post(confluence_base_url+'doauthenticate.action?destination=/admin/mail/viewmailservers.action',headers=headers,data=payload)
# the session instance holds the cookie. So use it to get/post later.
# Do another post to retrieve the atlassian-token
r = session.post(url,
auth=('admin', 'myPassword'),
headers=headers,
data=payload )
soup = BeautifulSoup(r.text, "lxml")
atlassian_token = soup.find("meta", {"id": "atlassian-token"})["content"]


def update_mailserver_config(session,atl_token):
# import requests
payload = {'password':'myPassword','authenticate':'Confirm','destination':''}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
url = confluence_base_url+'admin/mail/viewmailservers.action'
r = session.get(url,
auth=('admin', 'myPassword'),
headers=headers)

if r.text:
mail_servers = re.findall('<a href="removemailserver.*?>', r.text)
print(mail_servers)
#It will capture something like -> <a href="removemailserver.action?id=1520106736789&atl_token=5d199fff330bbc8ccb3be03c4af313f9a0102b74" onClick="javascript&colon;if (confirm(\'Remove mail server?\')) return true; else return false;">
for mail_server in mail_servers:
url_param_start_index = mail_server.find("?")
url_param_end_index = mail_server.find('"',url_param_start_index)

tokens = mail_server[url_param_start_index+1:url_param_end_index]
key_value_server_id = tokens.split("&")[0]
id_mail_server = key_value_server_id[key_value_server_id.find("=")+1:]
print(id_mail_server)
# key_value_alt_token = tokens.split("&")[1]
# alt_token = key_value_alt_token[key_value_alt_token.find("=")+1:]
url_remove_mail_server = confluence_base_url+"admin/mail/removemailserver.action?id=%s&atl_token=%s"%(id_mail_server,atl_token)
print (url_remove_mail_server)
if id_mail_server == '1520116056861':
r = session.get(url_remove_mail_server,
auth=('admin', 'myPassword'))


confluence_base_url = "localhost/confluence"
(session,atlassian_token) = get_authenticated_admin_session_and_token(target_environment)
update_mailserver_config(session,atlassian_token)

 

Updating the site title should be similar.

I advise you to use google Chrome and inspect what API Call is being sent while clicking on the submit/save button to see how to change it based on your use case.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 24, 2018 in Confluence

Atlassian Research opportunity with Confluence templates

Do you use templates with Confluence? Take part in a remote 1-hr workshop. You'll receive USD $100 for your time!   We're looking for people to participate in a   remote 1-hr workshop...

1,168 views 20 14
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you