Hi,
Using Confluence API (not plugins), I want to get subpart only of page content (not entire page) in the aim to update it later.
I tried with page properties but I can’t get only unique property but a list of all pages with properties with next command (/rest/masterdetail/1.0/detailssummary/lines?cql=type=page&spaceKey=XXX&headings=XXX).
What is the best way to put data in the page structure and find easily with Confluence API?
Thank in advance for your answer.
Use the python module from here
https://pypi.org/project/atlassian-python-api/
It's easy to use. It has useful examples too.
Hi, thanks for the suggestions. Would you please provide an example of patching a specific part of the page, e.g. adding an admonition to the page? Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the explanation.
Currently I am on PHP but I will look for Python because the API actually has 2 interesting methods (get_page_property and set_page_property)...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You would have to import packages and add authentication as shown in above docs.
Okay. Here is the example of getting the page content and replacing the content. I am removing {group3} references in the page to nothing.
def rest_page_update(space,page_id,title):
content = confluence.get_page_by_id(page_id,expand='body.storage').get('body').get('storage').get('value')
body = re.sub('{group3}','', content, flags = re.M)
confluence.update_page(None, page_id, title, body, type='page')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fantastic! Thanks a bunch. Could you please post a working sample that could be used to get started.
I mean a working sample that shows how to auth on confluence and call your
rest_page_update
API. Kinda new to Python, so any short sample that would work from scratch is highly appreciated.
Thank you. That replacement sample is really cool: so simple and demonstrative.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
here you go...
import fileinput
import re
import os
import hashlib
from collections import defaultdict
import shutil
from atlassian import Confluence
confluence = Confluence(
url='https://ursite.url.com',
username='username',
password='*****')
def rest_page_update(space,page_id,title):
content = confluence.get_page_by_id(page_id,expand='body.storage').get('body').get('storage').get('value')
body = re.sub('{group3}','', content, flags = re.M)
confluence.update_page(None, page_id, title, body, type='page')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Whoaa, thank you @jira guy That's what I am hugely missing from Atlassian's docs. Samples. Any clue on how could I skip the SSL check?
I get the following error:
Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
When invoking `requests` component, I used to employ the following line to skip SSL verification:
requests.packages.urllib3.disable_warnings()
How is it done with `atlassian` component?
It feels like it's done like that
confluence = Confluence(
url=WIKI_WEB,
username=userName,
password=userPassword,
verify_ssl=False)
and like if setting `verify_ssl` to False is enought. But. Then I get:
TypeError: 'NoneType' object is not subscriptable
when processing this line:
confluence.update_page(None, page_id, title, body, type='page')
Any clues?
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I tried with Python Confluence API:
confluence = self.get_confluence()
status = confluence.page_exists(space=self.page_space, title=self.page_title)
if status:
self.page_id = confluence.get_page_id(self.page_space, self.page_title)
print(confluence.get_page_properties(self.page_id))
Problem is same as Web Service: Existing page properties from Confluence Web site are not visible by API...
But when I create a property by API:
property_data1 = {"key": "1234",
"value": {"Test API ": "en cours"}, "version": {"number": 1, "minorEdit": 'false'}}
prop = confluence.set_page_property(self.page_id, data=property_data)
It work fine in database, result from get_page_properties is:
"results": [
{
"id": "2955040",
"key": "1234",
"value": "Test API ",
"version": {
"when": "2019-09-09T17:19:18.533+02:00",
"message": "",
"number": 1,
"minorEdit": false,
"hidden": false
},
"_links": {
"self": "https://confluence.test/rest/api/content/2954600/property/1234"
},
"_expandable": {
"content": "/rest/api/content/2954600"
}
},
{
"id": "2955032",
"key": "example-Property001",
"value": [
"Test API ",
"en cours"
],
"version": {
"when": "2019-09-09T17:01:01.192+02:00",
"message": "",
"number": 1,
"minorEdit": false,
"hidden": false
},
"_links": {
"self": "https://confluence.test/rest/api/content/2954600/property/example-Property001"
},
"_expandable": {
"content": "/rest/api/content/2954600"
}
}
],
"start": 0,
"limit": 10,
"size": 2,
"_links": {
"self": "https://confluence.test/rest/api/content/2954600/property",
"base": "https://confluence.test",
"context": ""
}
}
Unfortunately, API page properties are not visible on Confluence Web site…
I tried changing profile as admin for the same result…
Do you have some idea of what happen ?
Thank in advance for your answer.
Regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.