Get a list of bugzilla bugs in PHP - php

Is it possible to get a list of all new bugs from a bugzilla installation via PHP?
I can see that there is the xmlrpc.cgi file but I can't find any examples of how to use it
Any help appreciated
Thanks!

Example how to do it with Zend_Http_Client. You can do it with raw PHP as well. http://petehowe.co.uk/2010/02/23/example-of-calling-the-bugzilla-api-using-php-zend-framework/

I actually figured out that I can get raw XML using...
/buglist.cgi?ctype=atom&bug_status=NEW

Is this what you're looking for, XMLRPC Bugzilla
Example XMLRPC Call:
<?php
// Add the Zend Library, make sure this is installed: sudo apt-get install libzend-framework-php
ini_set("include_path", "/usr/share/php/libzend-framework-php");
// Add the AutoLoader, Calls any Library that's needed
require_once('Zend/Loader/Autoloader.php');
Zend_Loader_Autoloader::getInstance();
// New client that calls your Bugzilla XMLRPC server
$server = new Zend_XmlRpc_Client('http://bugzilla.yourdomain.com/xmlrpc.cgi');
$client = $server->getProxy();
// Create the Multi-Call array request
$request = array(
array(
'methodName' => 'system.listMethods',
'params' => array()
));
/*
// Example: Multi call array format
$request = array(
array(
'methodName' => 'system.listMethods',
'params' => array()
),
array(
'methodName' => 'your_service.your_function',
'params' => array('parm')
));
*/
// $response is an array()
$response = $client->system->multicall($request);
// Print the array
echo print_r($response,true);
?>

Related

How can i get my PHP SoapClient to Authenticate with Digest

I currently have a vb.net ASMX web service hosted on IIS along with a PHP page which is calling the web service via a SoapClient.
I need to authenticate the webservice against ActiveDirectory and i figured the easiest way to do this would be to enable Digest Authentication on IIS and allow the user to enter their AD username/password into the PHP page and send this authentication in the SoapHeaders.
I am not really quite sure how to go about this, especially when trying to contact the WSDL (which is also behind the Digest Authentication).
Any help would be appreciated.
Thanks
EDIT: What i've tried:
SERVICE_URL points to http://mypage/service.asmx?wsdl
Attempt 1: User and Pass as MD5
$options = array(
'authentication' => SOAP_AUTHENTICATION_DIGEST,
'realm' => 'myrealm',
'login' => $_SESSION['authUser'],
'password' => $_SESSION['authPass']
);
try { $client = new SoapClient(SERVICE_URL, $options); }
Attempt 2: Auth is the 'user':'realm':'pass' as MD5:
$options = array(
'authentication' => SOAP_AUTHENTICATION_DIGEST,
'login' => $_SESSION['auth']
);
try { $client = new SoapClient(SERVICE_URL, $options); }
You can add headers to your soap client using SoapHeader() class/object (SoapHeader() documentation) and soap object operator __setSoapHeaders() (__setSoapHeaders() documentation).
Your request would look something like this:
<?php
$options = array(
'authentication' => SOAP_AUTHENTICATION_DIGEST,
'realm' => 'myrealm',
'login' => $_SESSION['authUser'],
'password' => $_SESSION['authPass']
);
try {
$client = new SoapClient(SERVICE_URL, $options);
// create and populate header array
$headers = array();
$headers[] = new SoapHeader('MYNAMESPACE',
'authentication',
'SOAP_AUTHENTICATION_DIGEST');
$headers[] = new SoapHeader('MYNAMESPACE',
'realm',
'myrealm');
$client->__setSoapHeaders($headers); // set headers
$client->__soapCall("echoVoid", null); // make soap call
}
?>

php autoload not loading correctly?

