Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to print by given example - 1 #7

Open
lokendracdn opened this issue Mar 7, 2016 · 7 comments
Open

Not able to print by given example - 1 #7

lokendracdn opened this issue Mar 7, 2016 · 7 comments

Comments

@lokendracdn
Copy link

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

@petertuthill
Copy link
Contributor

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?

@lokendracdn
Copy link
Author

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

@holtkamp
Copy link

holtkamp commented Feb 2, 2017

Minor bump on this for @PrintNode-Pete

Currently investigating PrintNode, (pro)active support from the company in GitHub would be a major plus...

@petertuthill
Copy link
Contributor

@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.

@pareshhp
Copy link

pareshhp commented Jul 25, 2017

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 ?

@petertuthill
Copy link
Contributor

petertuthill commented Jul 25, 2017 via email

@pareshhp
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants