WooCommerce REST API Fatal Error Connection Issue - php

I'm trying to make woocommerce REST API work. On first sight it apears quite simple by following the doc: https://woocommerce.github.io/woocommerce-rest-api-docs/?php#introduction.
But I struggle making it work.
Here is my code:
<?php
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'my_website_uri',
'consumer_key',
'consumer_secret',
[
'wp_api' => true,
'version' => 'wc/v2'
]
);
try{
print_r($woocommerce->get(''));
}
catch (HttpClientException $e) {
print_r($e->getMessage());
print_r($e->getRequest());
print_r($e->getResponse());
}
?>
Here is what i get:
Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: Syntax error in /Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:346 Stack trace: #0 /Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php(385): Automattic\WooCommerce\HttpClient\HttpClient->processResponse() #1 /Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/Client.php(82): Automattic\WooCommerce\HttpClient\HttpClient->request('', 'GET', Array, Array) #2 /Applications/MAMP/htdocs/WC_REST/test.php(19): Automattic\WooCommerce\Client->get('') #3 {main} thrown in /Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php on line 346
I wrote down exactly what's in the doc.

I always got an '/wp-json/wc/v2/system_status was not found on this server.' error when enabling the output of $body as suggested above.
I fixed it with enabling permalinks (in admin-backend) which is needed for accessing a slash separated url.

Related

Uncaught SoapFault exception: [HTTP] Forbidden

I am new to SOAP API and WSDL. I had this project to use the SOAP API and I used this code from one of the stackoverflow answers. But when I am running this, I am getting this error.
Fatal error: Uncaught SoapFault exception: [HTTP] Forbidden in 'directory' Stack trace: #0 [internal function]: SoapClient->__doRequest('...') #1 directory): SoapClient->__call('method', Array) #2
Here is my code:
<?php
try{
$wsdl_url = 'API';
$client = new SoapClient($wsdl_url);
} catch (SoapFault $e) {
echo 'Error in Soap Connection : '.$e->getMessage();
}
$params = array(
'LBID' => '1',
'YearID' => '23',
'SectorId' => '3',
'Password' => 'password'
);
$result= $client->getProjectDetails($params);
print_r($result);
?>
I am able to access the api by directly putting it on address bar. The soap connection is established, no errors there. But this error is showing on the method calling line, $result= $client->getProjectDetails($params);
I don't know what this error is, I tried searching the forums but couldn't get any idea about this. Can anyone help?

How to login Five9 through API

