This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Authorization failed.

Jina wrote on 2018-06-30:

Recently i created a free trial account. And implemented the API code but when it comes to convert HTML to PDF it shows me error as

Authorization failed. Provide a valid username and API key.

Also its not showing me correct used tokens.

Can you help me out

Following is the code for just accessing total token used. And we are using wordpress:

So included file as:

if( ! class_exists('PdfCrowd') ) {
include( dirname( __FILE__ ).'/includes/api/pdfcrowd.php' );

$client = new \Pdfcrowd\HtmlToPdfClient( "support_westerndeal", "your-api-key" );

$token = '<span class="description">Token Used: </span> ' . $client->getRemainingCreditCount();
support wrote on 2018-06-30:
Hello Jina,

The message means some authorization error. Please try to run curl test for more details.
Use your API key, the API key is not written here, because it's like a password and this is a public forum.

curl -v -u 'support_westerndeal:your-api-key' -F text='hello world' -o test.pdf

Your license is working correctly. The following PHP test works too:
require 'pdfcrowd.php';

    // create the API client instance
    $client = new \Pdfcrowd\HtmlToPdfClient("support_westerndeal",
                                            "your api key");

    // create output file for conversion result
    $output_file = fopen("/tmp/test.pdf", "wb");

    // run the conversion and store the result into a pdf variable
    $pdf = $client->convertString("hello world");

    // write the pdf the into the output file
    fwrite($output_file, $pdf);

    // close the output file
catch(\Pdfcrowd\Error $why)
    // report the error
    error_log("Pdfcrowd Error: {$why}\n");
    error_log("Pdfcrowd Error Code: {$why->getCode()}\n");
    error_log("Pdfcrowd Error Message: {$why->getMessage()}\n");

    // handle the exception here or rethrow and handle it at a higher level
    throw $why;

Jina wrote on 2018-07-09:

I have to again write to you.

I tried your example and it worked for me but again same issue occurred ( Authorization failed. ) with another API account of our client. I am not sure if this is trial or paid version.

Username: hutchinson

Just to inform you we have upgraded the version of API. Is that creating an issue ?

But the upgradation worked for me than why not for this API credentials ?

Please reply us soon.
support wrote on 2018-07-09:
Hi Jina,

Pdfcrowd account with username hutchinson is using API v1. Please check your source code which version you are using.
The easiest way for API version identification is a Pdfcrowd client instantiation in your source code. API v2 contains string HtmlToPdfClient. e.g. for PHP
API v1
$client = new Pdfcrowd("your_username", "your_apikey");
API v2
$client = new \Pdfcrowd\HtmlToPdfClient("your_username", "your_apikey");

You can send us your source code to if the problem still persists.
Jina wrote on 2018-07-09:
The code we are using is of v2.

So updating the user account to v2 will work ?
support wrote on 2018-07-09:
Yes, each API version requires a license.
User hutchinson uses API v1 Medium Plan.