Using php-ews I try to create a calendar event by example (just to get the hang of it):
require $server_path.'scripts/ews/vendor/autoload.php';
use garethp\ews\API;
use garethp\ews\API\Enumeration;
use garethp\ews\API\Type;
$ews = API::withUsernameAndPassword($exchange_host, $_SESSION["user_data"]["u_email"], $_SESSION["user_data"]["u_pwd"]);
Seems to work without errors.
// Start building the request.
$calendar = $ews->getCalendar();
$start = new DateTime('8:00 AM');
$end = new DateTime('9:00 AM');
$request = array(
'Items' => array(
'CalendarItem' => array(
'Start' => $start->format('c'),
'End' => $end->format('c'),
'Body' => array(
'BodyType' => Enumeration\BodyTypeType::HTML,
'_value' => 'This is <b>the</b> body'
),
'ItemClass' => Enumeration\ItemClassType::APPOINTMENT,
'Sensitivity' => Enumeration\SensitivityChoicesType::NORMAL,
'Categories' => array('Testing', 'php-ews'),
'Importance' => Enumeration\ImportanceChoicesType::NORMAL
)
),
'SendMeetingInvitations' => Enumeration\CalendarItemCreateOrDeleteOperationType::SEND_TO_NONE
);
$request = Type::buildFromArray($request);
$response = $ews->CreateItem($request);
I get:
PHP Fatal error: Call to undefined method garethp\ews\API::CreateItem() in
in the execute part ($ews->CreateItem())
Please take a look at my examples/, they cover exactly this. The firs thing to note is that creating Calendar events is incredibly simplified, so your long request isn't entirely needed. That being said, if you want to access the functions directly, you can't do
$response = $ews->CreateItem($request);
you need to do
$response = $ews->getClient()->CreateItem($request);
More info on building requests manually can be found here.

PHP SoapClient "Body must be present in a SOAP envelope" error

I faced with very strange issue when tried to use PHP SoapClient for this service http://bws.neteven.com/NWS/2.
I have to setup an authentication header. Request body should be empty. The code, which I used is below:
$client = new SoapClient("http://bws.neteven.com/NWS/2", array("trace" => 1, "exception" => 1));
$auth = array(//the params are not valid of course
'Method' => 'TestConnection',
'Login' => 'login',
'Seed' => 'seed',
'Stamp' => 'stamp',
'Signature' => 'signature'
);
$client->__setSoapHeaders(new SoapHeader('auth', 'AuthenticationHeader', $auth));
$client->__soapCall('TestConnection',array(null));
After that I used $client->__getLastRequest() to see what is final XML of the request. However I can see that the header and body params were not setup properly.
$client->__getLastRequest() outputs plain text like this:
MethodTestConnectionLoginloginSeedseedStampstampSignaturesignature
Which doesn't look like valid XML. So of course I get SoapFault exception with the text "Body must be present in a SOAP envelope".
Does anybody knows why header and body are not wrapped by required XML tags?
Any issue in the code? Because I saw lots of examples of PHP SoapClient usage with the same approach. In addition I tried a few test WSDL services and had valid requests and responses there.
Could it be a problem of provided WSDL schema?
Or a problem of my server configuration? I use PHP 5.6.3, php_soap extension is enabled.
Hope you guys can help me. Any your thoughts would be really appreciated.
Thank you.
The code example I found has a different URL...
http://bws.neteven.com/NWS/2 vs http://ws.neteven.com/NWS
$client = new SoapClient("http://ws.neteven.com/NWS", array("trace" => 1, "exception" => 1));
$auth = array(//the params are not valid of course
'Method' => 'TestConnection',
'Login' => 'login',
'Seed' => 'seed',
'Stamp' => 'stamp',
'Signature' => 'signature'
);
$client->__setSoapHeaders(new SoapHeader('auth', 'AuthenticationHeader', $auth));
$client->__soapCall('TestConnection',array(null));
Also, you can call methods like this without using __soapCall (even though it would be doing the same thing).
$result = $client->echo(array("EchoInput" => "ReturnMe"));
var_dump($result->EchoOutput);
$result = $client->TestConnection();
var_dump($result->TestConnectionResult);

Using SoapClient in php in mule

