I am getting issue to call brandbank webservice via php by using nusoap.php library.
I have to fetch data from Brandbank webservice which they exposed at
https://www.i-label.net/partners/webservices/datafeedbasic/extractdata.asmx?WSDL
I have made my code in php by using nusoap.php library but getting errors
MY code
require_once "nusoap.php";
$client = new nusoap_client("https://www.i-label.net/partners/webservices/datafeedbasic/extractdata.asmx?WSDL");
$error = $client->getError();
if ($error) {
echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
$param = array('ExternalCallerId'=>' 32 char key ','GTIN'=>'04015400440819','Description'=>'TAMPAX BLUE BOX MINI 20s','OwnLabel'=>'false','Category'=>'HHB','HasImage'=>'false');
$client->setUseCurl(true);
$client->soap_defencoding = 'UTF-8';
$result = $client->call("GetUnsentProductData", $param);
if ($client->fault) {
echo "<h2>Fault</h2><pre>";
print_r($result);
echo "</pre>";
}
else {
$error = $client->getError();
if ($error) {
echo "<h2>Error</h2><pre>" . $error . "</pre>";
}
else {
echo "<h2>Products Info</h2><pre>";
echo $result;
echo "</pre>";
}
}
Here is response of webservice
Array
(
[faultcode] => soap:Server
[faultstring] => Server was unable to process request. ---> An exception has occured whilst processing your request. The details have been logged, and the system administrator has been notified
[detail] =>
)
Brandbank WSDL link: https://www.i-label.net/partners/webservices/datafeedbasic/extractdata.asmx?WSDL
The problem that I am facing I don’t know how to send them product list in parameters along with this soap call.
I can see this ticket is old, but it appears you are trying to send Coverage file information to the GetUnsent endpoint.
The endpoint for Coverage can be found via https://www.i-label.net/partners/webservices/datafeedbasic/extractdata.asmx?WSDL
Related
This code sometimes works, but frequently runs for ~20s then fails with the "503 Service Unavailable" message when I call getPage(). The authentication/token request seems to be working fine.
I can't seem to identify any pattern of when it fails/succeeds. I don't believe it's a throttling error, as there is no "Retry-After" header returned, and the script only runs once per day at night with <200 records returned. I've also tried removing the $filter and changing parameter order as described here, with no clear benefit.
Can someone please help find the cause here? Happy to share any additional info. Any help is much appreciated, thanks!
<?php
define('DEBUG', true);
session_start();
// set config vars
$ms_url_base = "https://login.microsoftonline.com/d3523db7-f84a-4a24-a815-cd4ba4691c9c";
$ms_client_id = '<client id>';
$ms_redirect_uri = "https://example.com/path";
$ms_scope = "calendars.readwrite user.read";
$ms_client_secret = '<secret>';
$ms_auth_endpoint = '/oauth2/v2.0/authorize';
$ms_token_endpoint = '/oauth2/v2.0/token';
$query_numdays = 100;
if (DEBUG) error_reporting(E_ALL);
date_default_timezone_set("America/Detroit");
require_once __DIR__.'/vendor/autoload.php';
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;
class EventMod extends \Microsoft\Graph\Model\Event {
// custom functions here
public function getNextLink() {
parent::getNextLink();
}
}
class ResponseMod extends \Microsoft\Graph\Http\GraphResponse {}
// authorization
$provider = new Stevenmaguire\OAuth2\Client\Provider\Microsoft([
'clientId' => $ms_client_id,
'clientSecret' => $ms_client_secret,
'redirectUri' => $ms_redirect_uri,
'urlAuthorize' => $ms_url_base.$ms_auth_endpoint,
'urlAccessToken' => $ms_url_base.$ms_token_endpoint,
'urlResourceOwnerDetails' => 'https://graph.microsoft.com/v2.0/me',
]);
if (!isset($_GET['code'])) {
$options = ['scope' => $ms_scope, 'aud' => 'Graph'];
$authUrl = $provider->getAuthorizationUrl($options);
$_SESSION['oauth2state'] = $provider->getState();
header('Location: '.$authUrl);
exit;
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
} else {
try {
$token = $provider->getAccessToken('authorization_code', ['code' => $_GET['code']]);
} catch (League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
exit ("Get access token exception: ".$e->getMessage());
}
if (DEBUG) {
echo 'Access Token: ' . $token->getToken() . "<p>";
echo 'Refresh Token: ' . $token->getRefreshToken() . "<p>";
echo 'Expired in: ' . $token->getExpires() . "<p>";
echo 'Already expired? ' . ($token->hasExpired() ? 'expired' : 'not expired') . "<p>";
}
// start calendar query
$start=new DateTimeImmutable("yesterday 0:0:1");
$end = $start->add(new DateInterval("P".$query_numdays."D"));
$url='/me/calendarview'
.'?startdatetime='.$start->format('c')
.'&enddatetime='.$end->format('c')
.'&$filter=isOrganizer+eq+false'
.'&$select=subject,responseStatus,start,categories'
.'&$orderby=start/dateTime';
$graph = new Graph;
$graph->setAccessToken($token->getToken());
$data = array();
try {
$iterator = $graph->createCollectionRequest("GET", $url)
->setReturnType(EventMod::class)
->addHeaders(["Prefer" => 'outlook.timezone="America/Detroit"'])
->setPageSize(25);
do {
$page = $iterator->getPage(); /*************** THIS IS WHERE THE EXCEPTION HAPPENS ************/
if (DEBUG) echo "<pre>".print_r($page, true)."</pre>";
$data = array_merge($data, $page);
} while (!$iterator->isEnd());
}
catch (\Microsoft\Graph\Exception\GraphException $e) {
if (DEBUG) echo "GraphException Message: ".$e->getMessage();
exit;
}
catch (Exception $e) {
if (DEBUG) echo "Unk Exception getting data: ".$e->getMessage();
exit;
}
if (DEBUG) print_r($data);
}
?>
composer.json
{
"require": {
"microsoft/microsoft-graph": "^1.29",
"stevenmaguire/oauth2-microsoft": "^2.2"
}
}
I played with your above API call and i ended up noticing the issue - in the case of having bigger larger dates and lot of data at my end (not with smaller time window or less records). It tells me that the failure is due to the client timeout. We need to understand that Calendar view is an expensive operation that too when you deal with calendars and filters added to it. So i went ahead in this scenario, reduce/minimize time window for calendar view by client so smaller segments of time are scanned for matching calendar events. It helped me to get the records as i expected and make use of effective usage of Calendarview API call too.
Apparently the issue was not in the code at all. I discovered that the 503 error was thrown only when a specific date's events were being read by the API. One of the events was rather large and I deleted it; after this the script works well.
This particular event has 16536 attendees listed, which I believe was the source of the error. Still unexplained is why the error was intermittent. I was eventually able to get graph explorer to successfully read the event, so perhaps the bug is in the Microsoft Graph SDK for PHP. I will post there to see if the devs want to capture this error condition.
In the Twilio documentation, it states you can send a text to voice call statically like this:
use Twilio\Rest\Client;
$AccountSid = "";
$AuthToken = "";
$client = new Client($AccountSid, $AuthToken);
try {
$call = $client->account->calls->create(
"+15555551234",
"+15555554321",
array("url" => '/twilio/twilio.welcome.message.php')
);
echo "Started call: " . $call->sid;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
I find that to be a little bit much for dynamically created messages. This is fine for static messages. What I want to do is something like this:
use Twilio\Twiml;
$response = new Twiml();
$response->say('Chapeau!', ['voice' => 'woman', 'language' => 'fr']);
$AccountSid = "";
$AuthToken = "";
$client = new Client($AccountSid, $AuthToken);
try {
$call = $client->account->calls->create(
"+phoneNumber",
"+phoneNumber",
array("response" => $response)
);
echo "Started call: " . $call->sid;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
It hints at being able to do this in the documentation, but I can't find it anywhere. I'd be really shocked if there wasn't an easier implementation than creating a php script, to call, and then delete to get this to work. But I've seen worse things in my life.
Twilio developer evangelist here.
I'm afraid there's no way to send TwiML to Twilio to be executed when a call is answered. You still need to send a URL that will respond with TwiML when the call is connected.
However, you can make that URL react dynamically. If you are just sending a message to be read out then you could send the message as a query parameter in the URL and then use that message when the webhook is called. For example:
$message = "Hello! This is a message!";
$call = $client->account->calls->create(
"+15555551234",
"+15555554321",
array("url" => '/twilio/twilio.welcome.message.php?message='.urlencode($message))
);
Then, in your webhook:
<?php
$message = $_REQUEST['message'];
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
?>
<Response>
<Say><?php echo $message ?></Say>
</Response>
This way, you can dynamically create messages but only host one webhook endpoint.
Let me know if that helps at all.
What about using Twiml bin? This way instead of pointing to your server, you'd have a twilio hosted URL that generates the twiml for you. It supports dynamic variables, looping etc.
see : https://support.twilio.com/hc/en-us/articles/230878368
And then use dynamic variables like this :
<Say>Hello {{CustomerName}}</Say>
I am able to consume soap web service using wizdler in my chrome but need to how can I consume it in my php code.
From Wizdler I can get the proper response, for example I am posting the information like this:
Question is how to call this service from php code, what I did/trying so far is:
<?php
$wsdl = "http://64.20.37.90/VTWebServiceTest/VisualService.svc?wsdl";
$client = new SoapClient($wsdl);
$request_param = array(
"storeNumber" => "valid value",
"enterpriseId" => "valid value",
"credential" => "valid value"
);
try {
$responce_param = $client->GetCategories($request_param);
$result = $responce_param->GetCategoriesResult;
print_r($result);
} catch (Exception $e) {
echo "Exception Error!";
echo $e->getMessage();
}
?>
But it always returns message "12|Invalid service credential."
Can anybody help me out?
Thanks in advance.
maybe try this ...
$responce_param = $client->GetCategories($request_param);
print_r($responce_param);
or even
$responce_param = $client->GetCategories($request_param);
$values = get_object_vars($responce_param);
$myresults = object_to_array($values);
print_r($myresults);
Trying to add to cart functionality in my custom php code using shopify ajax api. My code is below for which getting error code 401.
Anybody can give me example of how use the Shopify ajax apis or solve problem in code below in php code.
CODE:
<?php
session_start();
require __DIR__.'/vendor/autoload.php';
use phpish\shopify;
require __DIR__.'conf.php';
$shopify = shopify\client(SHOPIFY_SHOP, SHOPIFY_APP_API_KEY, SHOPIFY_APP_PASSWORD, true);
try
{
$add = $shopify('POST /cart/add.js',array(), array
(
'cart' => array
(
"quantity" => 2,
"id" => 3908511558
)
));
echo "<pre>";
print_r($add);
echo "</pre>";
}
catch(shopify\ApiException $e)
{
echo $e;
echo "<pre>";
print_R($e->getRequest());
print_R($e->getResponse());
echo "</pre>";
}
catch(shopify\CurlException $e)
{
echo $e;
echo "<pre>";
print_R($e->getRequest());
print_R($e->getResponse());
echo "</pre>";
}
?>
ERROR:
phpish\shopify\ApiException: [401] Unauthorized
You are sending wrong parameters to the api. Try :
shopify\client(STORE_NAME, SHOPIFY_APP_API_KEY, ACCESS_TOKEN);
in place of :
$shopify = shopify\client(SHOPIFY_SHOP, SHOPIFY_APP_API_KEY, SHOPIFY_APP_PASSWORD, true);
Rest of the code seems correct.
I am going crazy starting off with Web Services. I am trying to call the following WSDL using PHP and keep getting nowhere:
http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCreateRQ.wsdl
I found the following piece of code on the net, from someone with similar problems, but I could not get it to work either:
$soap = new SoapClient('http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCreateRQ.wsdl',
array(
'trace' => true,
'soap_version' => SOAP_1_2,
"exceptions" => 0));
$eb = new EbXmlMessage();
$sec = new Security();
$scrq = new SessionCreateRQ();
try {
$omg = $soap->SessionCreateRQ($scrq, $sec,$eb);
}
catch (Exception $e)
{
print_r($e);
}
//debug
print "Request: \n".
htmlspecialchars($soap->__getLastRequestHeaders()) ."\n";
print "Request: \n".
htmlspecialchars($soap->__getLastRequest()) ."\n";
print "Response: \n".
$soap->__getLastResponseHeaders()."\n";
print "Response: \n".
$soap->__getLastResponse()."\n";
print_r($omg);
//the first envelope headers
class EbXmlMessage
{
public $From = array('PartyId' => 'mysite.com');
public $To = array('PartyId' => 'myprovider.com');
public $CPAId = 'ZZZZ';
public $ConversationId = 'myconv#id.com';
public $Service = 'Session';// or SessionCreate?
public $Action = 'SessionCreateRQ';
public $MessageData = array(
'MessageId' => 'messageid',
'Timestamp' => '2009-04-18T15:15:00Z');
}
//the security token
class Security {
public $Username = "xxxxx";
public $Password = "yyyyy";
public $Organization = "ZZZZ";
public $Domain = "DEFAULT";
}
//this is suppoused to be the payload, or the xml i need to send at the end
class SessionCreateRQ
{
public $POS = array(
'Source' => array(
'_'=>"",
'PseudoCityCode'=>'ZZZZ'
));
}
I keep getting the following error:
Response:
HTTP/1.1 500 Internal Server Error
SOAPAction: ""
Content-Type: text/xml;charset=utf-8
Date: Sun, 19 Apr 2009 22:21:34 GMT
Connection: close
Server: SWS
Response:
soap-env:Client.InvalidEbXmlMessageUnable to internalize
messagejavax.xml.soap.SOAPException: Unable to internalize message at
com.sun.xml.messaging.saaj.soap.MessageImpl.(MessageImpl.java:135)
at
com.sun.xml.messaging.saaj.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:32)
at
com.sabre.universalservices.gateway.control.SoapProcessor.getRequest(SoapProcessor.java:263)
at
com.sabre.universalservices.gateway.control.WSGateway.handleRequest(WSGateway.java:380)
at
com.sabre.universalservices.gateway.control.WSGateway.doPost(WSGateway.java:306)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)
at
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:584)
at
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
at java.lang.Thread.run(Thread.java:595) Caused by:
javax.xml.soap.SOAPException: Invalid
Content-Type:application/soap+xml at
com.sun.xml.messaging.saaj.soap.MessageImpl.verify(MessageImpl.java:159)
at
com.sun.xml.messaging.saaj.soap.MessageImpl.(MessageImpl.java:91)
... 19 more
SoapFault Object (
[message:protected] => Unable to internalize message
[string:private] => .....
This service should be validating me on the system and returning a security object to be used in later calls - a string(?) which I can then store in a session variable for the following calls.
Any help GREATLY appreciated!!!
One thing I noticed is that there is a faultcode value in the SoapFault Object:
[faultcode] => soap-env:Client.InvalidEbXmlMessage
So that may be a useful avenue to start debugging.
I tried comparing the structure of your EbXmlMessage to the XSD and the schema documentation, but I couldn't see any obvious reason that it was declared invalid.
Have you tried changing the Content-type header to text/xml?
Try using wsdl2php. It makes php classes out of the wsdl file. It uses php's SoapClient to send the data.
Here is a nice post explaining how to do it:
http://itworkarounds.blogspot.com/2011/10/simple-soap-client-with-wsdl2php-using.html
Just use nuSOAP. I don't like PHP native SoapClient. nuSoap generates for you a wsdl so you don't have to worry about how to make one.. Here's nuSOAP and here's a simple example code or you can download whole working code here :
Server :
<?php
// include the SOAP classes
require_once('nuSOAP/lib/nusoap.php');
function HelloWorld(){
return 'HelloWorld'; // Returns HelloWorld string
}
function Hello($name){
return 'Hello '.$name; // Returns Hello with name string parameter
}
// create the server object
$server = new nusoap_server();
// Initialize WSDL support
$server->configureWSDL('webservicenamespace', 'urn:webservicenamespace');
$server->register('HelloWorld', array(), array('result' => 'xsd:string')); //xsd:string; xsd:boolean; xsd:integer and so on..
$server->register('Hello', array('name' => 'xsd:string'), array('result' => 'xsd:string')); // array('parametername' => 'parametertype'),array('result' => 'returntype');
if (isset($error))
{
$fault =
$server->fault('soap:Server','',$error);
}
// send the result as a SOAP response over HTTP $HTTP_RAW_POST_DATA
$post = file_get_contents('php://input');
$server->service($post);
?>
Client :
<?php
// Pull in the NuSOAP code
require_once('nuSOAP/lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('http://pathtourl/sample_webservice.php?wsdl', true);
// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
// At this point, you know the call that follows will fail
}
// Call the SOAP method
$result = $client->call('Hello', array('name' => 'Scott')); // Call function name, parameters;
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
Now when you want to make a client you need your wsdl you can simply get it by adding ?wsdl on your link i.e( webservice.php?wsdl )
Hope this helps :) Good luck with your web service.