Im new to Five9 i got some sample code in GitHub (https://github.com/kielerrr/Five9 ) which i went though the code and i passed the credentials into API but i get the following error
"Fatal error: Uncaught Error: Class 'SoapClient' not found in C:\xampp\htdocs\Five9-master\includes\Five9.php:20 Stack trace: #0 C:\xampp\htdocs\Five9-master\contacts\getContactRecords.php(12): f9->__construct() #1 {main} thrown in C:\xampp\htdocs\Five9-master\includes\Five9.php on line 20"
$wsdl_five9 = "https://api.five9.com/wsadmin/v4/AdminWebService?wsdl&user=User_ID";
//$wsdl_five9 = "https://api.five9.com/wsadmin/v4/AdminWebService?wsdl";
try {
$soap_options = array('login' => 'uer_name', 'password' => 'mypassword', 'trace' => true);
$this->_connection = new SoapClient($wsdl_five9, $soap_options);//20th line
} catch (Exception $e) {
$error_message = $e->getMessage();
echo $error_message."ERROR";
exit;
}
Please help me to go through this ...
The Above code works fine need to enable soap in your system .
locate your php.ini file and Un-comment(remove semicolon before soap extension)as below.
change from :
";extension=php_soap.dl"
to :
"extension=php_soap.dll" .

php code not working for SOAP API, TNT

I am working on TNT SOAP based API, I am using below code but gets only error, I can`t understand what I am doing wrong ?
ini_set("default_socket_timeout",120);
$client = new SoapClient('https://uat.tntexpress.com.au/Webservices/Conservice/ConsignmentService.svc?wsdl');
$params = array(
'payingAccount' => '20003191',
'UserName' => 'NEX-APIT',
'Password' => 'NEX_APIPWT'
);
$response = $client->__soapCall('ProcessConsignmentRequest',$params);
print_r($response);
I am getting this error :
Fatal error: Uncaught SoapFault exception: [s:Client] The creator of this fault did not specify a Reason. in D:\xampp\htdocs\tnt\soap.php:11
Stack trace:
#0 D:\xampp\htdocs\tnt\soap.php(11): SoapClient->__soapCall('ProcessConsignm...', Array)
#1 {main} thrown in D:\xampp\htdocs\tnt\soap.php on line 11
I found here the working code tnt-express

Spotify request access token is not working when refresh url

Right now i am working on spotify api, When i hit url for first time it is giving me all playlist but when i refresh page again it is giving me exception error, here is my code,
require '../../../vendor/autoload.php';
$session = new SpotifyWebAPI\Session('******', '*******', 'http://localhost:8080/spotify/vendor/jwilsson/spotify-web-api-php/demo.php');
$api = new SpotifyWebAPI\SpotifyWebAPI();
if (isset($_GET['code'])) {
$session->requestAccessToken($_GET['code']);
$data = $api->setAccessToken($session->getAccessToken());
$artistData = $api->me();
$artistId = $artistData->id;
$playlists = $api->getUserPlaylists($artistId, array(
'limit' => 5
));
foreach ($playlists->items as $playlist) {
echo '' . $playlist->name . ' <br>';
}
} else {
$scopes = array(
'scope' => array(
'user-read-email',
'user-library-modify',
),
);
header('Location: ' . $session->getAuthorizeUrl($scopes));
}
Here is my exception error
Fatal error: Uncaught exception 'SpotifyWebAPI\SpotifyWebAPIException' with message 'Invalid authorization code' in D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Request.php:156 Stack trace: #0 D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Request.php(26): SpotifyWebAPI\Request->send('POST', 'https://account...', Array, Array) #1 D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Session.php(233): SpotifyWebAPI\Request->account('POST', '/api/token', Array) #2 D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\demo.php(31): SpotifyWebAPI\Session->requestAccessToken('AQAaVZvpXUExKg2...') #3 {main} thrown in D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 156
Can anyone please tell me why it cause error ? If anyone have experiance with spotify
Creator of the library here.
The only thing I can think of which would yield that error message is if you try to request a access token twice with the same code. Try visiting the URL to your PHP file again but remove any ?code=... parts.

How to upload a file using box view api in php

I am trying to utilize in php uploading a file using box view api. I am using the library from box-view-api GitHub
Here is my code:
<?php
require_once('repository_fns.php');
require 'lib/box-view-api.php';
require 'lib/box-view-document.php';
session_start();
$objid=$_GET['objid'];
$object_general=get_obj_general($objid);
$object_rights=get_obj_rights($objid);
$object_lifecycle=get_obj_lifecycle($objid);
$object_tech=get_obj_tech($objid);
do_html_header('', 'browse.css');
display_object_metadata($object_general, $object_rights, $object_lifecycle, $object_tech);
$api_key = 'MY_KEY';
$box = new Box_View_API($api_key);
$doc = new Box_View_Document(array(
'name' => 'Geology of Canada',
'file_path' => '/uploads/Geology of Canada.docx',
));
$box->upload($doc);
display_file_page();
do_html_footer();
?>
But why am I getting an error message:
Fatal error: Uncaught exception 'Box_View_Exception' with message 'couldn't open file "/uploads/Geology of Canada.docx"' in /home/ychenlucs15/public_html/lib/box-view-api.php:241 Stack trace: #0 /home/ychenlucs15/public_html/lib/box-view-api.php(456): Box_View_API->httpRequest(Array) #1 /home/ychenlucs15/public_html/show_object.php(28): Box_View_API->upload(Object(Box_View_Document)) #2 {main} thrown in /home/ychenlucs15/public_html/lib/box-view-api.php on line 241
Can someone show me how to implement it correctly with php? Thank you in advance.

Categories