Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Confluence XML-RPC (atlassian.com)
<?php
$fullname = 'test1';
$username = 'test1';
$email = 'test1@gmail.com';
$password = '123456';
$xmlRpc = new XmlRPC('http://localhost:8090','/rpc/xmlrpc');
$xmlRpc->setCredentials('admin','123456');
$token = $xmlRpc->call(xmlrpc_encode_request("confluence1.login", ['admin','123456']));
$request = $xmlRpc->call(xmlrpc_encode_request("confluence1.addUser", [$token, ['email'=>$email,'fullname'=>$fullname, 'name' => $fullname], $password]));
class XmlRPC {
private $host;
private $path;
private $user;
private $pass;
public $token;
public function __construct($host,$path) {
$this->host = $host;
$this->path = $path;
}
public function setCredentials($user,$pass) {
$this->user = $user;
$this->pass = $pass;
}
public function setToken($token){
$this->token = $token;
}
public function call($request) {
$auth = base64_encode($this->user.":".$this->pass);
$header = (version_compare(phpversion(), '5.2.8'))
? array("Content-Type: text/xml","Authorization: Basic $auth")
: "Content-Type: text/xml\r\nAuthorization: Basic $auth" ; //[1]
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => $header,
'content' => $request
)));
$webservice= $this->host.$this->path;
$file = file_get_contents($webservice, false, $context);
return $token = xmlrpc_decode($file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.