Not able to print by given example - 1
Opened this issue · 7 comments
Hi Support Team,
I have used your given instruction in example code, I am getting below error.
Catchable fatal error: Argument 1 passed to PrintNode\Request::__construct() must be an instance of PrintNode\Credentials, instance of PrintNode\ApiKey given, called in /var/www/html/printnode/examples/example-1-submitting-a-printjob.php on line 28 and defined in /var/www/html/printnode/examples/vendor/printnode/printnode-php/src/PrintNode/Request.php on line 85
But i fixed it by adding below code.
$credentials = new PrintNode\Credentials();
$credentials->setApiKey(PRINTNODE_APIKEY);
After added this code, I am getting another error:
Fatal error: Uncaught exception 'RuntimeException' with message 'HTTP Error (401): Unauthorized' in /var/www/html/printnode/examples/vendor/printnode/printnode-php/src/PrintNode/Request.php:597 Stack trace: #0 /var/www/html/printnode/examples/example-1-submitting-a-printjob.php(39): PrintNode\Request->__call('getComputers', Array) #1 /var/www/html/printnode/examples/example-1-submitting-a-printjob.php(39): PrintNode\Request->getComputers() #2 {main} thrown in /var/www/html/printnode/examples/vendor/printnode/printnode-php/src/PrintNode/Request.php on line 597
Please let me know what i am doing wrong and how cloud i run my basic example code.
Thanks
Lokendra Meena
Can you confirm what version of the client lib you are using? There is two releases at the moment "master" and "release/2.0.0-rc1".
Can you also publish the code which is throwing the error so I can have a go at reproducing?
Thanks support Team,
I am using the master branch code.
I have checked again my code and debuging it, I was wrong set api from printnode admin. Its type should be "restricted" but i have set it account.
after change the type. My code working properly.
Thanks
Lokendra Meena
Minor bump on this for @PrintNode-Pete
Currently investigating PrintNode, (pro)active support from the company in GitHub would be a major plus...
@holtkamp I hear you.
A while back one of my colleagues did a lot of work on this API lib (adding support for some of our newer API endpoints and reworking some of the pain points) but IIRC it didn't get merged back into master because of some breaking API changes and a some missing docs.
If you checkout the release/2.0.0 branch and view this https://github.com/PrintNode/PrintNode-PHP/blob/release/2.0.0/Examples/example-2-creating-your-first-printjob.php it works.
This release is also on composer tagged 2.0.0-rc1. https://packagist.org/packages/printnode/printnode-php#2.0.0-rc1
We're hard at work at the moment finishing off a big-ish project (adding linux support into our client software) at the moment but I'll find some time this week to get this release polished up, docs completed and finally merged into master which is something long overdue.
I am getting the same error
Error
Fatal error: Uncaught RuntimeException: HTTP Error (401): Unauthorized in project\include\PrintNode\Request.php:605
Stack trace: #0 project\include\utils\utils.php(13259): PrintNode\Request->__call('getPrinters', '?limit=2000')
#1 project\modules\SalesOrder\createdocuments.php(1493): checkForPrintNodePrinterKey(Array)
Code
function checkForPrintNodePrinterKey($pnParams)
{
$printnodeAPIKey = $pnParams['printNodeApiKey'];
require_once('include/PrintNode/loader.php');
$credentials = new PrintNode\Credentials();
$credentials->setApiKey($printnodeAPIKey);
$request = new PrintNode\Request($credentials);
$printers = $request->getPrinters("?limit=2000"); // GET ERROR ON THIS LINE.
....
}
It runs before perfect now getting above error.
What is the issue ? How to solve it ?
Thanks Peter !!
You are right, the API key (I was using) is not present in API tab of PrintNode logged page.
So it is dead or someone deleted.
I have used another existed PrintNode key and its works ! :)
Thanks for instant answer!