NAME
Confluence::Client::XMLRPC - Client for the Atlassian Confluence wiki, based on RPC::XML
VERSION
version 2.4
SYNOPSIS
my $object = Confluence::Client::XMLRPC->new( <URL>, <user>, <pass> );
my $result = $object->method(argument,..);
# Starting with version 2.3 of this module you can pass a fourth value to
# new, denoting the Confluence API version to use (see below).
my $object = Confluence::Client::XMLRPC->new( <URL>, <user>, <pass>, 2 );
METHODS
All method calls are simply mapped (via AUTOLOAD) to RPC method calls. Please refer to the official list of available methods for further information.
The module tries to automatically map between the data types mentioned in the Atlassian docs and the appropriate Perl data types:
Vectors: array referencesStructsanddata objects: hash referencesBoolean: strings "true" and "false"
For everything else, simple scalars are used and mapped to RPC::XML::string, so explicit type conversions should not be required.
Note: the "token" paramater mentioned in the Confluence docs is the session id and is automatically added by this module, so do not pass in a parameter for it when invoking a method.
ERROR HANDLING
This package has two global flags which control error handling.
Confluence::Client::XMLRPC::setRaiseError(1); # Enable die
Confluence::Client::XMLRPC::setPrintError(1); # Enable warn
Confluence::Client::XMLRPC::setRaiseError(0); # Disable die
Confluence::Client::XMLRPC::setPrintError(0); # Disable warn
The setRaiseError and setPrintError functions both return the previous setting of the flag so that it may be restored if necessary.
RaiseError is initially set to 1 to preserve the original package behavior.
PrintError is initially set to 0.
If RaiseError is set to 0 then Confluence::Client::XMLRPC::lastError() can be used to determine if an error occurred.
Confluence::Client::XMLRPC::setRaiseError(0);
my $page = $wiki->getPage($space, $title);
if ( my $e = Confluence::Client::XMLRPC::lastError() ) {
say $e;
}
Debugging
You can get more info about the communication between your client and the API by setting the environment variable CONFLDEBUG to a true value. If you do so, the module will log the messages exchanged to STDERR.
API VERSIONS
Analogous to the global error handling flags there is a flag to set the API version to use:
Confluence::Client::XMLRPC::setApiVersion($num); # set the version
The setApiVersion function returns the previous setting of the flag so that it may be restored if necessary. The function accepts both plain numbers ("1" or "2") or the full version namespaces ("confluence1", "confluence2").
The version 2 of the API was introduced with Confluence 4.0 and Atlassian recommends to use the newer version. However, due to backwards compatibility reasons the default value for the API version in this module still is 1.
Note: you can use most but not all of the version 1 API calls on newer Confluence installations! The Confluence docs contain a detailed and authoritative description of the differences between versions 1 and 2 of the API!
The new version 2 API implements the same methods as the version 1 API, however all content is stored and retrieved using the storage format. This means that you cannot, for example, create a page using wiki markup with the version 2 API, you must instead define the page using the new XHTML based storage format. You will be able to create pages, blogs and comments in wiki markup using the version 1 API even on Confluence 4.0 and later. However you will no longer be able to retrieve pages, blogs and comments using the version 1 API.
To aid in the migration phase Confluence 4.0 and up provide a method convertWikiToStorageFormat() where you can pass in a string with wiki markup and will recieve the same data converted to the new storage format (which you can then use to create or update a page).
API extension
- updatePage
-
This package has a function called
updatePagewhich is not part of the original remote API. If the page id is not specified then the function will callstorePageto do an insert. If an "already exists" error is encountered then the function will callgetPageto retrieve the page id and version, and then repeat thestorePageattempt. This function is intended to be used in situations where the intent is to upload pages, overwriting existing content if it exists. See example below.
EXAMPLES
upload_files.pl- Upload files-
The sample script uploads the contents of a directory to the wiki. Each file in the directory is uploaded as a separate page. The page title is the file name with extension removed. This script requires five arguments: API url, user name, password, space key and a directory name.
upload_users.pl- Upload Users-
This script reads and loads a list of users from a file (or stdin). If errors are encountered then the script will print an error message, but continue processing. This script requires three arguments: API url, name and password of an admin user.
det_group_mbrship.pl- Determine Group Membership-
The script prints the group membership of all users. This script requires three arguments: API url, name and password of an admin user.
Please refer to the examples directory of the distribution for the scripts themselves.
NOTES
The package uses the RPC::XML module to do the heavy lifting. Read the perldoc for this package to learn more.
RPC::XML uses LWP for handling http/https messaging. If you are experiencing problems when connecting to a https based API endpoint, please make sure that the necessary modules - like, e.g. LWP::Protocol::https - are installed.
For further information on the Confluence API itself please refer to the official documentation as provided by Atlassian.
Please note that starting with Confluence 5.5 the XML-RPC API will be deprecated, meaning that Atlassian will not add new features or fix bugs related to the XML-RPC API for Confluence 5.5 or later. This does not mean, that this module will not work with newer Confluence versions: as of now, there is no information if or when Atlassian will remove the XML-RPC API and rely solely on the new REST API.
CAVEAT
ATTENTION, please: This module was written by Asgeir Nilsen in 2004 and later on improved by Giles Lewis, Martin Ellis, and Torben K. Jensen.
I - Heiko Jansen - only took the available source code and created a CPAN distribution for it, because at least to me a Perl module almost does not exist if it's not on available via CPAN.
This package should work with any remote API function.
The original authors tested it with addUserToGroup, getActiveUsers, getPage, getPages, getServerInfo, getUser, and storePage. I (Heiko Jansen) have used it successfully to create and update pages, but I did not test most other API functions and am thus unable to give any guarantee that it will work as expected!
The original module was simply named "Confluence" but since Atlassian is currently working on a new REST-based API I renamed it to Confluence::Client::XMLRPC.
AUTHORS
Asgeir Nilsen
Giles Lewis
Martin Ellis
Torben K. Jensen
Heiko Jansen <hjansen@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2014 by Heiko Jansen.
This is free software, licensed under:
The GNU General Public License, Version 2, June 1991