I am using the following php script in mule. When i am running this php file individually(through wamp) i am able to get the required output.
<?php
$client1=new SoapClient('example/v2_soap?wsdl', array('trace' => 1, 'connection_timeout' => 120));
$username = '******';
$password = '******';
//retreive session id from login
$session = $client1->login(
array(
'username' => $username,
'apiKey' => $password,
)
);
$result= $client1->catalogProductInfo(
array(
'sessionId' => $session->result,
'productId' => 1,
)
);
print_r($result);
return $result;
?>
But i want to run the following script through mule. So when i am running it through mule i am getting the following error.
Root Exception stack trace:
com.caucho.quercus.QuercusErrorException: eval::5: Fatal Error: 'SoapClient' is an unknown class name.
at com.caucho.quercus.env.Env.error(Env.java:4480)
at com.caucho.quercus.env.Env.error(Env.java:4399)
at com.caucho.quercus.env.Env.createErrorException(Env.java:4130)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
It says SoapClient is an unknown class. What is the problem here?
Do i have to include some SoapClient here? If so where can i find it. Please help!!
I'm not sure if mule supports php extensions, but that's what it seems by the error. You could try downloading nusoap into your project,
which doesn't require any php extension. The syntaxis is a little bit different though, but shouldn't be harder to adapt your code.
For what it's worth, this is a simple example of a soap request using nusoap (taken from here http://www.richardkmiller.com/files/msnsearch_nusoap.html):
require_once('nusoap/lib/nusoap.php');
$request = array('Request' => array(
'AppID' => 'MSN_SEARCH_API_KEY',
'Query' => 'Seinfeld',
'CultureInfo' => 'en-US',
'SafeSearch' => 'Strict',
'Flags' => '',
'Location' => '',
'Requests' => array(
'SourceRequest' => array(
'Source' => 'Web',
'Offset' => 0,
'Count' => 50,
'ResultFields' => 'All'))));
$soapClient = new soapclient("http://soap.search.msn.com/webservices.asmx?wsdl", false);
$result = $soapClient->call("Search", $request);
print_r($result);
I hope it helps.
I understand there seems to be a problem with running the soap client inside quercus (rather than Mule).
However instead of focusing on it I would suggest to take a look to the CXF client and the Web services consumer. You are running inside of Mule a powerful opensource ESB, there is no need to write a php script to consume a service, you have all that functinality already present.

SOAP to XML conversion in PHP

I need to generate the following XML with SOAP:
...
<InternationalShippingServiceOption>
<ShippingService>StandardInternational</ShippingService>
<ShippingServiceCost currencyID="USD">39.99</ShippingServiceCost>
<ShippingServicePriority>1</ShippingServicePriority>
<ShipToLocation>CA</ShipToLocation>
</InternationalShippingServiceOption>
...
So I have the following SOAP array in PHP to do this:
$params = array(
'InternationalShippingServiceOption' => array(
'ShippingService'=>'StandardInternational',
'ShippingServiceCost'=>39.99,
'ShippingServicePriority'=>1,
'ShipToLocation'=>'CA',
)
)
$client = new eBaySOAP($session); //eBaySOAP extends SoapClient
$results = $client->AddItem($params);
Everything works great, except I am not generating the currencyID="USD" attribute in the ShippingServiceCost tag in the XML. How do I do this?
You don't need to use SoapVar. This works (for me at least):
$params = array(
'InternationalShippingServiceOption' => array(
'ShippingService'=>'StandardInternational',
'ShippingServiceCost' => array('_' => 39.99, 'currencyID' => 'USD')
'ShippingServicePriority'=>1,
'ShipToLocation'=>'CA',
)
)
I'm using this technique with the PayPal SOAP API.
Why, I am glad you asked. I just solved this today.
$shippingsvccostwithid = new SoapVar(array('currencyID' => $whatever),SOAP_ENC_OBJECT, 'ShippingServiceCost', 'https://your.namespace.here.com/');
$params = array("InternationalShippingServiceOption" => array(
"ShippingService" => "StandardInternational",
"ShippingServiceCost" => $shippingsvccostwithid,
"ShippingServicePriority" => 1,
"ShipToLocation" => "CA"
);
And then continue as normal.
Please let me know if you need any more help.

Categories