Printful is migrating from legacy API keys to Private Tokens and Public Apps.

On September 30, 2022, the creation of legacy API keys will be disabled in the Printful Dashboard.
On March 30, 2023, the Printful API will no longer be accessible when using legacy API keys.

The module needs to be updated to support these changes.

Comments

cameron prince created an issue. See original summary.

delty’s picture

I'm not much of a coder but I'm happy to help with this however I can.

trigdog’s picture

There really isn't much that is needed to get this working. I have not fully tested it but the amount of work depends on:

  • how to support both the api key and the new token
  • if you want to make a new config token setting instead of using the existing apiKey setting.

Changing these two lines in the Printful.php service class gets it working (So far, I have only test the get endpoints, in postman.co, to make sure they where the same and I did synchronize products through Drupal).

First, the /store endpoint does exist in OAuth and you have to use /stores:

'getStoreInfo' => [
      'path' => 'store',
    ],

To:

'getStoreInfo' => [
      'path' => 'stores',
    ],

Second, The header needs changed (if you use the apiKey field setting for the oauth token):

$options = [
      'headers' => [
        'Authorization' => 'Basic ' . base64_encode($this->apiKey),
      ],
    ];

To:

$options = [
      'headers' => [
        'Authorization' => 'Bearer ' . $this->apiKey,
      ],
    ];
delty’s picture

Howdy,

I tried the above changes but now get an error when attempting to sync products.

Warning: Undefined array key "name" in Drupal\commerce_printful\Form\PrintfulStoreForm->validateForm() (line 297 of /home/my_site/public_html/modules/contrib/commerce_printful/src/Form/PrintfulStoreForm.php)

Incidentally, this is with PHP 8 and using the patch from issue 3304984.

Thanks,

-=Delty

trigdog’s picture

StatusFileSize
new713 bytes

Are you sure the Store form saved when you entered the token into the api key field? I only got that error when I did not update the endpoint for getStoreInfo to 'stores' from 'store'. Make sure that is changed in the Printful.php service class file, clear the cache, and resaved the Printful Store form with the Token in the API Key field. This is just for testing, as I am not sure the approach the maintainers of this modules want to go with this.

I attached a patch for this.

trigdog’s picture

Note: If you test this, make sure you keep a copy of your old API Key because I don't think you can get another one of those anymore.

You do have to register a new private token at https://developers.printful.com/ to test the patch.

trigdog’s picture

Orders seem to post fine to printful with the above patch in #5 but there is an error logged originating in OrderItemsTrait.php:

Warning: Undefined array key "currency" in Drupal\commerce_printful\Plugin\Commerce\ShippingMethod\PrintfulShipping->getRequestData() (line 75 of /var/www/wcs/web/modules/contrib/commerce_printful/src/OrderItemsTrait.php)

$store_info = $this->pf->getStoreInfo();
$pf_currency = $store_info['result']['currency'];

The problem is the getStoreInfo() endpoint "/stores" for OAuth does not return the default currency anymore ($store_info['result']['currency']). I have a support request into Printful about this to see how we can get that info. Will report back when I hear back.

DennisBradenton’s picture

any update on this? I am with a new install here and with a new account on printful and they deactivated the api generation.

trigdog’s picture

They finally got back. This is their response:

"Our developer team explained that we don't expose the store's default currency in the API currently"

So we will need to remove/rework that bit of code. I will try and get to that in the next couple days.

@DennisBradenton - The patch in #5 does seem to work if you generate the new private token at https://developers.printful.com/ and paste the token in the api key field. Everything I have tested has worked and the issue mentioned in #7 is just an error that is logged and needs fixed. The orders still posts to Printful just fine and the product syncing also works.

cameron prince’s picture

Here's a patch to also resolve the problem in #4.

  • cameron prince committed fc555a1e on 2.0.x
    Issue #3279532 by trigdog, cameron prince: Support new API tokens
    
cameron prince’s picture

Status: Active » Fixed
delty’s picture

I just updated to the latest release and added my new API token. Everything appears to be working. I was able to sync with no errors and complete a sale so that's good news. Thanks for the update!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.