Getting WordPress fatal error when hitting WooCommerce API


I have made a script that extracts products from WooCommerce and a script that update stock in WooCommerce. The shop have about 750 parent products and total number of variants under these parents are about 4500. I use Automattic’s PHP SDK for WooCommerce.

When i run my “extract products” function to save all product information in an external database, it will run fine. But if i re-run the script 15 minutes later, i get this message:

Fatal error: Uncaught AutomatticWooCommerceHttpClientHttpClientException: Error: <p>En kritisk feil har inntruffet på ditt nettsted.</p><p><a href="">Lær mer om feilsøking i WordPress.</a></p> [internal_server_error] in /Applications/XAMPP/xamppfiles/htdocs/portland_integrasjon/wc/inc/HttpClient/HttpClient.php:350 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/portland_integrasjon/wc/inc/HttpClient/HttpClient.php(386): AutomatticWooCommerceHttpClientHttpClient->lookForErrors(Object(stdClass)) #1 /Applications/XAMPP/xamppfiles/htdocs/portland_integrasjon/wc/inc/HttpClient/HttpClient.php(422): AutomatticWooCommerceHttpClientHttpClient->processResponse() #2 /Applications/XAMPP/xamppfiles/htdocs/portland_integrasjon/wc/inc/Client.php(82): AutomatticWooCommerceHttpClientHttpClient->request('products', 'GET', Array, Array) #3 /Applications/XAMPP/xamppfiles/htdocs/portland_integrasjon/wc/wc-procucts-extract.php(8): AutomatticWooCommerceClient->g in /Applications/XAMPP/xamppfiles/htdocs/portland_integrasjon/wc/inc/HttpClient/HttpClient.php on line 350

Error message is in Norwegian, but in English it says: A critical error have occured on you website.

The API call i use for “extract products” are:

 $products = $woocommerce->get('products', $parameters=['per_page' => 99999]);
 $productVariation = $woocommerce->get('products/'.$productId.'/variations/'.$child);

If i wait a few more minutes and run another API hit for WooCommerce, lets say “update stock”, and then re-run “extract products”, everything works fine.

So my problem is: I want to be able to re-run “extract-products” function several times without having to wait or run another API hit first.

Any sugestions?

, , , phingoc 1 year 2020-07-26T05:11:09-05:00 0 Answers 50 views 0

Leave an answer