Using the official PHP library for the WooCommerce REST API with basic auth

If a WordPress installation is protected via .htaccess basic auth, the requests against the WooCommerce REST API with the PHP library do not work. I did not find the GitHub issue where someone said that CURL could be used to set the login credentials, but with that information, I found a question and the answers on Stack Overflow, that helped me:

$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERPWD, 'user:password' );Code language: PHP (php)

I inserted these two lines at the beginning of my script and replaced user and password with the actual login data. With that, the requests against the protected installation worked.

Leave a Reply

Your email address will not be published. Required fields are marked *

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.