I am trying to use PHP to connect to ServiceNow and retrieve incident records.
I tried to use the code below but somehow I receive errors:
<?php
$credentials = array('login'=>'user', 'password'=>'pass');
$client = new SoapClient("https://blah.com/incident.do?WSDL", $credentials);
$params = array('param1' => 'value1', 'param1' => 'value1');
$result = $client->__soapCall('getRecords', array('parameters' => $params));
// result array stored in $result->getRecordsResult
?>
I am always getting:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https : // blah . service-now . com / incident.do?WSDL' : failed to load external entity "https : // blah . service-now.com / incident.do?WSDL" in /var/www/index.php:3 Stack trace: #0 /var/www/index.php(3): SoapClient->SoapClient('https://blah.ser...', Array) #1 {main} thrown in /var/www/index.php on line 3
Of course I use the subdomain I want instead of blah. But let's assume it's blah.
Please help me. Is this code ok? Where do I place my username? On the user area? or in the login area? What about param1 and value1, which one of these do I need to change?
Yes, I have permission to do this on my servicenow instance, I can do other things regarding soap and wsdl.
goto "System Properties" -> "Web Services" and make sure that
"Require authorization for incoming WSDL requests." ist set to NO
If this flag is set to Yes you will not be able to directly create a SoapClient within PHP the way you described it.
Related
I am attempting to create a user on my Chef Server through the Chef Server API. I am currently using a PHP wrapper for the API interface which can be found here.
I understand that in order to create a user using the API, you must provide the pivotal.pem file as well as the pivotal username.
Here is a snippet of my PHP code that I am using:
// ENVIRONMENT VARIABLES
// The URL for the Chef Server
$server = "mycompany.com";
// The name used when authenticating
$client = 'pivotal';
// The location of the file which contains the client key
$key = "../../../pivotal.pem";
// The version of the Chef Server API that is being used
$version = "12.0.2";
// Create a Chef object
$chef = new Chef($server, $client, $key, $version);
// API Request
$createUserRequest = array("name"=>$displayName, "display_name"=>$displayName, "email"=>$emailAddress, "password"=>$password);
$createUserRequest = json_encode($createUserRequest);
$chef->post('/users/', $createUserRequest);
Here is the reponse that I receive from the server:
Fatal error: Uncaught exception 'Exception' with message 'Invalid signature for user or client 'pivotal'' in C:\Workspace\SA_SSAF\app\plugin\CHEF\Chef PHP\src\Jenssegers\Chef\Chef.php:187
Stack trace:
#0 C:\..\..\app\plugin\CHEF\Chef PHP\src\Jenssegers\Chef\Chef.php(70): Jenssegers\Chef\Chef->api('/users/', 'POST', '{"name":"entra"...')
#1 C:\..\..\app\plugin\CHEF\controller\chefEnrollUser.php(55): Jenssegers\Chef\Chef->post('/users/', '{"name":"entra"...')
#2 {main}
thrown in C:\..\..\app\plugin\CHEF\Chef PHP\src\Jenssegers\Chef\Chef.php on line 187
If I try and perform a GET request using the same configuration, I receive a successful response.
Any clues as to why something like this may be happening?
Thanks
I am trying to create a website that retrieves data from a Web Service using the site API.
The 'nuSOAP' PHP library seems to be a perfect way to go about this and so I have been trying to run through a basic tutorial by Scott Nichol called 'Introduction to NuSOAP'.
Here is the code for server.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server;
// Register the method to expose
$server->register('hello');
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
...and here is the code for the client.php:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/beehive/server.php');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'John'));
// Display the result
print_r($result);
?>
I have 'XAMMP' installed and so when I call up client.php via the browser it should bring up a basic page that says 'Hello, John' but instead I get the following error message:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from '.../server.php' : Start tag expected, '<' not found in C:\xampp\htdocs\beehive\client.php:7 Stack trace: #0 C:\xampp\htdocs\beehive\client.php(7): SoapClient->SoapClient('http://...') #1 >{main} thrown in C:\xampp\htdocs\beehive\client.php on line 7
I figured I should be loading the client page rather than the server, but if I load server.php then I get the error message 'This service does not provide a Web description'.
I have followed the tutorial exactly and can't figure out why it's throwing this error; can anyone please help?
Thank you!
The error you receive makes perfect sense with your error description. The server isn't responding with the right format and therefor your client breaks.
The same error is discussed here:
nusoap simple server
You need to point the client constructor to your wsdl file...
$client = new soapclient('http://localhost/beehive/server.php');
I have been trying to update a cell in a google spreadsheet. I'm using ZendFramework-1.12.6 and PHP Version 5.5.9. The response I get using the code is:
ERROR: Expected response code 200, got 400 The spreadsheet at this URL could not be found. Make sure that you have the right URL and that the owner of the spreadsheet hasn't deleted it.
And if I remove the error trapping I get this message:
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400 Missing resource version ID' in /volume1/web/Zend/Gdata/App.php:717 Stack trace: #0 /volume1/web/Zend/Gdata/App.php(933): Zend_Gdata_App->performHttpRequest('PUT', '', Array, 'put(Object(Zend_Gdata_Spreadsheets_CellEntry), NULL, NULL, NULL, Array) #2 /volume1/web/Zend/Gdata/App/Entry.php(209): Zend_Gdata_App->updateEntry(Object(Zend_Gdata_Spreadsheets_CellEntry), NULL, NULL, Array) #3 /volume1/web/Zend/Gdata/Spreadsheets.php(307): Zend_Gdata_App_Entry->save() #4 /volume1/web/gss.php(19): Zend_Gdata_Spreadsheets->updateCell('1', '1', 'test', '1zoCs23pKzQXPtB...', 'od6') #5 {main} thrown in /volume1/web/Zend/Gdata/App.php on line 717
It seems like everything works great until I try writing the string 'test' to the spreadsheet with the updateCell call. Can anyone help?
<?php
// load Zend Gdata libraries
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
// set credentials for ClientLogin authentication
$user = "mygmailaccount#gmail.com";
$pass = "mypassword";
// connect to API
$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$service = new Zend_Gdata_Spreadsheets($client);
// set target spreadsheet and worksheet
$ssKey = '1zoCs23pKaQXPtB2rT5Rn6KVzJalIoR5VYBnlURJRRLs';
$wsKey = 'od6';
$service->updateCell('1', '1', 'test', $ssKey, $wsKey);
?>
After several hours of troubleshooting this same problem, I eventually figured out that this is a bug or a missing feature with the "new" Google Spreadsheets.
See the comments on this post: Updating cell in Google Spreadsheets returns error "Missing resource version ID" / "The remote server returned an error: (400) Bad Request."
Information on the "new" Google Sheets: https://support.google.com/drive/answer/3541068
On that page is a link that allows you to create a new spreadsheet using the "old" Sheets: https://g.co/oldsheets
My solution was to create a new "old" sheet. I'm now able to use updateCell with no problems!
I just found your question and with some additional information I found a really easy solution so I thought I'd share that too.
The problem seems to be, that there needs to be an Etag set for the skript to perform correctly. This Etag is
array('If-Match'=> '*')
To add this as a header to every UpdateCell request go into the source file in the library path:
library/Zend/Gdata/Spreadsheets.php
and change the UpdateCell method definition from
$entry = $this->getCellEntry($query);
$entry->setCell(new Zend_Gdata_Spreadsheets_Extension_Cell(null, $row, $col, $inputValue));
$response = $entry->save();
to
$entry = $this->getCellEntry($query);
$entry->setCell(new Zend_Gdata_Spreadsheets_Extension_Cell(null, $row, $col, $inputValue));
$response = $entry->save(null,null,array('If-Match'=> '*'));
Requests are now working for me as previously.
I'm using SSRS SDK for PHP
PHP Version 5.4
WebServer: Centos 6.4
MSSQL Server 2008 R2
When I make
$ssrs_report = new SSRSReport(new Credentials(UID, PASWD), SERVICE_URL);
I got the following error
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL:
Couldn't load from 'http://172.16.4.63/ReportServerURL/Pages/ReportViewer.aspx?%2fTestFolder%2ftestClaimHdr&rs:Command=Render/ReportExecution2005.asmx?wsdl' :
Premature end of data in tag html line 1 in /var/www/emilio/app/Libraries/SSRSReport/bin/SSRSReport.php:196
Stack trace: #0 /var/www/emilio/app/Libraries/SSRSReport/bin/SSRSReport.php(196):
SoapClient->SoapClient('http://172.16.4...', Array) #1 /var/www/emilio/SSRS/index.php(12):
SSRSReport->SSRSReport(Object(Credentials), 'http://172.16.4...') #2 {main} thrown in
/var/www/emilio/app/Libraries/SSRSReport/bin/SSRSReport.php on line 196
I'm looking how to fix it and get the report trough the soap(SSRS SDK for PHP).
I tried using file_get_content() and curl and both worked fine, then isn't connection problems, I have
Soap Client enabled
allow_url_fopen is On
this is the line where the sdk call the soap service
$executionServiceUrl="http://172.16.4.63/ReportServerURL?%2fTestFolder%2ftestClaimHdr&rs:Command=Render/ReportExecution2005.asmx?wsdl";
$options = array ( 'login' => 'xxxx\\xxxx', 'password' => 'xxxx', )
$this->_soapHandle_Exe = new SoapClient($executionServiceUrl, $options);
Adding
try {
$this->_soapHandle_Exe = new SoapClient($executionServiceUrl, $options);
} catch (Exception $e) {
var_export(libxml_get_last_error());
}
I get the following array:
LibXMLError::__set_state(array(
'level' => 3,
'code' => 77,
'column' => 43325,
'message' => 'Premature end of data in tag html line 1',
'file' => 'http://172.16.4.63/ReportServerURL?%2fTestFolder%2ftestClaimHdr&rs:Command=Render/ReportExecution2005.asmx?WSDL',
'line' => 1,
)
According to xmlerror from libxml2
level 3 = XML_ERR_FATAL = 3 : A fatal error
code 77 = XML_ERR_TAG_NOT_FINISHED = 77 : 77
I have alredy set the Basic authentication in the SSRS SERVER
Update
As #jwhaley58 said I changed to:
define("SERVICE_URL", "http://172.16.4.63/ReportServerURL");
$ssrs_report = new SSRSReport(new Credentials(UID, PASWD), SERVICE_URL);
$ssrs_report->LoadReport2('testClaimHdr',NULL);
and I get:
Fatal error: Uncaught exception 'SSRSReportException' in
/var/www/emilio/app/Libraries/SSRSReport/bin/SSRSReport.php:590 Stack trace: #0
/var/www/emilio/app/Libraries/SSRSReport/bin/SSRSReport.php(326):
SSRSReport->ThrowReportException(Object(SoapFault)) #1 /var/www/emilio/SSRS/index.php(15):
SSRSReport->LoadReport2('testClaimHdr', NULL) #2 {main} thrown in
/var/www/emilio/app/Libraries/SSRSReport/bin/SSRSReport.php on line 590
Some gochas that I only found through trial and error are some configuration issues, on the server that is running the reporting server service, make sure that in your file rsreportserver.config has been modified to allow for basic authentication. By default, if I'm understanding it correctly, it wants a more trustworthy connection type, but the sdk needs you to allow simple name and passwords to be passed. This means that needs to be added to your authentication methods in the configuration.
so for example,
In
C:\Program Files\Microsoft SQL Server\MSRS11.1\Reporting Services\ReportServer\rsreportserver.config (Different for server and version, but you get the idea.)
<Authentication>
<AuthenticationTypes>
<RSWindowsNTLM/>
<RSWindowsBasic/> ##you need to add this one##
</AuthenticationTypes>
<RSWindowsExtendedProtectionLevel>Off</RSWindowsExtendedProtectionLevel>
</Authentication>
IIRC you will have to restart the service for this to take effect.
Also, if you are attempting to RenderAs, some of the template files used to pop the headers have space in them towards the bottom that will prevent you from rendering as Excel, PDF, ect unless that has been fixed since I worked on it.
I'm looking through the code you provided, I may be reading it wrong, but it looks like you are trying to explicitly define the report you're after in the execution url. If that is in fact what you are doing, I believe the fix would be to only define the report base you are connecting to so for your example the url should be http://172.16.4.63/ReportServer/. After that connection is made, you would use the LoadReport2 function to specify which report you need.
Lastly, Where you have the name of the report, it looks like you have a subdirectory called testfolder? if that is still the case, you would need your report name to be "/TestFolder/testClaimHdr" in the call to LoadReport2.
Hope any of that helps.
I am trying to access a Magento API, using SOAP. the code I have works fine normally, however the client wishes to password protect the Magento main folder. Doing so breaks access to the API and causes an error.
The documentation suggests this isnt a problem and you can just specify the username/password, however this does not work.
I am using PHP and IIS, with the password protection set up via Plesk 10. Does this use Basic HTTP authentication or something else?
My access code is:
$client = new SoapAuthClient($GLOBALS["magento_api_path"],array(
'login'=>"admin",
'password'=>"password"
)
);
$session = $client->login($GLOBALS["magento_api_user"], $GLOABLS["magento_api_password"] ,
array(
'login'=>"admin",
'password'=>"password"
) );
The error I get is:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/' : failed to load external entity "http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/" in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php:20 Stack trace: #0 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->__call('login', Array) #1 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->login('backenduser', 'backendwebuser', Array) #2 {main} thrown in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php on line 20
The line referred to is the $client->login command.
Any suggestions?
I've faced a similiar problem long time ago.
In my case, I didn't immediately realize that I need to use .htaccess credentials while creating the SoapClient instance, but pass SOAP API credentials to the login method.
I was passing the SOAP API credentials all over and got a similiar error like you do.
Here's what worked for me (1.3.x version, though. Still works for me as of today):
$cProxy = new SoapClient(
URL . 'index.php/api/soap/?wsdl',
array(
'login' => HTACCESS_USER,
'password' => HTACCESS_PASS
)
);
$rSessionId = $cProxy->login(
SOAP_USER,
SOAP_PASS
);
Just to play save, that you are didn't got trapped by a typo: you pass $GLOABLS["magento_api_password"] as 2nd param to the login method, which should be $GLOBALS["magento_api_password"].
Finally, you're passing a 3rd argument to the login method which I believe is obsolete, since afaik it's defined to have two params only:
<message name="login">
<part name="username" type="xsd:string" />
<part name="apiKey" type="xsd:string" />
</message>
Been there, done that :P
$client = new SoapClient("http://${http_user}:${http_pass}#subdomain.domain.com", array(
'login' => $user,
'password' => $pass,
));
The problem is that the use of the http auth only happens during the requests and not while actually fetching the wsdl on the first request. To get around that, simply use the format i posted above: http://USERNAME:PASSWORD#server.com/
Cheers
This problem is likely because internally Magento is requesting, via a local HTTP request, it's own WSDL. As you've password protected the access, it's not going to work. Modify the security to not require a password if the request is coming from localhost.
If you look at Mage_Api_Model_Server_Adapter_Soap::getWsdlUrl() you will see, that magento assumes that basic auth login and password are passed as environment variables PHP_AUTH_USER and PHP_AUTH_PW.